typst_library/math/
root.rs

1use typst_syntax::Span;
2
3use crate::foundations::{elem, func, Content, NativeElement};
4use crate::math::Mathy;
5
6/// A square root.
7///
8/// ```example
9/// $ sqrt(3 - 2 sqrt(2)) = sqrt(2) - 1 $
10/// ```
11#[func(title = "Square Root")]
12pub fn sqrt(
13    span: Span,
14    /// The expression to take the square root of.
15    radicand: Content,
16) -> Content {
17    RootElem::new(radicand).pack().spanned(span)
18}
19
20/// A general root.
21///
22/// ```example
23/// $ root(3, x) $
24/// ```
25#[elem(Mathy)]
26pub struct RootElem {
27    /// Which root of the radicand to take.
28    #[positional]
29    pub index: Option<Content>,
30
31    /// The expression to take the root of.
32    #[required]
33    pub radicand: Content,
34}