formel 0.1.0

Lay out mathematical formulas from MathML with a font's OpenType MATH table
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
//! The English lexicon. Everything spoken lives in these tables; the engine in
//! [`super`] only decides which entry applies.

use super::{Lexicon, Phrases};

pub const ENGLISH: Lexicon = Lexicon {
    symbols: SYMBOLS,
    limit_symbols: &[
        ("→", "approaches"),
        ("↓", "decreases to"),
        ("↑", "increases to"),
    ],
    set_symbols: &[("∈", "in")],
    argument_symbols: &[("∣", "given")],
    cardinals: &[
        ("1", "one"),
        ("2", "two"),
        ("3", "three"),
        ("4", "four"),
        ("5", "five"),
        ("6", "six"),
        ("7", "seven"),
        ("8", "eight"),
        ("9", "nine"),
    ],
    fraction_denominators: &[
        ("2", "half", "halves"),
        ("3", "third", "thirds"),
        ("4", "quarter", "quarters"),
        ("5", "fifth", "fifths"),
        ("6", "sixth", "sixths"),
        ("7", "seventh", "sevenths"),
        ("8", "eighth", "eighths"),
        ("9", "ninth", "ninths"),
        ("10", "tenth", "tenths"),
    ],
    ordinals: &[
        ("2", "second"),
        ("3", "third"),
        ("4", "fourth"),
        ("n", "n-th"),
        ("k", "k-th"),
    ],
    silent_names: &[
        ("\u{2062}", "invisible times"),
        ("\u{2063}", "invisible separator"),
    ],
    identifiers: IDENTIFIERS,
    variants: &[
        ("bold", "bold"),
        ("bold-italic", "bold"),
        ("double-struck", "double-struck"),
        ("script", "script"),
        ("bold-script", "bold script"),
        ("fraktur", "fraktur"),
        ("bold-fraktur", "bold fraktur"),
        ("sans-serif", "sans-serif"),
        ("bold-sans-serif", "bold sans-serif"),
        ("sans-serif-italic", "sans-serif"),
        ("sans-serif-bold-italic", "bold sans-serif"),
        ("monospace", "monospace"),
    ],
    powers: &[
        ("2", "squared"),
        ("−1", "inverse"),
        ("-1", "inverse"),
        ("T", "transpose"),
        ("⊤", "transpose"),
        ("∘", "degrees"),
        ("°", "degrees"),
        ("3", "cubed"),
        ("′", "prime"),
        ("″", "double prime"),
        ("‴", "triple prime"),
        ("*", "star"),
        ("∗", "star"),
        ("†", "dagger"),
    ],
    root_indices: &[
        ("2", "square"),
        ("3", "cube"),
        ("4", "fourth"),
        ("5", "fifth"),
        ("6", "sixth"),
        ("7", "seventh"),
        ("8", "eighth"),
        ("9", "ninth"),
        ("10", "tenth"),
    ],
    accents: ACCENTS,
    large_operators: &[
        ("∑", "the sum", "over"),
        ("∏", "the product", "over"),
        ("∐", "the coproduct", "over"),
        ("∫", "the integral", "over"),
        ("∬", "the double integral", "over"),
        ("∭", "the triple integral", "over"),
        ("∮", "the contour integral", "over"),
        ("⋃", "the union", "over"),
        ("⋂", "the intersection", "over"),
        ("⋁", "the disjunction", "over"),
        ("⋀", "the conjunction", "over"),
        ("⨁", "the direct sum", "over"),
        ("⨂", "the tensor product", "over"),
        ("lim", "the limit", "as"),
        ("lim sup", "the limit superior", "as"),
        ("lim inf", "the limit inferior", "as"),
        ("max", "the maximum", "over"),
        ("min", "the minimum", "over"),
        ("sup", "the supremum", "over"),
        ("inf", "the infimum", "over"),
        ("arg max", "the arg max", "over"),
        ("arg min", "the arg min", "over"),
    ],
    fences: &[
        ("|", "|", "the absolute value of {0}"),
        ("‖", "‖", "the norm of {0}"),
        ("⌊", "⌋", "the floor of {0}"),
        ("⌈", "⌉", "the ceiling of {0}"),
    ],
    table_fences: &[
        ("(", ")", "matrix"),
        ("[", "]", "matrix"),
        ("|", "|", "determinant"),
    ],
    enclosures: &[
        ("box", "{0} in a box"),
        ("roundedbox", "{0} in a rounded box"),
        ("circle", "{0} in a circle"),
        ("updiagonalstrike", "{0} crossed out"),
        ("downdiagonalstrike", "{0} crossed out"),
        ("horizontalstrike", "{0} crossed out"),
        ("verticalstrike", "{0} crossed out"),
        ("longdiv", "{0} under a long division sign"),
        ("actuarial", "{0} in an actuarial symbol"),
        ("radical", "the square root of {0}"),
        ("top", "{0} with a line above"),
        ("bottom", "{0} with a line below"),
        ("left", "{0} with a line on the left"),
        ("right", "{0} with a line on the right"),
    ],
    phrases: Phrases {
        blank: "blank",
        space: "space",
        capital: "capital {0}",
        variant: "{0} {1}",
        negative: "negative",
        string: "the string {0}",
        error: "error: {0}",
        enclosed: "{0} enclosed",

        common_fraction: "{0} {1}",
        fraction_simple: "{0} over {1}",
        fraction: "the fraction with numerator {0} and denominator {1}",
        square_root: "the square root of {0}",
        named_root: "the {0} root of {1}",
        simple_root: "the {0}-th root of {1}",
        root: "the root with index {0} of {1}",

        named_power: "{0} {1}",
        power_simple: "{0} to the {1}",
        power: "{0} to the power {1}, end exponent",
        subscript_simple: "{0} sub {1}",
        subscript: "{0} sub {1}, end sub",
        sub_named_power: "{0} sub {1} {2}",
        sub_power: "{0} sub {1}, to the {2}",

        large_operator_under: "{0} {1} {2}",
        large_operator_over: "{0} to {1}",
        large_operator_both: "{0} from {1} to {2}",
        operand: "of",
        binomial: "{0} choose {1}",
        set: "the set {0}",
        set_builder: "the set of all {0} such that {1}",
        empty_set: "the empty set",
        cases: "{0} cases; {1}; end cases",
        case: "case {0}: {1}",
        case_condition: "{0}, if {1}",
        case_text: "{0}, {1}",
        derivative: "derivative",
        partial_derivative: "partial derivative",
        ordinal_derivative: "{0} {1}",
        derivative_of: "the {0} of {1} with respect to {2}",
        derivative_operator: "the {0} with respect to {1}",
        variable_separator: " and ",

        accent: "{0} {1}",
        under: "{0} with {1} below",
        over: "{0} with {1} above",
        under_over: "{0} with {1} below and {2} above",

        multiscripts: "{0} with {1}",
        list_separator: ", ",
        post_subscript: "subscript {0}",
        post_superscript: "superscript {0}",
        pre_subscript: "presubscript {0}",
        pre_superscript: "presuperscript {0}",

        table: "the {0} by {1} {2}; {3}; end {2}",
        empty_table: "an empty {0}",
        table_kind: "table",
        row_separator: "; ",
        cell_separator: ", ",
        row: "row {0}: {1}",
        labeled_row: "row {0}, labeled {1}: {2}",
    },
};

