Skip to main content

Math Elements

note

The math element is currently in beta and only fully supported for DOCX output.

  • For PDF and ODT output, math rendering is not yet fully stable.
  • Complex formulas may render incorrectly or as placeholder boxes in exported PDF/ODT files.
  • For reliable math rendering, prefer DOCX and open the document in Microsoft Word.

Math elements render LaTeX formulas as native Word equations (OMML) in DOCX documents.

Math Element Properties & Defaults

Math Element Properties

PropertyTypeRequiredDescriptionDefault
typestringElement type: "math" (DOCX only)-
latexstringLaTeX math expression (inline or display style)-
alignstringHorizontal alignment: "left", "center", "right"From defaults.styles.math.align or left
spacingobjectCustom spacing override (before / after in pt)From defaults.spacing.math

Math Defaults (defaults)

Math elements can use global defaults for alignment, font size and spacing.

PropertyTypeDescription
defaults.spacing.before.mathnumberSpacing before math elements in pt (0-100)
defaults.spacing.after.mathnumberSpacing after math elements in pt (0-100)
defaults.styles.math.fontSizenumberDefault font size for math in pt
defaults.styles.math.alignstringDefault alignment for math: "left", "center", "right"

Defaults Example

{
"document": {
"type": "docx",
"filename": "math-defaults-example"
},
"defaults": {
"spacing": {
"before": {
"math": 10
},
"after": {
"math": 15
}
},
"styles": {
"math": {
"fontSize": 14,
"align": "center"
}
}
},
"sections": []
}

Basic Math Example

Basic Math JSON
{
"document": {
"type": "docx",
"filename": "math-element-example",
"title": "Math Element Example",
"author": "Json2doc"
},
"defaults": {
"fontFamily": "Arial",
"fontSize": 11,
"color": "#000000",
"spacing": {
"before": {
"math": 10
},
"after": {
"math": 15
}
},
"styles": {
"h1": { "fontSize": 24, "fontWeight": "bold", "color": "#0066cc" },
"math": { "fontSize": 14, "align": "center" }
}
},
"sections": [
{
"type": "flow",
"content": [
{ "type": "h1", "text": "Math Element Demo" },
{ "type": "text", "text": "Below is a LaTeX formula rendered as a native Word equation:" },
{
"type": "math",
"latex": "E = mc^2",
"align": "center",
"spacing": { "before": 10, "after": 20 }
},
{ "type": "text", "text": "You can add more math elements using the same 'math' type and a LaTeX string." }
]
}
]
}

Pythagoras Example

Pythagoras JSON
{
"document": {
"type": "docx",
"filename": "math-pythagoras-example"
},
"sections": [
{
"type": "flow",
"content": [
{
"type": "text",
"text": "Pythagorean theorem:"
},
{
"type": "math",
"latex": "a^2 + b^2 = c^2",
"align": "center",
"spacing": { "before": 10, "after": 20 }
}
]
}
]
}

Multi-line Math Example

Multi-line math is supported by splitting the LaTeX string on explicit \\ line breaks or real newline characters (\n). Each segment is rendered as its own math paragraph with shared alignment.

Multi-line Math JSON
{
"document": {
"type": "docx",
"filename": "math-multiline-example"
},
"sections": [
{
"type": "flow",
"content": [
{
"type": "text",
"text": "Basic vector calculus identities (separate lines):"
},
{
"type": "math",
"latex": "div E = rho / eps_0\n div B = 0\n curl E = - dB/dt\n curl B = mu_0 J + mu_0 eps_0 dE/dt",
"align": "center",
"spacing": { "before": 6, "after": 12 }
}
]
}
]
}