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();
|
||||
math.def_func::<FormulaNode>("formula");
|
||||
math.def_func::<LrNode>("lr");
|
||||
math.def_func::<OpNode>("op");
|
||||
math.def_func::<FloorFunc>("floor");
|
||||
math.def_func::<CeilFunc>("ceil");
|
||||
math.def_func::<AbsFunc>("abs");
|
||||
@ -75,8 +76,8 @@ pub fn module() -> Module {
|
||||
math.def_func::<FrakNode>("frak");
|
||||
math.def_func::<MonoNode>("mono");
|
||||
math.def_func::<BbNode>("bb");
|
||||
define_spacings(&mut math);
|
||||
define_operators(&mut math);
|
||||
spacing::define(&mut math);
|
||||
op::define(&mut math);
|
||||
Module::new("math").with_scope(math)
|
||||
}
|
||||
|
||||
|
@ -48,42 +48,56 @@ impl LayoutMath for OpNode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Hook up all operators.
|
||||
pub(super) fn define_operators(math: &mut Scope) {
|
||||
math.define("arccos", op("arccos", false));
|
||||
math.define("arcsin", op("arcsin", false));
|
||||
math.define("arctan", op("arctan", false));
|
||||
math.define("arg", op("arg", false));
|
||||
math.define("cos", op("cos", false));
|
||||
math.define("cosh", op("cosh", false));
|
||||
math.define("cot", op("cot", false));
|
||||
math.define("coth", op("coth", false));
|
||||
math.define("csc", op("csc", false));
|
||||
math.define("deg", op("deg", false));
|
||||
math.define("det", op("det", true));
|
||||
math.define("dim", op("dim", false));
|
||||
math.define("exp", op("exp", false));
|
||||
math.define("gcd", op("gcd", true));
|
||||
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));
|
||||
macro_rules! ops {
|
||||
($($name:ident $(: $value:literal)? $(($tts:tt))?),* $(,)?) => {
|
||||
pub(super) fn define(math: &mut Scope) {
|
||||
$(math.define(
|
||||
stringify!($name),
|
||||
OpNode {
|
||||
text: ops!(@name $name $(: $value)?).into(),
|
||||
limits: ops!(@limit $($tts)*),
|
||||
}.pack()
|
||||
);)*
|
||||
}
|
||||
};
|
||||
(@name $name:ident) => { stringify!($name) };
|
||||
(@name $name:ident: $value:literal) => { $value };
|
||||
(@limit limits) => { true };
|
||||
(@limit) => { false };
|
||||
}
|
||||
|
||||
fn op(name: &str, limits: bool) -> Content {
|
||||
OpNode { text: name.into(), limits }.pack()
|
||||
ops! {
|
||||
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);
|
||||
|
||||
/// 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("med", HNode::strong(MEDIUM).pack());
|
||||
math.define("thick", HNode::strong(THICK).pack());
|
||||
|
Loading…
x
Reference in New Issue
Block a user