LaTeX, MathML, and native Word equations: a tested conversion reference

A technical, reproducible reference for moving AI-generated LaTeX through MathML into editable Microsoft Word equations and Chromium PDF output.

An equation that looks correct in an AI chat window is not automatically a Word equation. Chat interfaces commonly render LaTeX with a browser math engine. Microsoft Word stores editable equations using Office Math Markup Language (OMML). A robust converter therefore has to recognize the source expression, create a mathematical structure, and package it in the format Word expects.

This guide explains that pipeline and records input patterns tested in AIText2Doc. It complements the live compatibility matrix, which separates supported, limited, and intentionally unsupported cases.

The conversion pipeline

The DOCX path has four distinct stages:

  1. Detect equation boundaries in the copied AI text.
  2. Normalize common copy artifacts without changing mathematical meaning.
  3. Convert the supported LaTeX expression into MathML.
  4. Transform the mathematical structure into OMML for the DOCX package.

The PDF path is different. It uses formatted HTML and MathML output and asks headless Chromium to print the document. This avoids flattening the equation into plain text and preserves structures such as fraction bars and scripts.

The Microsoft Open XML documentation describes OMML as the Office representation for mathematical content. The W3C MathML Core specification defines browser-oriented mathematical markup used in the preview and PDF stage.

Delimiters tested by AIText2Doc

The converter recognizes:

  • Inline dollar delimiters: $x^2$.
  • Display dollar delimiters: $$x^2+y^2=z^2$$.
  • Inline LaTeX delimiters: \(x^2\).
  • Display LaTeX delimiters: \[x^2+y^2=z^2\].
  • Standalone bracket blocks when bracket detection is enabled.
  • Equation-like parentheses when parenthesis detection is enabled.

Parenthesis detection is heuristic. A short expression containing equality, scripts, units, LaTeX commands, or scientific symbols is likely mathematics. A long explanatory sentence is likely prose. Use explicit delimiters when you can edit the source.

Tested inline quantities

Scientific AI responses often encode quantities like this:

On considère un corps de masse (m = 500,g = 0{,}5,kg)
placé à une hauteur (h = 30,m).

The intended output contains m = 500 g = 0,5 kg and h = 30 m. The braces inside 0{,}5 represent a decimal comma. The other commas act as visual spacing before units or another assignment.

AIText2Doc uses targeted normalization for known patterns. It does not delete all commas because commas are legitimate in coordinates, function arguments, probability notation, and prose.

A second regression case is (g = 10,\text{N/kg}). The expected equation is g = 10 N/kg, not g = 10,N/kg.

Fractions and reaction quotients

Fractions must remain structural. Replacing \frac{a}{b} with a/b is readable but does not preserve the source presentation.

A chemistry regression case is:

[
Q_{r,eq}=\frac{[\mathrm{H_3O^+}]_{eq}[\mathrm{CH_3CH_2COO^-}]_{eq}}
{[\mathrm{CH_3CH_2COOH}]_{eq}}
]

The expected result includes:

  • Q with r,eq as a subscript.
  • Hydronium and propanoate concentrations in the numerator.
  • Propanoic acid concentration in the denominator.
  • A visible fraction line.
  • Correct equilibrium indices and ionic charges.

The DOCX stores this as a Word equation object. Chromium prints the MathML fraction in the PDF. The regression pack includes this case because it exercises fractions, brackets, chemistry subscripts, charges, and equilibrium indices together.

Subscripts, superscripts, and isotopes

Simple scripts such as E_{pp} and 10^{-2} map to lower and upper structures. Isotopes are harder because the mass and atomic numbers appear before the element:

{}^{235}_{92}U

Earlier Word output could show a dotted placeholder representing an empty base before the scripts. The current DOCX logic keeps the left scripts visually attached to the following element without exposing an empty placeholder.

Known AI copy formats may include separators such as ! or *, for example {}^{235}*{92}U. These characters may be invisible in chat rendering but present in copied text. AIText2Doc normalizes recognized isotope patterns. The preferred source remains {}^{235}_{92}U.

Chemistry charges and molecular indices

Chemistry requires distinguishing a molecular subscript from an ionic charge:

  • H_2O places 2 below the baseline.
  • H^+ places the charge above the baseline.
  • Mg^{2+} keeps magnitude and sign together.
  • SO_4^{2-} combines a molecular subscript and charge.

Plain text such as Mg2+ is ambiguous. Explicit scripts make the intended structure clear and more editable.

The \mathrm{...} command can keep chemical symbols upright. Commands from specialized chemistry packages are outside the current regression set and should be rewritten using standard LaTeX when possible.

Multiplication artifacts

Some copied AI output uses commas around a visible multiplication point:

W_e = U_{AB},.,I,.,\Delta t

The intended expression is W_e = U_{AB} · I · Δt. The commas are spacing artifacts; the points represent multiplication and must remain.

Normalization targets the sequence rather than globally replacing punctuation. A broad comma rule would damage decimal values. A broad point rule would remove multiplication.

When the copied pattern is unclear, simplify it to W_e = U_{AB} \cdot I \cdot \Delta t.

Protecting prose from equation detection

Consider:

(Cela signifie : quand le corps monte, (z) augmente,
donc (\Delta E_{pp}>0) et le travail du poids est négatif.)

The outer parentheses contain prose. Treating the whole sentence as mathematics collapses spaces and italicizes ordinary words. AIText2Doc protects long prose-like parentheses and converts the equation fragments.

This protection cannot infer every language or notation. Explicit delimiters remain safest when editing is possible.

Intentionally unsupported arrays

AI models sometimes use this pattern to draw vertical arithmetic:

\begin{array}{r c r}
& & 23 \\
& + & 45 \\
\hline
& = & \ldots
\end{array}

This is a layout instruction, not just an equation. Mapping it into one Word equation creates fragile spacing and inconsistent lines. Mapping it into a Word table requires a separate document-layout converter.

AIText2Doc detects worksheet-style arrays, marks them unsupported, prevents DOCX/PDF download, and explains how to proceed. Blocking an unreliable format is safer than silently generating a malformed file.

How to validate Word output

After download, click an equation in Word. It should behave as a mathematical object rather than an image or plain text.

Check that:

  • A fraction has a horizontal bar.
  • A superscript is above the normal baseline.
  • A subscript remains attached to the intended symbol.
  • An isotope has no empty placeholder.
  • A bullet list remains bulleted.
  • Inline equations stay inside their sentences.
  • Display equations occupy separate paragraphs.

If DOCX is correct but PDF is wrong, report a PDF rendering regression. If preview is already wrong, simplify the source before checking exports.

Minimal regression set

Use this after converter changes:

Inline: (h = 30,m)

[
\frac{x^2+1}{\sqrt{x}}
]

Ion: (\mathrm{Mg^{2+}})
Isotope: ({}^{235}_{92}\mathrm{U})

It covers inline detection, units, fractions, exponents, roots, chemistry charges, and left-side isotope scripts. The full regression pack also tests lists, decimal commas, reaction quotients, prose protection, and nuclear reactions.

Correct the source or report a bug?

Correct the source when braces are unmatched, custom commands are unsupported, delimiters are missing, or the AI generated a layout array.

Report a converter issue when:

  • A case in the regression pack previously worked and now fails.
  • Preview and DOCX disagree structurally.
  • DOCX contains an isotope placeholder.
  • PDF loses a fraction line or attaches a script to the wrong symbol.
  • A bullet list becomes numbering.

A short reproducible input is more useful than a complete private document.

References and related testing

This page is updated when a regression case is added or supported syntax changes.