> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nemu.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Formulas

> Typeset LaTeX block and inline formulas to vector paths with selectable math fonts

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.

```ts theme={null}
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.

```ts theme={null}
doc.set_style({ formula: { font: "termes", font_size: 13, color: "#111827" } });
```

<Note>
  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`.
</Note>

## Block formula

A `formula` block renders the LaTeX on its own line.

```ts theme={null}
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.

```ts theme={null}
{
  type: "paragraph",
  text: [
    "The identity ",
    { type: "formula", text: "e^{i\\pi} + 1 = 0" },
    " ties together five constants.",
  ],
}
```

<Tip>
  When markdown is enabled, plain strings also honor `$inline math$`. Structured inline
  formula nodes are the reliable path for generated content.
</Tip>

## Optional math fonts

The default `termes` font is bundled. Any other math font needs its own package installed,
for example:

```bash theme={null}
npm i @mathjax/mathjax-pagella-font
```

<Warning>
  A missing math font logs a warning and falls back to `termes`. Install the matching package
  before selecting a non default font.
</Warning>

<Card title="Installation" icon="download" href="/packages/pdf/installation" horizontal>
  Add the package and install optional math font packages.
</Card>
