Skip to content

Commit 338b7bc

Browse files
committed
OMML/MathML writers: Use upright font for numbers by default
Fixes rendering of numbers in OMML and MathML output to use upright (roman) font style by default, matching the behavior of other LaTeX engines and typographic standards. ## Background and Rationale According to typographic standards and mathematical typesetting conventions: 1. **ISO 80000-2 Standard** (Quantities and units — Part 2: Mathematics) specifies that numbers should be set in upright (roman) font. 2. **LaTeX Default Behavior**: In math mode, LaTeX renders digits in upright font by default. The Computer Modern font family, used by default in LaTeX, has separate italic and upright variants, and numbers always use the upright variant in math mode. 3. **MathML Specification**: The `<mn>` element represents "numeric literal" content and should be rendered with upright font styling unless explicitly overridden with mathvariant attribute. 4. **OMML Specification**: Numbers in Office Math ML should use m:sty="p" (plain/roman) to indicate upright font. ## What Changed ### OMML Writer (src/Text/TeXMath/Writers/OMML.hs) - Numbers now get m:sty="p" attribute by default when no explicit style is set, matching the treatment of uppercase Greek letters (see #255) ### MathML Writer (src/Text/TeXMath/Writers/MathML.hs) - `<mn>` elements now get mathvariant="normal" attribute by default when no explicit style is set, matching the treatment of uppercase Greek letters (see #255) ### Test Data Fix - Fixed test/writer/omml/simplePres.test: Changed ENumber "\946" (β) to EIdentifier "\946", as Greek letters should be identifiers, not numbers ## Examples Before: OMML: `<m:r><m:t>123</m:t></m:r>` (rendered as italic in Word) MathML: `<mn>123</mn>` (may render as italic depending on context) After: OMML: `<m:r><m:rPr><m:sty m:val="p" /></m:rPr><m:t>123</m:t></m:r>` MathML: `<mn mathvariant="normal">123</mn>` ## Compatibility - Explicitly styled numbers (e.g., $\mathit{123}$) still render as italic - Variables remain italic - Uppercase Greek letters remain upright (already fixed in #255) - Lowercase Greek letters remain italic - This aligns texmath's output with standard LaTeX/pdfLaTeX behavior ## Related - Closes #255 (uppercase Greek letters fix) - Similar to: Typst issue #4139 "Italic digits do not work in math" ## References - ISO 80000-2:2019: Quantities and units — Part 2: Mathematics https://www.iso.org/standard/64973.html - "Typesetting Mathematics According to the ISO Standard" by Nick Higham https://nhigham.com/2016/01/28/typesetting-mathematics-according-to-the-iso-standard/ - "upright italics (math mode)?" - TeX StackExchange discussion https://tex.stackexchange.com/questions/431740/upright-italics-math-mode - MathML Core specification on `<mn>` element https://w3c.github.io/mathml-core/spec.html - isomath package documentation (ISO 80000-2 compliant typesetting) https://ctan.math.utah.edu/ctan/tex-archive/macros/latex/contrib/isomath/isomath.pdf
1 parent aee6b49 commit 338b7bc

File tree

436 files changed

+21351
-7465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

436 files changed

+21351
-7465
lines changed

src/Text/TeXMath/Writers/MathML.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ showExp tt e =
196196
vnode elname t
197197
= case tt of
198198
Nothing ->
199-
if isUppercaseGreek t -- see #255
199+
if elname == "mn" || isUppercaseGreek t -- see #255
200200
then withAttribute "mathvariant" "normal" $ tunode elname t
201201
else tunode elname t
202202
Just TextNormal -> withAttribute "mathvariant" "normal" $

src/Text/TeXMath/Writers/OMML.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ handleDownup' _ xs = xs
206206
showExp :: [Element] -> Exp -> [Element]
207207
showExp props e =
208208
case e of
209-
ENumber x -> [str props x]
209+
ENumber x
210+
| null props -> [str [mnodeA "sty" "p" ()] x]
211+
| otherwise -> [str props x]
210212
EGrouped [EUnderover _ (ESymbol Op s) y z, w] ->
211213
[makeNary props "undOvr" s y z w]
212214
EGrouped [ESubsup (ESymbol Op s) y z, w] ->