/// Operators and other symbols, as `<mo>` content (also used for any character in other
/// tokens). An empty word means the symbol is not spoken.
const SYMBOLS: &[(&str, &str)] = &[
    // arithmetic
    ("+", "plus"),
    ("-", "minus"),
    ("−", "minus"),
    ("±", "plus or minus"),
    ("∓", "minus or plus"),
    ("×", "times"),
    ("⋅", "times"),
    ("·", "times"),
    ("*", "times"),
    ("∗", "times"),
    ("÷", "divided by"),
    ("/", "divided by"),
    ("∕", "divided by"),
    ("!", "factorial"),
    ("%", "percent"),
    ("°", "degrees"),
    ("′", "prime"),
    ("″", "double prime"),
    ("‴", "triple prime"),
    ("∘", "composed with"),
    ("⊗", "tensor"),
    ("⊕", "direct sum"),
    ("√", "square root"),
    // relations
    ("=", "equals"),
    ("≠", "does not equal"),
    ("<", "is less than"),
    (">", "is greater than"),
    ("≤", "is less than or equal to"),
    ("≥", "is greater than or equal to"),
    ("⩽", "is less than or equal to"),
    ("⩾", "is greater than or equal to"),
    ("≪", "is much less than"),
    ("≫", "is much greater than"),
    ("≈", "is approximately equal to"),
    ("≃", "is asymptotically equal to"),
    ("≅", "is congruent to"),
    ("≡", "is equivalent to"),
    ("∼", "is similar to"),
    ("~", "is similar to"),
    ("∝", "is proportional to"),
    ("≔", "is defined as"),
    (":=", "is defined as"),
    ("≜", "is defined as"),
    ("⊥", "is perpendicular to"),
    ("∥", "is parallel to"),
    ("∣", "divides"),
    ("∤", "does not divide"),
    // arrows and logic
    ("→", "right arrow"),
    ("←", "left arrow"),
    ("↔", "left right arrow"),
    ("↦", "maps to"),
    ("⇒", "implies"),
    ("⟹", "implies"),
    ("⇐", "is implied by"),
    ("⟸", "is implied by"),
    ("⇔", "if and only if"),
    ("⟺", "if and only if"),
    ("∀", "for all"),
    ("∃", "there exists"),
    ("∄", "there does not exist"),
    ("¬", "not"),
    ("∧", "and"),
    ("∨", "or"),
    ("∴", "therefore"),
    ("∵", "because"),
    ("⊢", "proves"),
    ("⊨", "models"),
    // sets
    ("∈", "is an element of"),
    ("∉", "is not an element of"),
    ("∋", "contains"),
    ("⊂", "is a subset of"),
    ("⊆", "is a subset of or equal to"),
    ("⊊", "is a proper subset of"),
    ("⊃", "is a superset of"),
    ("⊇", "is a superset of or equal to"),
    ("∪", "union"),
    ("∩", "intersection"),
    ("∖", "set minus"),
    ("∅", "the empty set"),
    // calculus and constants
    ("∞", "infinity"),
    ("∂", "partial"),
    ("∇", "nabla"),
    ("∑", "the sum"),
    ("∏", "the product"),
    ("∫", "the integral"),
    ("∬", "the double integral"),
    ("∭", "the triple integral"),
    ("∮", "the contour integral"),
    ("ℏ", "h bar"),
    ("∠", "angle"),
    ("△", "triangle"),
    // fences and punctuation
    ("(", "open paren"),
    (")", "close paren"),
    ("[", "open bracket"),
    ("]", "close bracket"),
    ("{", "open brace"),
    ("}", "close brace"),
    ("⟨", "open angle bracket"),
    ("⟩", "close angle bracket"),
    ("⌊", "left floor"),
    ("⌋", "right floor"),
    ("⌈", "left ceiling"),
    ("⌉", "right ceiling"),
    ("|", "vertical bar"),
    ("‖", "double vertical bar"),
    (",", "comma"),
    (";", "semicolon"),
    (":", "colon"),
    (".", "dot"),
    ("…", "dot dot dot"),
    ("⋯", "dot dot dot"),
    ("⋮", "vertical dots"),
    ("⋱", "diagonal dots"),
    // invisible operators
    ("\u{2061}", "of"),
    ("\u{2062}", ""),
    ("\u{2063}", ""),
    ("\u{2064}", "and"),
];

