1use ecow::EcoString;
2use unicode_math_class::MathClass;
3
4use crate::foundations::{Content, NativeElement, Scope, SymbolElem, elem};
5use crate::layout::HElem;
6use crate::math::{ClassElem, Mathy, THIN, upright};
7use crate::text::TextElem;
8
9#[elem(title = "Text Operator", Mathy)]
25pub struct OpElem {
26 #[required]
28 pub text: Content,
29
30 #[default(false)]
32 pub limits: bool,
33}
34
35macro_rules! ops {
36 ($($name:ident $(: $value:literal)? $(($tts:tt))?),* $(,)?) => {
37 pub(super) fn define(math: &mut Scope) {
38 $({
39 let operator = EcoString::from(ops!(@name $name $(: $value)?));
40 math.define(
41 stringify!($name),
42 OpElem::new(TextElem::new(operator).into())
44 .with_limits(ops!(@limit $($tts)*))
45 .pack()
46 );
47 })*
48
49 let dif = |d| {
50 HElem::new(THIN.into()).with_weak(true).pack()
51 + ClassElem::new(MathClass::Unary, upright(SymbolElem::packed(d))).pack()
52 };
53 math.define("dif", dif('d'));
54 math.define("Dif", dif('D'));
55 }
56 };
57 (@name $name:ident) => { stringify!($name) };
58 (@name $name:ident: $value:literal) => { $value };
59 (@limit limits) => { true };
60 (@limit) => { false };
61}
62
63ops! {
64 arccos,
65 arcsin,
66 arctan,
67 arg,
68 cos,
69 cosh,
70 cot,
71 coth,
72 csc,
73 csch,
74 ctg,
75 deg,
76 det (limits),
77 dim,
78 exp,
79 gcd (limits),
80 lcm (limits),
81 hom,
82 id,
83 im,
84 inf (limits),
85 ker,
86 lg,
87 lim (limits),
88 liminf: "lim inf" (limits),
89 limsup: "lim sup" (limits),
90 ln,
91 log,
92 max (limits),
93 min (limits),
94 mod,
95 Pr (limits),
96 sec,
97 sech,
98 sin,
99 sinc,
100 sinh,
101 sup (limits),
102 tan,
103 tanh,
104 tg,
105 tr,
106}