test/writer/mml/01.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
<mrow>
3434
<msup>
3535
<mi>b</mi>
36-
<mn>2</mn>
36+
<mn mathvariant="normal">2</mn>
3737
</msup>
3838
<mo>−</mo>
39-
<mn>4</mn>
39+
<mn mathvariant="normal">4</mn>
4040
<mi>a</mi>
4141
<mi>c</mi>
4242
</mrow>
4343
</msqrt>
4444
</mrow>
4545
<mrow>
46-
<mn>2</mn>
46+
<mn mathvariant="normal">2</mn>
4747
<mi>a</mi>
4848
</mrow>
4949
</mfrac>

test/writer/mml/02.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525
<?xml version='1.0' ?>
2626
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
2727
<mrow>
28-
<mn>2</mn>
28+
<mn mathvariant="normal">2</mn>
2929
<mo>=</mo>
3030
<mrow>
3131
<mo stretchy="true" form="prefix">(</mo>
3232
<mfrac>
3333
<mrow>
3434
<mrow>
3535
<mo stretchy="true" form="prefix">(</mo>
36-
<mn>3</mn>
36+
<mn mathvariant="normal">3</mn>
3737
<mo>−</mo>
3838
<mi>x</mi>
3939
<mo stretchy="true" form="postfix">)</mo>
4040
</mrow>
4141
<mo>×</mo>
42-
<mn>2</mn>
42+
<mn mathvariant="normal">2</mn>
4343
</mrow>
4444
<mrow>
45-
<mn>3</mn>
45+
<mn mathvariant="normal">3</mn>
4646
<mo>−</mo>
4747
<mi>x</mi>
4848
</mrow>

test/writer/mml/03.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
<mi>a</mi>
1717
<msup>
1818
<mi>x</mi>
19-
<mn>2</mn>
19+
<mn mathvariant="normal">2</mn>
2020
</msup>
2121
<mo>+</mo>
2222
<mi>b</mi>
2323
<mi>x</mi>
2424
<mo>+</mo>
2525
<mi>c</mi>
2626
<mo>=</mo>
27-
<mn>0</mn>
27+
<mn mathvariant="normal">0</mn>
2828
</mrow>
2929
</math>

test/writer/mml/04.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
<msup>
3535
<mrow>
3636
<mo stretchy="true" form="prefix">(</mo>
37-
<mn>5</mn>
37+
<mn mathvariant="normal">5</mn>
3838
<mo>−</mo>
3939
<mi>T</mi>
4040
<mo stretchy="true" form="postfix">)</mo>
4141
</mrow>
42-
<mn>2</mn>
42+
<mn mathvariant="normal">2</mn>
4343
</msup>
44-
<mn>2</mn>
44+
<mn mathvariant="normal">2</mn>
4545
</mfrac>
4646
</mrow>
4747
</math>

test/writer/mml/06.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<mrow>
4141
<mi>m</mi>
4242
<mo>=</mo>
43-
<mn>1</mn>
43+
<mn mathvariant="normal">1</mn>
4444
</mrow>
4545
<mo accent="false">∞</mo>
4646
</munderover>
@@ -49,37 +49,37 @@
4949
<mrow>
5050
<mi>n</mi>
5151
<mo>=</mo>
52-
<mn>1</mn>
52+
<mn mathvariant="normal">1</mn>
5353
</mrow>
5454
<mo accent="false">∞</mo>
5555
</munderover>
5656
<mfrac>
5757
<mrow>
5858
<msup>
5959
<mi>m</mi>
60-
<mn>2</mn>
60+
<mn mathvariant="normal">2</mn>
6161
</msup>
6262
<mspace width="0.167em" />
6363
<mi>n</mi>
6464
</mrow>
6565
<mrow>
6666
<msup>
67-
<mn>3</mn>
67+
<mn mathvariant="normal">3</mn>
6868
<mi>m</mi>
6969
</msup>
7070
<mrow>
7171
<mo stretchy="true" form="prefix">(</mo>
7272
<mi>m</mi>
7373
<mspace width="0.167em" />
7474
<msup>
75-
<mn>3</mn>
75+
<mn mathvariant="normal">3</mn>
7676
<mi>n</mi>
7777
</msup>
7878
<mo>+</mo>
7979
<mi>n</mi>
8080
<mspace width="0.167em" />
8181
<msup>
82-
<mn>3</mn>
82+
<mn mathvariant="normal">3</mn>
8383
<mi>m</mi>
8484
</msup>
8585
<mo stretchy="true" form="postfix">)</mo>

test/writer/mml/09.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<mo>→</mo>
2626
<msub>
2727
<mi>z</mi>
28-
<mn>0</mn>
28+
<mn mathvariant="normal">0</mn>
2929
</msub>
3030
</mrow>
3131
</munder>
@@ -41,7 +41,7 @@
4141
<mo stretchy="true" form="prefix">(</mo>
4242
<msub>
4343
<mi>z</mi>
44-
<mn>0</mn>
44+
<mn mathvariant="normal">0</mn>
4545
</msub>
4646
<mo stretchy="true" form="postfix">)</mo>
4747
</mrow>

test/writer/mml/10.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@
5656
</mrow>
5757
<mo>=</mo>
5858
<mfrac>
59-
<mn>1</mn>
59+
<mn mathvariant="normal">1</mn>
6060
<mrow>
61-
<mn>4</mn>
61+
<mn mathvariant="normal">4</mn>
6262
<msup>
6363
<mi>π</mi>
64-
<mn>2</mn>
64+
<mn mathvariant="normal">2</mn>
6565
</msup>
6666
<msup>
6767
<mi>κ</mi>
68-
<mn>2</mn>
68+
<mn mathvariant="normal">2</mn>
6969
</msup>
7070
</mrow>
7171
</mfrac>
7272
<msubsup>
7373
<mo>∫</mo>
74-
<mn>0</mn>
74+
<mn mathvariant="normal">0</mn>
7575
<mi>∞</mi>
7676
</msubsup>
7777
<mfrac>
@@ -103,7 +103,7 @@
103103
<mo stretchy="true" form="prefix">[</mo>
104104
<msup>
105105
<mi>R</mi>
106-
<mn>2</mn>
106+
<mn mathvariant="normal">2</mn>
107107
</msup>
108108
<mfrac>
109109
<mrow>

test/writer/mml/11.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,38 @@
3636
<mo stretchy="true" form="postfix">)</mo>
3737
</mrow>
3838
<mo>=</mo>
39-
<mn>0.033</mn>
39+
<mn mathvariant="normal">0.033</mn>
4040
<msubsup>
4141
<mi>C</mi>
4242
<mi>n</mi>
43-
<mn>2</mn>
43+
<mn mathvariant="normal">2</mn>
4444
</msubsup>
4545
<msup>
4646
<mi>κ</mi>
4747
<mrow>
4848
<mo>−</mo>
49-
<mn>11</mn>
49+
<mn mathvariant="normal">11</mn>
5050
<mi>/</mi>
51-
<mn>3</mn>
51+
<mn mathvariant="normal">3</mn>
5252
</mrow>
5353
</msup>
5454
<mo>,</mo>
5555
<mspace width="1.0em" />
5656
<mfrac>
57-
<mn>1</mn>
57+
<mn mathvariant="normal">1</mn>
5858
<msub>
5959
<mi>L</mi>
60-
<mn>0</mn>
60+
<mn mathvariant="normal">0</mn>
6161
</msub>
6262
</mfrac>
6363
<mo>≪</mo>
6464
<mi>κ</mi>
6565
<mo>≪</mo>
6666
<mfrac>
67-
<mn>1</mn>
67+
<mn mathvariant="normal">1</mn>
6868
<msub>
6969
<mi>l</mi>
70-
<mn>0</mn>
70+
<mn mathvariant="normal">0</mn>
7171
</msub>
7272
</mfrac>
7373
</mrow>

0 commit comments

Comments
 (0)