Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@react-pdf/math

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/math

Render LaTeX math expressions in react-pdf documents

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
208
-67.5%
Maintainers
1
Weekly downloads
 
Created
Source

@react-pdf/math

Render LaTeX math expressions in react-pdf documents.

Uses MathJax to convert LaTeX into SVG paths, then maps them to react-pdf's built-in SVG primitives. No fonts or external assets needed — all glyphs are rendered as vector paths directly in the PDF.

Installation

npm install @react-pdf/math
# or
yarn add @react-pdf/math

Peer dependencies:

npm install @react-pdf/renderer react

Usage

import React from 'react';
import { Document, Page } 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>
);

API

<Math>

PropTypeDefaultDescription
childrenstringLaTeX math expression to render
inlinebooleanfalseInline mode (compact) vs display mode (centered, larger)
widthnumber | stringWidth of the SVG element
heightnumber | stringHeight of the SVG element
colorstring"black"Color for the math expression
debugbooleanfalseAdds a visible border around the SVG element for debugging layout

Display vs Inline mode

Display mode (default) renders the expression as a block, centered with larger operators — ideal for standalone equations:

<Math>{"\\int_0^\\infty e^{-x^2} dx = \\sqrt{\\pi}"}</Math>

Inline mode (inline) renders compact expressions suitable for embedding within text:

<View style={{ flexDirection: 'row', alignItems: 'center' }}>
  <Text>The equation </Text>
  <Math inline>{"E = mc^2"}</Math>
  <Text> is famous.</Text>
</View>

Examples

Fractions and roots

<Math>{"\\frac{\\sqrt{3}}{2}"}</Math>

Summations and integrals

<Math>{"\\sum_{n=1}^{\\infty} \\frac{1}{n^2} = \\frac{\\pi^2}{6}"}</Math>
<Math>{"\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}"}</Math>

Matrices

<Math>{"\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}"}</Math>

Greek letters and operators

<Math>{"\\nabla \\times \\vec{E} = -\\frac{\\partial \\vec{B}}{\\partial t}"}</Math>

Limits

<Math>{"\\lim_{x \\to 0} \\frac{\\sin x}{x} = 1"}</Math>

How it works

  • LaTeX → SVG: MathJax converts the LaTeX expression into SVG markup with fontCache: 'none', ensuring all glyphs are inlined as <path> elements (no <use>/<defs> references).
  • SVG → react-pdf: A lightweight parser converts the SVG string into a tree, then recursively maps each SVG element (path, rect, g, etc.) to the corresponding react-pdf SVG component.

Supported LaTeX features

All standard LaTeX math features supported by MathJax are available, including:

  • Arithmetic operators, fractions, roots
  • Greek and Hebrew letters
  • Summations, products, integrals
  • Limits
  • Matrices and arrays
  • Binomial coefficients
  • Trigonometric functions
  • Accents and decorations
  • Spacing commands

License

MIT

FAQs

Package last updated on 06 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts