Skip to content

Equation

Use Equation for a math formula written in TeX: a variable or short expression inside a sentence, or a formula on its own line in an explanation, a report or an answer from a model. To render a whole Markdown message whose math is written as $…$ and $$…$$, turn on mathExtension in Markdown and it uses Equation for you. For code, use Code.

Before you start
  • Rendering needs KaTeX, which Pika neither bundles nor depends on: install katex, pass it to ConfigProvider (katex={katex}) or to the katex prop, and import its stylesheet once (import "katex/dist/katex.min.css"), which also loads its fonts. Without KaTeX, Equation shows the TeX source as code.
  • In Markdown, math is off until you add mathExtension from @pika-lab/react/markdown to extensions.

Equation renders with KaTeX’s renderToString, so it renders on the server and in the first paint, and it outputs MathML beside the visual HTML for screen readers. Commands that would need KaTeX’s trust (links, classes, images) stay off.

Setting up KaTeX

tsx
import "katex/dist/katex.min.css"; import katex from "katex"; import { ConfigProvider } from "@pika-lab/react"; export function App() { return <ConfigProvider katex={katex}>{/* … */}</ConfigProvider>; }

Demos

Basic

Inline in a line of text, at the text’s size and color.

Display

display puts the formula on its own centered line. A formula wider than its container scrolls sideways.

Errors and no KaTeX

A formula KaTeX cannot parse shows its source with an error border instead of breaking the page; its title is KaTeX’s message. Without KaTeX the source shows as code.

In Markdown

With mathExtension, $…$ is an inline equation and a $$ block a display one. \$ writes a dollar sign. Without the extension a $ is plain text, so prices and shell variables are never read as math.

Props

NameTypeDefaultDescriptionVersion
valuestringrequiredThe formula in TeX, without $ delimiters.Unreleased
displaybooleanfalseOn its own centered line instead of inline.Unreleased
katexEquationRendererundefinedKaTeX for this equation (import katex from "katex"). Defaults to ConfigProvider’s.Unreleased

Other props go to the root <span>. EquationRenderer is the part of KaTeX that Equation calls (renderToString); Pika only exports its type and never imports KaTeX at runtime.