Skip to main content
Block and inline formula text is LaTeX, typeset by MathJax into vector paths. The default math font is termes, which ships bundled in the package, so formulas work with no extra install.

Math fonts

Two values are exported for selecting a math font.
import { available_formula_fonts, default_formula_font } from "@nemu-ai/pdf";

available_formula_fonts; // ["termes", "newcm", "modern", "pagella", "stix2", "fira"]
default_formula_font;    // "termes"
Pick a math font and size through the formula role or a block style. The font style field is the math font name.
doc.set_style({ formula: { font: "termes", font_size: 13, color: "#111827" } });
The font field in a style is the math font name, distinct from font_family which selects a text font. Only the formula role and formula blocks read font.

Block formula

A formula block renders the LaTeX on its own line.
doc.page().content(
  { type: "formula", text: "\\int_0^\\infty e^{-x^2}\\,dx = \\frac{\\sqrt{\\pi}}{2}" },
);

Inline formula

Inside any block that takes text, use an inline formula node to typeset math within a run of prose.
{
  type: "paragraph",
  text: [
    "The identity ",
    { type: "formula", text: "e^{i\\pi} + 1 = 0" },
    " ties together five constants.",
  ],
}
When markdown is enabled, plain strings also honor $inline math$. Structured inline formula nodes are the reliable path for generated content.

Optional math fonts

The default termes font is bundled. Any other math font needs its own package installed, for example:
npm i @mathjax/mathjax-pagella-font
A missing math font logs a warning and falls back to termes. Install the matching package before selecting a non default font.

Installation

Add the package and install optional math font packages.