Components
Math
NativeNative MathML from a small TeX-like parser, with spoken labels and numbered equations.
A few useful identities
From finding roots to describing motion, written with native math.
Solve a quadratic
For , isolate the two roots:
Connect five constants
Add a convergent series
Rotate a point
Describe the force
A constant mass converts acceleration into force.
Installation
npx nook-ui@latest add mathPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Math" component to this project, exactly as Nook ships it.
Native MathML from a small TeX-like parser, with spoken labels and numbered equations.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add math`. It writes `components/ui/math.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/math.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
import { Equation, Math } from "@/components/ui/math";
export default function MathDefault() {
return (
<article className="grid w-full max-w-xl gap-5 text-sm leading-relaxed">
<div>
<h3 className="text-base font-semibold">A few useful identities</h3>
<p className="mt-1 text-muted-foreground">
From finding roots to describing motion, written with native math.
</p>
</div>
<div>
<h4 className="font-medium">Solve a quadratic</h4>
<p className="mt-1 text-muted-foreground">
For <Math>{"ax^2 + bx + c = 0"}</Math>, isolate the two roots:
</p>
<Equation
number={1}
caption="The discriminant tells us how many real roots exist."
>{String.raw`x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}`}</Equation>
</div>
<div>
<h4 className="font-medium">Connect five constants</h4>
<Equation
number={2}
caption="Euler’s identity"
>{String.raw`e^{i\pi} + 1 = 0`}</Equation>
</div>
<div>
<h4 className="font-medium">Add a convergent series</h4>
<Equation
number={3}
>{String.raw`\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}`}</Equation>
</div>
<div>
<h4 className="font-medium">Rotate a point</h4>
<Equation
number={4}
caption="A rotation through an angle θ."
>{String.raw`R = \begin{pmatrix}\cos\theta & -\sin\theta \\ \sin\theta & \cos\theta\end{pmatrix}`}</Equation>
</div>
<div>
<h4 className="font-medium">Describe the force</h4>
<p className="mt-1 text-muted-foreground">
A constant mass converts acceleration into force.
</p>
<Equation
number={5}
caption="Force in newtons; mass in kilograms; acceleration in metres per second squared."
>{String.raw`\vec{F} = m\vec{a}`}</Equation>
</div>
</article>
);
}
```
API
- `Math`: Inline or display math; accepts a TeX-like string as children.
- `children` (`string`): Fractions, roots, scripts, Greek, operators, accents, matrices and aligned blocks.
- `display` (`boolean`): Use display layout.
- `aria-label` (`string`): Overrides automatically generated speech.
- `Equation`: A numbered figure with a caption.
- `children` (`string`): Expression passed to Math.
- `number` (`string | number`): Equation number.
- `caption` (`ReactNode`): Explanation under the equation.
- `parseMath / speakMath`: Pure parser and speech generator.
- `source / node` (`string / MathNode`): Parse an expression or describe its parse tree.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: MathML has an explicit spoken aria-label. Unsupported commands stay visible with a destructive wavy underline. Static rendering needs no JavaScript.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { Equation, Math } from "@/components/ui/math";
export default function MathDefault() {
return (
<article className="grid w-full max-w-xl gap-5 text-sm leading-relaxed">
<div>
<h3 className="text-base font-semibold">A few useful identities</h3>
<p className="mt-1 text-muted-foreground">
From finding roots to describing motion, written with native math.
</p>
</div>
<div>
<h4 className="font-medium">Solve a quadratic</h4>
<p className="mt-1 text-muted-foreground">
For <Math>{"ax^2 + bx + c = 0"}</Math>, isolate the two roots:
</p>
<Equation
number={1}
caption="The discriminant tells us how many real roots exist."
>{String.raw`x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}`}</Equation>
</div>
<div>
<h4 className="font-medium">Connect five constants</h4>
<Equation
number={2}
caption="Euler’s identity"
>{String.raw`e^{i\pi} + 1 = 0`}</Equation>
</div>
<div>
<h4 className="font-medium">Add a convergent series</h4>
<Equation
number={3}
>{String.raw`\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}`}</Equation>
</div>
<div>
<h4 className="font-medium">Rotate a point</h4>
<Equation
number={4}
caption="A rotation through an angle θ."
>{String.raw`R = \begin{pmatrix}\cos\theta & -\sin\theta \\ \sin\theta & \cos\theta\end{pmatrix}`}</Equation>
</div>
<div>
<h4 className="font-medium">Describe the force</h4>
<p className="mt-1 text-muted-foreground">
A constant mass converts acceleration into force.
</p>
<Equation
number={5}
caption="Force in newtons; mass in kilograms; acceleration in metres per second squared."
>{String.raw`\vec{F} = m\vec{a}`}</Equation>
</div>
</article>
);
}Props
Math
Inline or display math; accepts a TeX-like string as children.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | string | – | Fractions, roots, scripts, Greek, operators, accents, matrices and aligned blocks. |
| display | boolean | – | Use display layout. |
| aria-label | string | – | Overrides automatically generated speech. |
Equation
A numbered figure with a caption.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | string | – | Expression passed to Math. |
| number | string | number | – | Equation number. |
| caption | ReactNode | – | Explanation under the equation. |
parseMath / speakMath
Pure parser and speech generator.
| Prop | Type | Default | Description |
|---|---|---|---|
| source / node | string / MathNode | – | Parse an expression or describe its parse tree. |
Accessibility
MathML has an explicit spoken aria-label. Unsupported commands stay visible with a destructive wavy underline. Static rendering needs no JavaScript.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.