latexmath 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/README.adoc +5 -1
- data/artifacts/latex.bindings.python.json +1 -1
- data/artifacts/latex.bindings.rs.json +1 -1
- data/artifacts/latex.bindings.ruby.json +1 -1
- data/artifacts/latex.bindings.ts.json +1 -1
- data/artifacts/latex.checksums.txt +14 -14
- data/artifacts/latex.json +1 -1
- data/docs/latex.adoc +289 -0
- data/docs/testsuite-pin.adoc +20 -5
- data/grammars/latex.wrappers.json +1 -1
- data/lib/latexmath/model/nodes.rb +4 -2
- data/lib/latexmath/model.rb +24 -9
- data/lib/latexmath/parser/engine.rb +3 -0
- data/lib/latexmath/version.rb +1 -1
- data/model/latex.lml.checksums.txt +2 -2
- data/model/latex.lml.json +8 -0
- metadata +5 -4
data/docs/latex.adoc
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
= LaTeX notation accepted by Latexmath
|
|
2
|
+
:toc:
|
|
3
|
+
|
|
4
|
+
This page describes the LaTeX math that Latexmath reads: how the input is
|
|
5
|
+
prepared, which constructs the grammar accepts, and which part of the typed
|
|
6
|
+
model each construct becomes. It is part of the specification set tracked in
|
|
7
|
+
https://github.com/plurimath/plurimath/issues/525[plurimath#525].
|
|
8
|
+
|
|
9
|
+
Everything here is taken from three sources in this repository:
|
|
10
|
+
|
|
11
|
+
* the grammar, `grammars/latex.parg`, generated from the LaTeX grammar of
|
|
12
|
+
Plurimath at commit `e7ab4a5186c9be96f62d670574bc2c72f9365ad4`;
|
|
13
|
+
* the model, `model/latex.lml.json`, generated from that grammar;
|
|
14
|
+
* the specs under `spec/` and the stage corpus pinned in
|
|
15
|
+
`spec/fixtures/testsuite-pin.yml`.
|
|
16
|
+
|
|
17
|
+
How the grammar and the model are produced and checked is in
|
|
18
|
+
link:parser-contract.adoc[the parser contract] and
|
|
19
|
+
link:model-contract.adoc[the model contract]. This page does not repeat
|
|
20
|
+
those rules; it describes the notation.
|
|
21
|
+
|
|
22
|
+
== The notation in brief
|
|
23
|
+
|
|
24
|
+
Latexmath reads the LaTeX math that Plurimath reads, not TeX itself. There is
|
|
25
|
+
no macro expansion, no `\def` and no catcode handling. The grammar is a fixed
|
|
26
|
+
set of commands, symbols and environments. A formula is a sequence of terms;
|
|
27
|
+
each term can carry a subscript and a superscript; some commands take
|
|
28
|
+
arguments in braces or brackets.
|
|
29
|
+
|
|
30
|
+
The grammar is not a LaTeX validator. It accepts what Plurimath accepts at
|
|
31
|
+
the pinned commit, including some forms that LaTeX itself would not, and it
|
|
32
|
+
refuses what Plurimath refuses.
|
|
33
|
+
|
|
34
|
+
== Before the grammar runs
|
|
35
|
+
|
|
36
|
+
The grammar reads a rewritten copy of the input, not the input itself. The
|
|
37
|
+
steps are listed in full in the parser contract. In short:
|
|
38
|
+
|
|
39
|
+
* Spaces are removed, except a space after a backslash (`\ `), and newlines
|
|
40
|
+
are removed.
|
|
41
|
+
* Every non-ASCII character, and the characters `<`, `>` and `'`, become
|
|
42
|
+
hexadecimal character references such as `α`. `&` and `"` stay as
|
|
43
|
+
they are.
|
|
44
|
+
* The contents of `\text{...}` and `\mbox{...}` are put back exactly as
|
|
45
|
+
written, spaces and non-ASCII characters included.
|
|
46
|
+
|
|
47
|
+
So `\alpha` and `α` reach the grammar as different text (`\alpha` and
|
|
48
|
+
`α`), and both are symbols. Spaces never separate terms: `ab` and
|
|
49
|
+
`a b` are the same input.
|
|
50
|
+
|
|
51
|
+
== Structure of a formula
|
|
52
|
+
|
|
53
|
+
The root rule is `expression`. Read from the grammar:
|
|
54
|
+
|
|
55
|
+
* An expression is one or more terms in a row. `{a \over b}` and
|
|
56
|
+
`a \over b` divide the terms before `\over` by the terms after it
|
|
57
|
+
(captures `dividend` and `divisor`).
|
|
58
|
+
* A term (rule `sequence`) is one of the constructs below. When none of the
|
|
59
|
+
special forms applies, it is an operand, optionally with scripts.
|
|
60
|
+
* An operand (rule `intermediate_exp`) is a single symbol, number or command,
|
|
61
|
+
a group in braces `{...}`, or a bracketed group: an opening bracket, an
|
|
62
|
+
optional expression and a closing bracket. The closing bracket may be
|
|
63
|
+
missing; then the model records it as absent.
|
|
64
|
+
|
|
65
|
+
=== Scripts
|
|
66
|
+
|
|
67
|
+
`_` gives a subscript and `^` a superscript. Both may be given, in either
|
|
68
|
+
order. A script is one operand: one letter, one number, one command or one
|
|
69
|
+
group. So `x^ab` is `x` with superscript `a`, followed by `b`, while `x^10`
|
|
70
|
+
has the superscript `10`, because a digit string is one number.
|
|
71
|
+
|
|
72
|
+
[cols="2,3"]
|
|
73
|
+
|===
|
|
74
|
+
|Form |Model
|
|
75
|
+
|
|
76
|
+
|`a_b` |`Base` with `subscript`
|
|
77
|
+
|`a^b` |`Power` with `supscript`
|
|
78
|
+
|`a_b^c`, `a^c_b` |`PowerBase` with `subscript` and `supscript`
|
|
79
|
+
|===
|
|
80
|
+
|
|
81
|
+
Large operators `\sum`, `\prod`, `\int` and `\oint` take their limits as
|
|
82
|
+
scripts and the operand after them as `third_value` (class `TernaryClass`). A function name
|
|
83
|
+
followed by `\limits`, such as `\max\limits_{i}`, is the `limits` form.
|
|
84
|
+
|
|
85
|
+
=== Fractions and other two-argument commands
|
|
86
|
+
|
|
87
|
+
These commands take two arguments (capture `binary`): `\frac`, `\binom`,
|
|
88
|
+
`\overset`, `\underset`, `\stackrel`, `\color`, and also `\lim`, `\log` and
|
|
89
|
+
`\inf`, which take their scripts as arguments. `\sqrt{x}` is a square root;
|
|
90
|
+
`\sqrt[n]{x}` takes the index in brackets as `first_value`. `\rule` takes up
|
|
91
|
+
to three optional arguments. `\bmod`, `\pmod` and `\mod` stand between two
|
|
92
|
+
operands (capture `under_over`).
|
|
93
|
+
|
|
94
|
+
=== One-argument commands
|
|
95
|
+
|
|
96
|
+
Function names and accents with one argument (capture `unary_functions`):
|
|
97
|
+
|
|
98
|
+
`\arccos \arcsin \arctan \bar \cancel \cos \cosh \cot \coth \csc \ddot \deg
|
|
99
|
+
\det \dim \dot \exp \gcd \hat \hom \ker \lg \liminf \limsup \ln \max \min
|
|
100
|
+
\overline \phantom \sec \sin \sinh \sup \tan \tanh \tilde \underbrace \vec`
|
|
101
|
+
|
|
102
|
+
The argument may be omitted, may be a bracketed operand or may be a
|
|
103
|
+
`\left ... \right` group. Each of these may also carry scripts.
|
|
104
|
+
|
|
105
|
+
`\overbrace` takes its argument and the label above it (capture
|
|
106
|
+
`underover`).
|
|
107
|
+
|
|
108
|
+
=== Fonts and text
|
|
109
|
+
|
|
110
|
+
Font commands take one argument. The model keeps the command name as the
|
|
111
|
+
text field `fonts` next to the argument:
|
|
112
|
+
|
|
113
|
+
`\Bbb \bf \cal \displaystyle \mathbb \mathbf \mathbfit \mathbold \mathcal
|
|
114
|
+
\mathds \mathfrak \mathit \mathrm \mathsf \mathsfbf \mathsfbfit \mathsfit
|
|
115
|
+
\mathtt \mbf \mbfit \mbfitsans \mbfsans \mfrak \mit \msans \mscr \mtt \rm
|
|
116
|
+
\textbf \textit \textrm`
|
|
117
|
+
|
|
118
|
+
`\text{...}` and `\mbox{...}` hold literal text, kept as the caller wrote
|
|
119
|
+
it: the field `text` names the command and `first_value` holds the text. `\operatorname{...}` holds the name of an operator.
|
|
120
|
+
|
|
121
|
+
=== Brackets
|
|
122
|
+
|
|
123
|
+
`\left` and `\right` enclose a group (model class `LeftRight`). The bracket
|
|
124
|
+
after `\left` or `\right` may be `.` or missing. The grammar accepts
|
|
125
|
+
`\left( x` with no `\right`. Recognised brackets include `(`, `)`, `[`,
|
|
126
|
+
`]`, `\{`, `\}`, `\lbrace`, `\rbrace`, `\lbrack`, `\rbrack`, `\langle`,
|
|
127
|
+
`\rangle`, `\lfloor`, `\rfloor`, `\lceil`, `\rceil`, `|`, `\vert`, `\Vert`,
|
|
128
|
+
`\|` and `\backslash`, together with their Unicode characters.
|
|
129
|
+
|
|
130
|
+
=== Environments
|
|
131
|
+
|
|
132
|
+
`\begin{name} ... \end{name}` reads an environment whose rows are separated
|
|
133
|
+
by `\\` (attribute `row_break`) and whose cells are separated by `&`. A
|
|
134
|
+
starred name and an optional argument in brackets are accepted.
|
|
135
|
+
`\begin{array}{...}` takes its column specification as `args`. The grammar
|
|
136
|
+
also has a command form, `\matrix{...}` and the like, for the names
|
|
137
|
+
`matrix`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`, `Vmatrix`, `align`,
|
|
138
|
+
`split`, `multline`, `array` and `cases`.
|
|
139
|
+
|
|
140
|
+
`\begin{cases} ... \end{cases}` is read the same way as the others. The
|
|
141
|
+
grammar does not say that its rows have a left brace and no right fence;
|
|
142
|
+
that is for the consumer to apply (Plurimath's `Table::Cases`).
|
|
143
|
+
|
|
144
|
+
The grammar does not check that the name after `\end` matches the name after
|
|
145
|
+
`\begin`. The model does not build rows and cells: the body of the
|
|
146
|
+
environment is the same nested expression as any other formula, and `&` and
|
|
147
|
+
`\\` appear in it as an `operant` and a `row_break` (see <<examples>>).
|
|
148
|
+
|
|
149
|
+
`\substack` takes one operand.
|
|
150
|
+
|
|
151
|
+
=== Symbols and numbers
|
|
152
|
+
|
|
153
|
+
* A single ASCII letter is a symbol.
|
|
154
|
+
* A command name from the symbol table, such as `\alpha` or `\leq`, is a
|
|
155
|
+
symbol. The table, `data/latex-symbols.json`, has 3,280 spellings at the
|
|
156
|
+
pinned commit. A character reference such as `α` is also looked up
|
|
157
|
+
there.
|
|
158
|
+
* `"` is a literal symbol, and the ASCII punctuation
|
|
159
|
+
`! # $ % & ' * + , - . / : ; < = > ? @ ^ _ |` reads as operators.
|
|
160
|
+
* Numbers are digit strings, with an optional decimal part:
|
|
161
|
+
`1`, `1.5`, `.5`. Hexadecimal (`0x1F`), binary (`0b101`) and octal
|
|
162
|
+
(`0o17`) numbers are separate forms.
|
|
163
|
+
* `\ ` is a space and `\;` a thick space.
|
|
164
|
+
|
|
165
|
+
Each symbol in the model is a `MathSymbol` with three fields: `spelling`
|
|
166
|
+
(the text matched), `value` (its Unicode text from the table) and `kind`
|
|
167
|
+
(`symbol`, `open` or `close`). A spelling the table lacks stands for itself.
|
|
168
|
+
|
|
169
|
+
=== Decimal marker
|
|
170
|
+
|
|
171
|
+
The decimal marker is `.` unless the caller passes `decimal: ","` or
|
|
172
|
+
`decimal: "٫"`. The grammar has one entry for each marker, and only the
|
|
173
|
+
chosen marker is read as part of a number.
|
|
174
|
+
|
|
175
|
+
== The typed model
|
|
176
|
+
|
|
177
|
+
`Latexmath.parse` returns a `Latexmath::Model::Document` with `expression`
|
|
178
|
+
(the formula) and `decimal` (the marker). Input with no formula gives a
|
|
179
|
+
document whose `expression` is nil. The model has 33 generated classes; the
|
|
180
|
+
names follow the grammar captures (`Binary`, `UnaryFunctions`,
|
|
181
|
+
`LeftRight`, `Environment`, `TableData`, `PowerBase` and so on). Every field
|
|
182
|
+
with its type is listed in `model/latex.lml.json`.
|
|
183
|
+
|
|
184
|
+
[[examples]]
|
|
185
|
+
== Examples
|
|
186
|
+
|
|
187
|
+
These results were produced by parsing each input with `Latexmath.parse` at
|
|
188
|
+
this revision and printing the non-empty fields of the model. A symbol is
|
|
189
|
+
shown as `MathSymbol(spelling)`. The root of the expression is a
|
|
190
|
+
`LatexTree`.
|
|
191
|
+
|
|
192
|
+
[source]
|
|
193
|
+
----
|
|
194
|
+
a^2
|
|
195
|
+
LatexTree(power: Power(supscript: Supscript(number: "2"), symbols: MathSymbol("a")))
|
|
196
|
+
|
|
197
|
+
x_i^2
|
|
198
|
+
LatexTree(power_base: PowerBase(subscript: Subscript(symbols: MathSymbol("i")),
|
|
199
|
+
supscript: Supscript(number: "2"), symbols: MathSymbol("x")))
|
|
200
|
+
|
|
201
|
+
\frac{a}{b}
|
|
202
|
+
LatexTree(binary: Binary(binary: Binary(literal: "frac"),
|
|
203
|
+
first_value: FirstValue(expression: Expression(symbols: MathSymbol("a"))),
|
|
204
|
+
second_value: SecondValue(expression: Expression(symbols: MathSymbol("b")))))
|
|
205
|
+
|
|
206
|
+
{a \over b}
|
|
207
|
+
LatexTree(over: Over(dividend: Dividend(items: [ItemsItem(symbols: MathSymbol("a"))]),
|
|
208
|
+
divisor: Divisor(items: [ItemsItem(symbols: MathSymbol("b"))])))
|
|
209
|
+
|
|
210
|
+
\sqrt[3]{x}
|
|
211
|
+
LatexTree(binary: Binary(first_value: FirstValue(expression: Expression(items: [ItemsItem(number: "3")]),
|
|
212
|
+
lparen: "[", rparen: "]"), root: "sqrt",
|
|
213
|
+
second_value: SecondValue(expression: Expression(symbols: MathSymbol("x")))))
|
|
214
|
+
|
|
215
|
+
\sin x
|
|
216
|
+
LatexTree(unary_functions: UnaryFunctions(first_value: FirstValue(symbols: MathSymbol("x")), unary: "sin"))
|
|
217
|
+
|
|
218
|
+
\sum_{i=1}^{n} i
|
|
219
|
+
LatexTree(ternary_class: TernaryClass(subscript: Subscript(expression: Expression(
|
|
220
|
+
expression: Expression(expression: Expression(number: "1"), sequence: Sequence(operant: "=")),
|
|
221
|
+
sequence: Sequence(symbols: MathSymbol("i")))),
|
|
222
|
+
supscript: Supscript(expression: Expression(symbols: MathSymbol("n"))),
|
|
223
|
+
ternary_functions: "sum", third_value: ThirdValue(symbols: MathSymbol("i"))))
|
|
224
|
+
|
|
225
|
+
\left( x \right)
|
|
226
|
+
LatexTree(left_right: LeftRight(expression: Expression(symbols: MathSymbol("x")),
|
|
227
|
+
left: "\\left", left_paren: LeftParen(literal: "("),
|
|
228
|
+
right: "\\right", right_paren: RightParen(literal: ")")))
|
|
229
|
+
|
|
230
|
+
\left( x
|
|
231
|
+
LatexTree(left_right: LeftRight(expression: Expression(symbols: MathSymbol("x")),
|
|
232
|
+
left: "\\left", left_paren: LeftParen(literal: "(")))
|
|
233
|
+
|
|
234
|
+
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
|
|
235
|
+
LatexTree(environment: Environment(ending: Ending(environment: Environment(literal: "pmatrix")),
|
|
236
|
+
environment: Environment(literal: "pmatrix"),
|
|
237
|
+
table_data: TableData(expression: Expression(expression: Expression(expression: Expression(
|
|
238
|
+
expression: Expression(expression: Expression(expression: Expression(symbols: MathSymbol("d")),
|
|
239
|
+
sequence: Sequence(operant: "&")), sequence: Sequence(symbols: MathSymbol("c"))),
|
|
240
|
+
sequence: Sequence(row_break: "\\\\")), sequence: Sequence(symbols: MathSymbol("b"))),
|
|
241
|
+
sequence: Sequence(operant: "&")), sequence: Sequence(symbols: MathSymbol("a")))))
|
|
242
|
+
|
|
243
|
+
\mathbf{x}
|
|
244
|
+
LatexTree(fonts: "mathbf", intermediate_exp: IntermediateExp(expression: Expression(symbols: MathSymbol("x"))))
|
|
245
|
+
|
|
246
|
+
\text{if } x
|
|
247
|
+
LatexTree(expression: Expression(symbols: MathSymbol("x")),
|
|
248
|
+
sequence: Sequence(first_value: FirstValue(text_list: "if "), text: "text"))
|
|
249
|
+
|
|
250
|
+
\alpha
|
|
251
|
+
LatexTree(symbols: MathSymbol("alpha"))
|
|
252
|
+
|
|
253
|
+
1.5
|
|
254
|
+
LatexTree(number: "1.5")
|
|
255
|
+
|
|
256
|
+
\frac{a}
|
|
257
|
+
Latexmath::ParseError at char 8
|
|
258
|
+
----
|
|
259
|
+
|
|
260
|
+
Fields inside each class are printed in the order the class declares them,
|
|
261
|
+
not in input order.
|
|
262
|
+
|
|
263
|
+
== Errors
|
|
264
|
+
|
|
265
|
+
Input the grammar does not match raises `Latexmath::ParseError`. The error
|
|
266
|
+
gives the position as a character and byte offset in the caller's text, and
|
|
267
|
+
the position in the rewritten text as `grammar_char_offset` and
|
|
268
|
+
`grammar_byte_offset`. The wording of the message is not part of the
|
|
269
|
+
contract. Input nested deeper than the native engine allows is parsed with
|
|
270
|
+
the Ruby engine by default, or raises `Latexmath::NestingTooDeep` when the
|
|
271
|
+
native engine is requested.
|
|
272
|
+
|
|
273
|
+
== Conformance
|
|
274
|
+
|
|
275
|
+
* `spec/model/parse_spec.rb` checks the public parse and its errors.
|
|
276
|
+
* `spec/corpus/replay_corpus_spec.rb` and `spec/stage_cases/` replay the
|
|
277
|
+
stage corpus generation pinned in `spec/fixtures/testsuite-pin.yml`
|
|
278
|
+
(plurimath-testsuite `stages/latex/`, generation 2, 139 cases).
|
|
279
|
+
* `spec/parser/oracle_parity_spec.rb` compares the raw tree with captures of
|
|
280
|
+
the Plurimath parser.
|
|
281
|
+
|
|
282
|
+
== Open questions
|
|
283
|
+
|
|
284
|
+
* Whether the mismatch between `\begin{name}` and `\end{other}` should be
|
|
285
|
+
refused: not specified.
|
|
286
|
+
* Whether `\left` without `\right` is intended or a legacy leniency: not
|
|
287
|
+
specified.
|
|
288
|
+
* The meaning of the model for commands that legacy keeps without a
|
|
289
|
+
dedicated class (for example `\rule`): not specified beyond the captures.
|
data/docs/testsuite-pin.adoc
CHANGED
|
@@ -11,16 +11,28 @@ named in `spec/fixtures/testsuite-pin.yml`:
|
|
|
11
11
|
----
|
|
12
12
|
schema: plurimath-stage/pin/1
|
|
13
13
|
repository: https://github.com/plurimath/plurimath-testsuite
|
|
14
|
-
commit:
|
|
14
|
+
commit: 337262eda0483ceaa43a02cc52362c5b721e5eb3
|
|
15
15
|
language: latex
|
|
16
|
-
generation:
|
|
17
|
-
snapshot_digest: sha256:
|
|
16
|
+
generation: 3
|
|
17
|
+
snapshot_digest: sha256:782cb6ee7c75ec1e38ed343301c2220ad14c283b96e5cf9eac2a4ff39b1aeceb
|
|
18
18
|
----
|
|
19
19
|
|
|
20
20
|
Generation 2 keeps every case of generation 1 (the legacy corpus, produced by
|
|
21
21
|
Plurimath 0.11.12) byte for byte and adds a raw-tree row for each of its 139
|
|
22
22
|
cases, rejections included, written by `scripts/stage_cases.rb`.
|
|
23
23
|
|
|
24
|
+
Generation 3 keeps every payload of generation 2 byte for byte and adds a
|
|
25
|
+
typed-model row for each of the 139 cases beside the raw-tree rows. The
|
|
26
|
+
replay compares both.
|
|
27
|
+
|
|
28
|
+
The typed-model rows were written before `Latexmath::Model::MathSymbol`
|
|
29
|
+
declared `value` and `kind`, so 108 of them have symbols without those two
|
|
30
|
+
fields. Both are derived attributes, computed from `spelling`. The replay
|
|
31
|
+
leaves a derived attribute out of the comparison when the row's object does
|
|
32
|
+
not record it, and lists those rows in its report
|
|
33
|
+
(`unrecorded_derived_rows`). A derived attribute that a row does record must
|
|
34
|
+
match, like every other field.
|
|
35
|
+
|
|
24
36
|
== What CI checks
|
|
25
37
|
|
|
26
38
|
The `corpus` workflow checks out the testsuite at the pinned commit and then:
|
|
@@ -39,14 +51,17 @@ The `corpus` workflow checks out the testsuite at the pinned commit and then:
|
|
|
39
51
|
`Latexmath::RawParser.parse` on the Ruby and the native engine. Each
|
|
40
52
|
engine's result, the preprocessed text and tree or the refusal and its byte
|
|
41
53
|
offset, must equal the row's expected value in the canonical form of the
|
|
42
|
-
testsuite's `docs/tree-parity-contract.adoc`.
|
|
54
|
+
testsuite's `docs/tree-parity-contract.adoc`. It then parses every row of
|
|
55
|
+
every typed-model payload with `Latexmath.parse` on both engines and
|
|
56
|
+
compares the model in the form `scripts/stage_cases.rb` writes, as
|
|
57
|
+
described above.
|
|
43
58
|
|
|
44
59
|
To run the replay locally:
|
|
45
60
|
|
|
46
61
|
[source,sh]
|
|
47
62
|
----
|
|
48
63
|
git clone https://github.com/plurimath/plurimath-testsuite tmp/testsuite
|
|
49
|
-
git -C tmp/testsuite checkout
|
|
64
|
+
git -C tmp/testsuite checkout 337262eda0483ceaa43a02cc52362c5b721e5eb3
|
|
50
65
|
bundle exec ruby scripts/replay_corpus.rb --testsuite tmp/testsuite --report tmp/replay.json
|
|
51
66
|
----
|
|
52
67
|
|
|
@@ -902,10 +902,12 @@ module Latexmath
|
|
|
902
902
|
end
|
|
903
903
|
|
|
904
904
|
# A catalog capture (+symbols+, +unicode_symbols+): the spelling the
|
|
905
|
-
# grammar matched. Its Unicode value and kind are
|
|
906
|
-
# table (lib/latexmath/model.rb).
|
|
905
|
+
# grammar matched. Its Unicode value and kind are derived from the
|
|
906
|
+
# spelling through the symbol table (lib/latexmath/model.rb).
|
|
907
907
|
class MathSymbol < Lutaml::Model::Serializable
|
|
908
908
|
attribute :spelling, :string
|
|
909
|
+
attribute :value, :string
|
|
910
|
+
attribute :kind, :string
|
|
909
911
|
end
|
|
910
912
|
|
|
911
913
|
# The root: one parsed formula (binding +model+), and the decimal
|
data/lib/latexmath/model.rb
CHANGED
|
@@ -13,6 +13,12 @@ module Latexmath
|
|
|
13
13
|
# (Document.new on the grammar's model binding). No code here walks the
|
|
14
14
|
# parse tree. See docs/model-contract.adoc.
|
|
15
15
|
module Model
|
|
16
|
+
# Stage-computed fields stay distinct from grammar-bound captures even
|
|
17
|
+
# though their portable LML declarations are ordinary typed strings.
|
|
18
|
+
def self.catalog_field?(klass, name)
|
|
19
|
+
klass.is_a?(Class) && klass <= MathSymbol && %w[value kind].include?(name.to_s)
|
|
20
|
+
end
|
|
21
|
+
|
|
16
22
|
end
|
|
17
23
|
end
|
|
18
24
|
|
|
@@ -20,24 +26,33 @@ require_relative "model/nodes"
|
|
|
20
26
|
|
|
21
27
|
module Latexmath
|
|
22
28
|
module Model
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
# Latexmath::Symbols). A spelling the table lacks is a plain symbol of
|
|
26
|
-
# its own text, kind "symbol".
|
|
29
|
+
# +value+ and +kind+ of a symbol are derived attributes: they are
|
|
30
|
+
# exported (and serialized) but never part of the bound data.
|
|
27
31
|
class MathSymbol
|
|
28
|
-
#
|
|
32
|
+
# Keep the Ruby convenience readers live while the portable schema
|
|
33
|
+
# carries ordinary typed values. Reads do not change default tracking.
|
|
34
|
+
def value
|
|
35
|
+
@value = symbol_value
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def kind
|
|
39
|
+
@kind = symbol_kind
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The Symbols::Entry for #spelling, looked up from its spelling,
|
|
43
|
+
# stripped, as in the legacy transform.
|
|
29
44
|
def entry
|
|
30
45
|
Latexmath::Symbols.resolve(spelling.to_s)
|
|
31
46
|
end
|
|
32
47
|
|
|
33
48
|
# The Unicode text the symbol stands for.
|
|
34
|
-
def
|
|
35
|
-
entry.value
|
|
49
|
+
def symbol_value
|
|
50
|
+
spelling && entry.value
|
|
36
51
|
end
|
|
37
52
|
|
|
38
53
|
# "symbol", "open" or "close".
|
|
39
|
-
def
|
|
40
|
-
entry.kind
|
|
54
|
+
def symbol_kind
|
|
55
|
+
spelling && entry.kind
|
|
41
56
|
end
|
|
42
57
|
end
|
|
43
58
|
end
|
|
@@ -125,6 +125,9 @@ module Latexmath
|
|
|
125
125
|
reporter = Parsanol::ErrorReporter::Deepest.new
|
|
126
126
|
root.parse(text, reporter: reporter)
|
|
127
127
|
end
|
|
128
|
+
rescue Parsanol::RecursionLimitExceeded => e
|
|
129
|
+
# parsanol 1.3.134+ raises this for native deep nesting.
|
|
130
|
+
raise NativeRecursionLimit, e.message.lines.first.to_s.strip, cause: nil
|
|
128
131
|
rescue Parsanol::ParseFailed => e
|
|
129
132
|
record(mode)
|
|
130
133
|
raise parse_error(e, reporter, text)
|
data/lib/latexmath/version.rb
CHANGED
|
@@ -17,7 +17,7 @@ Latexmath::Model::LatexTree sha256:ab699f312f98a337d0443fb0e46e901ec3a5f02d3b1dc
|
|
|
17
17
|
Latexmath::Model::LeftParen sha256:9948524e67fa426033187ebc1c9e015e2c5e3a4ace59b81ca3d223de9e849484
|
|
18
18
|
Latexmath::Model::LeftRight sha256:d219a07366ebf63b556957d75d0a2ef9a7b0b4d69db9d5a47cef3ba198673072
|
|
19
19
|
Latexmath::Model::Limits sha256:04d4af34438ccab20272798c0d23877dd1a14cc95c01290ffc37ba156d1a8a0c
|
|
20
|
-
Latexmath::Model::MathSymbol sha256:
|
|
20
|
+
Latexmath::Model::MathSymbol sha256:116d6d3b4a5479fefb4bb164db72ebaa7a135890eb64f7cc74313253472bf55c
|
|
21
21
|
Latexmath::Model::Options sha256:09363eec7dc62f50a06ea6a1065280fbeaef1385e2e84f1da92f7df4e9a01e6c
|
|
22
22
|
Latexmath::Model::Over sha256:5ec5c3ccd41a5c65149887cbed15632ac8dd2a05bd66ba337cde4b6cb1cee7c1
|
|
23
23
|
Latexmath::Model::Power sha256:6bf73b69d65980865f2c1d8922e0a2ab6c43c76d96f9135b94f9ffb2936da81a
|
|
@@ -33,4 +33,4 @@ Latexmath::Model::TernaryClass sha256:bd741ce478aa270bd90cd24c9e2e8a073afc750e97
|
|
|
33
33
|
Latexmath::Model::ThirdValue sha256:2ce323686afb2f7ad053ac49a62eb1dc092cbddd126f94f5ac2bc39cf043c4ac
|
|
34
34
|
Latexmath::Model::UnaryFunctions sha256:df5b690a991e6963faecbfdd2bebb06deb319bd0485d20c48379a3d844a67326
|
|
35
35
|
Latexmath::Model::UnderOver sha256:a6e7aa8d2ae55610b8473eed4fa39481c75bbfc09e1a44f4d14fd2df63ce8713
|
|
36
|
-
model/latex.lml.json sha256:
|
|
36
|
+
model/latex.lml.json sha256:b39479e2751d37c2b4d2d42f7dd630173d0360d1e9b03c1d035bd24f7f7c0f84
|
data/model/latex.lml.json
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: latexmath
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: htmlentities
|
|
@@ -53,7 +53,7 @@ dependencies:
|
|
|
53
53
|
version: '1.3'
|
|
54
54
|
- - ">="
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: 1.3.
|
|
56
|
+
version: 1.3.134
|
|
57
57
|
type: :runtime
|
|
58
58
|
prerelease: false
|
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -63,7 +63,7 @@ dependencies:
|
|
|
63
63
|
version: '1.3'
|
|
64
64
|
- - ">="
|
|
65
65
|
- !ruby/object:Gem::Version
|
|
66
|
-
version: 1.3.
|
|
66
|
+
version: 1.3.134
|
|
67
67
|
description: |
|
|
68
68
|
LaTeX math parser that runs a compiled Parsanol grammar artifact and
|
|
69
69
|
returns a typed LaTeX model declared with LutaML Model. Used by
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- artifacts/latex.checksums.txt
|
|
85
85
|
- artifacts/latex.json
|
|
86
86
|
- data/latex-symbols.json
|
|
87
|
+
- docs/latex.adoc
|
|
87
88
|
- docs/model-contract.adoc
|
|
88
89
|
- docs/parser-contract.adoc
|
|
89
90
|
- docs/testsuite-pin.adoc
|