/// Names of identifiers: function names and Greek letters. Capitals of letters listed here
/// are spoken with [`Phrases::capital`].
const IDENTIFIERS: &[(&str, &str)] = &[
    // functions
    ("sin", "sine"),
    ("cos", "cosine"),
    ("tan", "tangent"),
    ("cot", "cotangent"),
    ("sec", "secant"),
    ("csc", "cosecant"),
    ("arcsin", "arc sine"),
    ("arccos", "arc cosine"),
    ("arctan", "arc tangent"),
    ("sinh", "hyperbolic sine"),
    ("cosh", "hyperbolic cosine"),
    ("tanh", "hyperbolic tangent"),
    ("coth", "hyperbolic cotangent"),
    ("log", "log"),
    ("lg", "log"),
    ("ln", "natural log"),
    ("exp", "exponential"),
    ("lim", "limit"),
    ("max", "maximum"),
    ("min", "minimum"),
    ("sup", "supremum"),
    ("inf", "infimum"),
    ("det", "determinant"),
    ("dim", "dimension"),
    ("ker", "kernel"),
    ("deg", "degree"),
    ("arg", "argument"),
    ("gcd", "g c d"),
    ("lcm", "l c m"),
    ("tr", "trace"),
    ("Tr", "trace"),
    ("Pr", "probability"),
    ("Re", "real part"),
    ("Im", "imaginary part"),
    ("mod", "mod"),
    // Greek
    ("α", "alpha"),
    ("β", "beta"),
    ("γ", "gamma"),
    ("δ", "delta"),
    ("ε", "epsilon"),
    ("ϵ", "epsilon"),
    ("ζ", "zeta"),
    ("η", "eta"),
    ("θ", "theta"),
    ("ϑ", "theta"),
    ("ι", "iota"),
    ("κ", "kappa"),
    ("λ", "lambda"),
    ("μ", "mu"),
    ("ν", "nu"),
    ("ξ", "xi"),
    ("ο", "omicron"),
    ("π", "pi"),
    ("ϖ", "pi"),
    ("ρ", "rho"),
    ("ϱ", "rho"),
    ("σ", "sigma"),
    ("ς", "sigma"),
    ("τ", "tau"),
    ("υ", "upsilon"),
    ("φ", "phi"),
    ("ϕ", "phi"),
    ("χ", "chi"),
    ("ψ", "psi"),
    ("ω", "omega"),
    // other letters
    ("ı", "dotless i"),
    ("ȷ", "dotless j"),
    ("ℓ", "ell"),
    ("℘", "Weierstrass p"),
    ("ℵ", "aleph"),
];

/// Over- and underscripts spoken after their base (`x hat`).
const ACCENTS: &[(&str, &str)] = &[
    ("^", "hat"),
    ("ˆ", "hat"),
    ("\u{302}", "hat"),
    ("¯", "bar"),
    ("‾", "bar"),
    ("_", "bar"),
    ("\u{304}", "bar"),
    ("\u{305}", "bar"),
    ("~", "tilde"),
    ("˜", "tilde"),
    ("\u{303}", "tilde"),
    ("→", "vector"),
    ("\u{20D7}", "vector"),
    ("˙", "dot"),
    ("\u{307}", "dot"),
    ("¨", "double dot"),
    ("\u{308}", "double dot"),
    ("ˇ", "check"),
    ("\u{30C}", "check"),
    ("˘", "breve"),
    ("\u{306}", "breve"),
    ("´", "acute"),
    ("\u{301}", "acute"),
    ("`", "grave"),
    ("\u{300}", "grave"),
    ("˚", "ring"),
    ("\u{30A}", "ring"),
    ("⏞", "overbrace"),
    ("⏟", "underbrace"),
    ("⎴", "overbracket"),
    ("⎵", "underbracket"),
];