Skip to content

Commit 56edc14

Browse files
Omikhleiaalerque
authored andcommitted
fix(math): A period must be allowed in TeX-like math syntax for numbers
1 parent cb4d6e4 commit 56edc14

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/math/texlike.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,19 @@ local mathGrammar = function (_ENV)
1818
local _ = WS^0
1919
local eol = S"\r\n"
2020
local digit = R("09")
21-
local natural = digit^1 / tostring
21+
local natural = (
22+
-- TeX doesn't really knows what a number in a formula is.
23+
-- It handles any sequence of "ordinary" characters, including period(s):
24+
-- See for instance The TeXbook, p. 132.
25+
-- When later converting to MathML, we'll ideally want <mn>0.0123</mn>
26+
-- instead of, say, <mn>0</mn><mo>.</mo><mn>0123</mn> (not only wrong
27+
-- in essence, but also taking the risk of using a <mo> operator, then
28+
-- considered as a punctuation, thus inserting a space)
29+
-- We cannot be general, but checking MathJax and TeMML's behavior, they
30+
-- are not general either in this regard.
31+
digit^0 * P(".")^-1 * digit^1 + -- Decimal number (ex: 1.23, 0.23, .23)
32+
digit^1 -- Integer (digits only, ex: 123)
33+
) / tostring
2234
local pos_natural = R("19") * digit^0 / tonumber
2335
local ctrl_word = R("AZ", "az")^1
2436
local ctrl_symbol = P(1) - S"{}\\"

0 commit comments

Comments
 (0)