Skip to content

Conversation

@val3344
Copy link

@val3344 val3344 commented Jan 7, 2026

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)

MathML Writer (src/Text/TeXMath/Writers/MathML.hs)

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 \Omega results in MathML in italics #255)
  • Lowercase Greek letters remain italic
  • This aligns texmath's output with standard LaTeX/pdfLaTeX behavior

Related

References

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 jgm#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 jgm#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 jgm#255)
- Lowercase Greek letters remain italic
- This aligns texmath's output with standard LaTeX/pdfLaTeX behavior

## Related

- Closes jgm#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
@jgm
Copy link
Owner

jgm commented Jan 7, 2026

I'm on board with rendering numbers with an upright font. But doesn't this work already? If I use pandoc to convert $123$ to Word, then open the result in Word, it looks like this:
image
(screenshot)
which as you can see is upright. In the OMML we just have <m:t>. So, I don't see anything that is broken here.

Similarly, with the MathML output: as you note, the spec says that mn elements should be rendered with an upright font. That's pretty clear. So, we shouldn't need to explicitly tell it to do that -- that is the default. A consumer of MathML that renders an unmarked mn as italics is not conforming to the spec.

@val3344
Copy link
Author

val3344 commented Jan 8, 2026

My apologies - this was my mistake.

I discovered this issue when opening the converted docx file with WPS on Linux. I happened to see jgm/pandoc#7136 and assumed it was the same problem. So I made the changes in this PR by referencing 87f05f4.

After seeing your response, I checked with MS Office Word on Windows and LibreOffice Writer on Linux, and there are no issues with those. So this is a problem with WPS Linux, not with pandoc or texmath.

@val3344 val3344 closed this Jan 8, 2026
@val3344 val3344 deleted the upright-numbers branch January 8, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

\Omega results in MathML in italics

2 participants