AddonsMath
Math
React-pdf supports rendering LaTeX mathematical expressions via the @react-pdf/math package. It converts LaTeX notation into vector graphics (SVG paths), so all glyphs are fully embedded in the PDF without external fonts or assets.
Installation
npm install @react-pdf/mathUsage
import { Document, Page, Text, View } from '@react-pdf/renderer';
import { Math } from '@react-pdf/math';
const MyDocument = () => (
<Document>
<Page size="A4" style={{ padding: 40 }}>
<Math>{"x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}"}</Math>
</Page>
</Document>
);Inline mode
By default, expressions render in display mode (centered, larger). Set inline to render compact equations suitable for embedding alongside text:
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<Text>The equation </Text>
<Math inline height={12}>{"E = mc^2"}</Math>
<Text> is famous.</Text>
</View>Valid props
| Prop name | Description | Type | Default |
|---|---|---|---|
| children | LaTeX math expression to render | String | undefined |
| inline | Inline mode (compact) vs display mode (centered, larger) | Boolean | false |
| width | Width of the rendered expression. Auto-calculated from aspect ratio if omitted | Number, String | undefined |
| height | Height of the rendered expression. Defaults to 22 if omitted | Number, String | 22 |
| color | Color of the math expression | String | "black" |
| debug | Enables debug mode showing a border around the expression | Boolean | false |
Supported LaTeX features
All standard LaTeX math features supported by MathJax are available, including:
- Fractions, roots, and arithmetic operators
- Greek and Hebrew letters
- Summations, products, and integrals
- Limits and derivatives
- Matrices and arrays
- Binomial coefficients
- Trigonometric functions
- Accents and decorations
- Piecewise functions and aligned equations