mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Macro for math operators
This commit is contained in:
parent
a8fd64f928
commit
13efa128c8
@ -53,6 +53,7 @@ pub fn module() -> Module {
|
|||||||
let mut math = Scope::deduplicating();
|
let mut math = Scope::deduplicating();
|
||||||
math.def_func::<FormulaNode>("formula");
|
math.def_func::<FormulaNode>("formula");
|
||||||
math.def_func::<LrNode>("lr");
|
math.def_func::<LrNode>("lr");
|
||||||
|
math.def_func::<OpNode>("op");
|
||||||
math.def_func::<FloorFunc>("floor");
|
math.def_func::<FloorFunc>("floor");
|
||||||
math.def_func::<CeilFunc>("ceil");
|
math.def_func::<CeilFunc>("ceil");
|
||||||
math.def_func::<AbsFunc>("abs");
|
math.def_func::<AbsFunc>("abs");
|
||||||
@ -75,8 +76,8 @@ pub fn module() -> Module {
|
|||||||
math.def_func::<FrakNode>("frak");
|
math.def_func::<FrakNode>("frak");
|
||||||
math.def_func::<MonoNode>("mono");
|
math.def_func::<MonoNode>("mono");
|
||||||
math.def_func::<BbNode>("bb");
|
math.def_func::<BbNode>("bb");
|
||||||
define_spacings(&mut math);
|
spacing::define(&mut math);
|
||||||
define_operators(&mut math);
|
op::define(&mut math);
|
||||||
Module::new("math").with_scope(math)
|
Module::new("math").with_scope(math)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,42 +48,56 @@ impl LayoutMath for OpNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hook up all operators.
|
macro_rules! ops {
|
||||||
pub(super) fn define_operators(math: &mut Scope) {
|
($($name:ident $(: $value:literal)? $(($tts:tt))?),* $(,)?) => {
|
||||||
math.define("arccos", op("arccos", false));
|
pub(super) fn define(math: &mut Scope) {
|
||||||
math.define("arcsin", op("arcsin", false));
|
$(math.define(
|
||||||
math.define("arctan", op("arctan", false));
|
stringify!($name),
|
||||||
math.define("arg", op("arg", false));
|
OpNode {
|
||||||
math.define("cos", op("cos", false));
|
text: ops!(@name $name $(: $value)?).into(),
|
||||||
math.define("cosh", op("cosh", false));
|
limits: ops!(@limit $($tts)*),
|
||||||
math.define("cot", op("cot", false));
|
}.pack()
|
||||||
math.define("coth", op("coth", false));
|
);)*
|
||||||
math.define("csc", op("csc", false));
|
}
|
||||||
math.define("deg", op("deg", false));
|
};
|
||||||
math.define("det", op("det", true));
|
(@name $name:ident) => { stringify!($name) };
|
||||||
math.define("dim", op("dim", false));
|
(@name $name:ident: $value:literal) => { $value };
|
||||||
math.define("exp", op("exp", false));
|
(@limit limits) => { true };
|
||||||
math.define("gcd", op("gcd", true));
|
(@limit) => { false };
|
||||||
math.define("hom", op("hom", false));
|
|
||||||
math.define("inf", op("inf", true));
|
|
||||||
math.define("ker", op("ker", false));
|
|
||||||
math.define("lg", op("lg", false));
|
|
||||||
math.define("lim", op("lim", true));
|
|
||||||
math.define("ln", op("ln", false));
|
|
||||||
math.define("log", op("log", false));
|
|
||||||
math.define("max", op("max", true));
|
|
||||||
math.define("min", op("min", true));
|
|
||||||
math.define("Pr", op("Pr", true));
|
|
||||||
math.define("sec", op("sec", false));
|
|
||||||
math.define("sin", op("sin", false));
|
|
||||||
math.define("sinh", op("sinh", false));
|
|
||||||
math.define("sup", op("sup", true));
|
|
||||||
math.define("tan", op("tan", false));
|
|
||||||
math.define("tanh", op("tanh", false));
|
|
||||||
math.define("liminf", op("lim inf", true));
|
|
||||||
math.define("limsup", op("lim sup", true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op(name: &str, limits: bool) -> Content {
|
ops! {
|
||||||
OpNode { text: name.into(), limits }.pack()
|
arccos,
|
||||||
|
arcsin,
|
||||||
|
arctan,
|
||||||
|
arg,
|
||||||
|
cos,
|
||||||
|
cosh,
|
||||||
|
cot,
|
||||||
|
coth,
|
||||||
|
csc,
|
||||||
|
deg,
|
||||||
|
det (limits),
|
||||||
|
dim,
|
||||||
|
exp,
|
||||||
|
gcd (limits),
|
||||||
|
hom,
|
||||||
|
mod,
|
||||||
|
inf (limits),
|
||||||
|
ker,
|
||||||
|
lg,
|
||||||
|
lim (limits),
|
||||||
|
ln,
|
||||||
|
log,
|
||||||
|
max (limits),
|
||||||
|
min (limits),
|
||||||
|
Pr (limits),
|
||||||
|
sec,
|
||||||
|
sin,
|
||||||
|
sinh,
|
||||||
|
sup (limits),
|
||||||
|
tan,
|
||||||
|
tanh,
|
||||||
|
liminf: "lim inf" (limits),
|
||||||
|
limsup: "lim sup" (limits),
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ const THICK: Em = Em::new(5.0 / 18.0);
|
|||||||
const QUAD: Em = Em::new(1.0);
|
const QUAD: Em = Em::new(1.0);
|
||||||
|
|
||||||
/// Hook up all spacings.
|
/// Hook up all spacings.
|
||||||
pub(super) fn define_spacings(math: &mut Scope) {
|
pub(super) fn define(math: &mut Scope) {
|
||||||
math.define("thin", HNode::strong(THIN).pack());
|
math.define("thin", HNode::strong(THIN).pack());
|
||||||
math.define("med", HNode::strong(MEDIUM).pack());
|
math.define("med", HNode::strong(MEDIUM).pack());
|
||||||
math.define("thick", HNode::strong(THICK).pack());
|
math.define("thick", HNode::strong(THICK).pack());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user