summaryrefslogtreecommitdiff
path: root/library/src/math
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-10 12:55:21 +0100
commit62f35602a87574dcc607f1637aeae1be574981ff (patch)
tree363a1918006e06d7d79dc2ace5f8e59cd3b6bb19 /library/src/math
parentc38d72383d2068361d635d6c1c78ba97aa917801 (diff)
New #[func] macro
Diffstat (limited to 'library/src/math')
-rw-r--r--library/src/math/accent.rs2
-rw-r--r--library/src/math/attach.rs3
-rw-r--r--library/src/math/delimited.rs56
-rw-r--r--library/src/math/frac.rs4
-rw-r--r--library/src/math/mod.rs69
-rw-r--r--library/src/math/op.rs1
-rw-r--r--library/src/math/root.rs3
-rw-r--r--library/src/math/style.rs9
-rw-r--r--library/src/math/underover.rs6
9 files changed, 62 insertions, 91 deletions
diff --git a/library/src/math/accent.rs b/library/src/math/accent.rs
index 164247de..03caf411 100644
--- a/library/src/math/accent.rs
+++ b/library/src/math/accent.rs
@@ -24,7 +24,6 @@ pub struct AccentNode {
/// ```example
/// $arrow(A B C)$
/// ```
- #[positional]
#[required]
pub base: Content,
@@ -47,7 +46,6 @@ pub struct AccentNode {
/// | Caron | `caron` | `ˇ` |
/// | Right arrow | `arrow`, `->` | `→` |
/// | Left arrow | `arrow.l`, `<-` | `←` |
- #[positional]
#[required]
pub accent: Accent,
}
diff --git a/library/src/math/attach.rs b/library/src/math/attach.rs
index c2d7703d..7d8749f2 100644
--- a/library/src/math/attach.rs
+++ b/library/src/math/attach.rs
@@ -16,7 +16,6 @@ use super::*;
#[node(LayoutMath)]
pub struct AttachNode {
/// The base to which things are attached.
- #[positional]
#[required]
pub base: Content,
@@ -79,7 +78,6 @@ impl LayoutMath for AttachNode {
#[node(LayoutMath)]
pub struct ScriptsNode {
/// The base to attach the scripts to.
- #[positional]
#[required]
pub body: Content,
}
@@ -102,7 +100,6 @@ impl LayoutMath for ScriptsNode {
#[node(LayoutMath)]
pub struct LimitsNode {
/// The base to attach the limits to.
- #[positional]
#[required]
pub body: Content,
}
diff --git a/library/src/math/delimited.rs b/library/src/math/delimited.rs
index f9d22c43..6f468af7 100644
--- a/library/src/math/delimited.rs
+++ b/library/src/math/delimited.rs
@@ -24,7 +24,6 @@ pub struct LrNode {
pub size: Smart<Rel<Length>>,
/// The delimited content, including the delimiters.
- #[positional]
#[required]
#[parse(
let mut body = Content::empty();
@@ -111,15 +110,15 @@ fn scale(
/// $ floor(x/2) $
/// ```
///
-/// ## Parameters
-/// - body: `Content` (positional, required)
-/// The expression to floor.
-///
/// Display: Floor
/// Category: math
+/// Returns: content
#[func]
-pub fn floor(args: &mut Args) -> SourceResult<Value> {
- delimited(args, '⌊', '⌋')
+pub fn floor(
+ /// The expression to floor.
+ body: Content,
+) -> Value {
+ delimited(body, '⌊', '⌋')
}
/// Ceil an expression.
@@ -129,15 +128,15 @@ pub fn floor(args: &mut Args) -> SourceResult<Value> {
/// $ ceil(x/2) $
/// ```
///
-/// ## Parameters
-/// - body: `Content` (positional, required)
-/// The expression to ceil.
-///
/// Display: Ceil
/// Category: math
+/// Returns: content
#[func]
-pub fn ceil(args: &mut Args) -> SourceResult<Value> {
- delimited(args, '⌈', '⌉')
+pub fn ceil(
+ /// The expression to ceil.
+ body: Content,
+) -> Value {
+ delimited(body, '⌈', '⌉')
}
/// Take the absolute value of an expression.
@@ -147,15 +146,16 @@ pub fn ceil(args: &mut Args) -> SourceResult<Value> {
/// $ abs(x/2) $
/// ```
///
-/// ## Parameters
-/// - body: `Content` (positional, required)
-/// The expression to take the absolute value of.
///
/// Display: Abs
/// Category: math
+/// Returns: content
#[func]
-pub fn abs(args: &mut Args) -> SourceResult<Value> {
- delimited(args, '|', '|')
+pub fn abs(
+ /// The expression to take the absolute value of.
+ body: Content,
+) -> Value {
+ delimited(body, '|', '|')
}
/// Take the norm of an expression.
@@ -165,24 +165,24 @@ pub fn abs(args: &mut Args) -> SourceResult<Value> {
/// $ norm(x/2) $
/// ```
///
-/// ## Parameters
-/// - body: `Content` (positional, required)
-/// The expression to take the norm of.
-///
/// Display: Norm
/// Category: math
+/// Returns: content
#[func]
-pub fn norm(args: &mut Args) -> SourceResult<Value> {
- delimited(args, '‖', '‖')
+pub fn norm(
+ /// The expression to take the norm of.
+ body: Content,
+) -> Value {
+ delimited(body, '‖', '‖')
}
-fn delimited(args: &mut Args, left: char, right: char) -> SourceResult<Value> {
- Ok(Value::Content(
+fn delimited(body: Content, left: char, right: char) -> Value {
+ Value::Content(
LrNode::new(Content::sequence(vec![
TextNode::packed(left),
- args.expect::<Content>("body")?,
+ body,
TextNode::packed(right),
]))
.pack(),
- ))
+ )
}
diff --git a/library/src/math/frac.rs b/library/src/math/frac.rs
index c1f4065b..0624832a 100644
--- a/library/src/math/frac.rs
+++ b/library/src/math/frac.rs
@@ -22,12 +22,10 @@ const FRAC_AROUND: Em = Em::new(0.1);
#[node(LayoutMath)]
pub struct FracNode {
/// The fraction's numerator.
- #[positional]
#[required]
pub num: Content,
/// The fraction's denominator.
- #[positional]
#[required]
pub denom: Content,
}
@@ -50,12 +48,10 @@ impl LayoutMath for FracNode {
#[node(LayoutMath)]
pub struct BinomNode {
/// The binomial's upper index.
- #[positional]
#[required]
pub upper: Content,
/// The binomial's lower index.
- #[positional]
#[required]
pub lower: Content,
}
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs
index 0c9dc338..8f89e028 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -47,52 +47,52 @@ use crate::text::{
/// Create a module with all math definitions.
pub fn module() -> Module {
let mut math = Scope::deduplicating();
- math.def_func::<FormulaNode>("formula");
- math.def_func::<TextNode>("text");
+ math.define("formula", FormulaNode::func());
+ math.define("text", TextNode::func());
// Grouping.
- math.def_func::<LrNode>("lr");
- math.def_func::<AbsFunc>("abs");
- math.def_func::<NormFunc>("norm");
- math.def_func::<FloorFunc>("floor");
- math.def_func::<CeilFunc>("ceil");
+ math.define("lr", LrNode::func());
+ math.define("abs", abs);
+ math.define("norm", norm);
+ math.define("floor", floor);
+ math.define("ceil", ceil);
// Attachments and accents.
- math.def_func::<AttachNode>("attach");
- math.def_func::<ScriptsNode>("scripts");
- math.def_func::<LimitsNode>("limits");
- math.def_func::<AccentNode>("accent");
- math.def_func::<UnderlineNode>("underline");
- math.def_func::<OverlineNode>("overline");
- math.def_func::<UnderbraceNode>("underbrace");
- math.def_func::<OverbraceNode>("overbrace");
- math.def_func::<UnderbracketNode>("underbracket");
- math.def_func::<OverbracketNode>("overbracket");
+ math.define("attach", AttachNode::func());
+ math.define("scripts", ScriptsNode::func());
+ math.define("limits", LimitsNode::func());
+ math.define("accent", AccentNode::func());
+ math.define("underline", UnderlineNode::func());
+ math.define("overline", OverlineNode::func());
+ math.define("underbrace", UnderbraceNode::func());
+ math.define("overbrace", OverbraceNode::func());
+ math.define("underbracket", UnderbracketNode::func());
+ math.define("overbracket", OverbracketNode::func());
// Fractions and matrix-likes.
- math.def_func::<FracNode>("frac");
- math.def_func::<BinomNode>("binom");
- math.def_func::<VecNode>("vec");
- math.def_func::<MatNode>("mat");
- math.def_func::<CasesNode>("cases");
+ math.define("frac", FracNode::func());
+ math.define("binom", BinomNode::func());
+ math.define("vec", VecNode::func());
+ math.define("mat", MatNode::func());
+ math.define("cases", CasesNode::func());
// Roots.
- math.def_func::<SqrtNode>("sqrt");
- math.def_func::<RootNode>("root");
+ math.define("sqrt", SqrtNode::func());
+ math.define("root", RootNode::func());
// Styles.
- math.def_func::<UprightNode>("upright");
- math.def_func::<BoldNode>("bold");
- math.def_func::<ItalicNode>("italic");
- math.def_func::<SerifNode>("serif");
- math.def_func::<SansNode>("sans");
- math.def_func::<CalNode>("cal");
- math.def_func::<FrakNode>("frak");
- math.def_func::<MonoNode>("mono");
- math.def_func::<BbNode>("bb");
+ math.define("upright", UprightNode::func());
+ math.define("bold", BoldNode::func());
+ math.define("italic", ItalicNode::func());
+ math.define("serif", SerifNode::func());
+ math.define("sans", SansNode::func());
+ math.define("cal", CalNode::func());
+ math.define("frak", FrakNode::func());
+ math.define("mono", MonoNode::func());
+ math.define("bb", BbNode::func());
// Text operators.
- math.def_func::<OpNode>("op");
+ math.define("op", OpNode::func());
op::define(&mut math);
// Spacings.
@@ -139,7 +139,6 @@ pub struct FormulaNode {
pub block: bool,
/// The content of the formula.
- #[positional]
#[required]
pub body: Content,
}
diff --git a/library/src/math/op.rs b/library/src/math/op.rs
index aa2e4cf7..bd81aa0e 100644
--- a/library/src/math/op.rs
+++ b/library/src/math/op.rs
@@ -23,7 +23,6 @@ use super::*;
#[node(LayoutMath)]
pub struct OpNode {
/// The operator's text.
- #[positional]
#[required]
pub text: EcoString,
diff --git a/library/src/math/root.rs b/library/src/math/root.rs
index e190c65f..cb01e6a1 100644
--- a/library/src/math/root.rs
+++ b/library/src/math/root.rs
@@ -12,7 +12,6 @@ use super::*;
#[node(LayoutMath)]
pub struct SqrtNode {
/// The expression to take the square root of.
- #[positional]
#[required]
pub radicand: Content,
}
@@ -35,12 +34,10 @@ impl LayoutMath for SqrtNode {
#[node(LayoutMath)]
pub struct RootNode {
/// Which root of the radicand to take.
- #[positional]
#[required]
index: Content,
/// The expression to take the root of.
- #[positional]
#[required]
radicand: Content,
}
diff --git a/library/src/math/style.rs b/library/src/math/style.rs
index 43c1f391..60bad6a5 100644
--- a/library/src/math/style.rs
+++ b/library/src/math/style.rs
@@ -12,7 +12,6 @@ use super::*;
#[node(LayoutMath)]
pub struct BoldNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -38,7 +37,6 @@ impl LayoutMath for BoldNode {
#[node(LayoutMath)]
pub struct UprightNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -61,7 +59,6 @@ impl LayoutMath for UprightNode {
#[node(LayoutMath)]
pub struct ItalicNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -84,7 +81,6 @@ impl LayoutMath for ItalicNode {
#[node(LayoutMath)]
pub struct SerifNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -110,7 +106,6 @@ impl LayoutMath for SerifNode {
#[node(LayoutMath)]
pub struct SansNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -136,7 +131,6 @@ impl LayoutMath for SansNode {
#[node(LayoutMath)]
pub struct CalNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -162,7 +156,6 @@ impl LayoutMath for CalNode {
#[node(LayoutMath)]
pub struct FrakNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -188,7 +181,6 @@ impl LayoutMath for FrakNode {
#[node(LayoutMath)]
pub struct MonoNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
@@ -219,7 +211,6 @@ impl LayoutMath for MonoNode {
#[node(LayoutMath)]
pub struct BbNode {
/// The piece of formula to style.
- #[positional]
#[required]
pub body: Content,
}
diff --git a/library/src/math/underover.rs b/library/src/math/underover.rs
index 2aabf132..a723ae97 100644
--- a/library/src/math/underover.rs
+++ b/library/src/math/underover.rs
@@ -16,7 +16,6 @@ const BRACKET_GAP: Em = Em::new(0.25);
#[node(LayoutMath)]
pub struct UnderlineNode {
/// The content above the line.
- #[positional]
#[required]
pub body: Content,
}
@@ -39,7 +38,6 @@ impl LayoutMath for UnderlineNode {
#[node(LayoutMath)]
pub struct OverlineNode {
/// The content below the line.
- #[positional]
#[required]
pub body: Content,
}
@@ -62,7 +60,6 @@ impl LayoutMath for OverlineNode {
#[node(LayoutMath)]
pub struct UnderbraceNode {
/// The content above the brace.
- #[positional]
#[required]
pub body: Content,
@@ -89,7 +86,6 @@ impl LayoutMath for UnderbraceNode {
#[node(LayoutMath)]
pub struct OverbraceNode {
/// The content below the brace.
- #[positional]
#[required]
pub body: Content,
@@ -116,7 +112,6 @@ impl LayoutMath for OverbraceNode {
#[node(LayoutMath)]
pub struct UnderbracketNode {
/// The content above the bracket.
- #[positional]
#[required]
pub body: Content,
@@ -143,7 +138,6 @@ impl LayoutMath for UnderbracketNode {
#[node(LayoutMath)]
pub struct OverbracketNode {
/// The content below the bracket.
- #[positional]
#[required]
pub body: Content,