LaTeX Equations¶
papersmith converts LaTeX math expressions into native Office MathML (OMML), which renders as editable equations inside Microsoft Word.
Inline Equations¶
Wrap LaTeX in single dollar signs within add_text():
doc.add_text("Einstein's equation is $E = mc^2$ and it changed physics.")
doc.add_text("The integral $\\int_0^\\infty e^{-x} dx = 1$ converges.")
Display Equations¶
Use add_equation() for centered, standalone equations:
doc.add_equation(r"F = G \frac{m_1 m_2}{r^2}")
doc.add_equation(r"\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}")
doc.add_equation(r"\nabla \times \mathbf{E} = -\frac{\partial \mathbf{B}}{\partial t}")
Note
Display equations are automatically centered. Do not include $ delimiters in add_equation().
How It Works¶
papersmith uses a three-stage pipeline:
graph LR
A[LaTeX String] --> B[MathML]
B --> C[OMML via XSLT]
C --> D[Word Document]
- LaTeX → MathML: Uses
latex2mathmlto parse the expression - MathML → OMML: Applies an XSLT transform (bundled or from Office)
- OMML → Document: Inserts the native Office math XML into the paragraph
Supported LaTeX¶
Most standard math constructs are supported:
| Category | Examples |
|---|---|
| Fractions | \frac{a}{b} |
| Subscripts/Superscripts | x_i, x^2, x_i^2 |
| Greek letters | \alpha, \beta, \gamma, \Omega |
| Operators | \sum, \prod, \int, \lim |
| Roots | \sqrt{x}, \sqrt[3]{x} |
| Matrices | \begin{pmatrix} a & b \\ c & d \end{pmatrix} |
| Decorations | \hat{x}, \bar{x}, \vec{v}, \dot{x} |
| Delimiters | \left(, \right), \left[, \right] |
Fallback Behavior¶
If a LaTeX expression fails to render (e.g., unsupported syntax), papersmith inserts it as italic plain text with a warning: