FormaTeX

\begin{article}

draft — not published

Typeset Any Math Equation in LaTeX — latex-math Skill

Describe a formula in plain English and get correct LaTeX math markup — inline, display, aligned equations, matrices, and proofs with amsmath environments.

·8 min read·
Typeset Any Math Equation in LaTeX — latex-math Skill

You know the drill. You need to typeset a multi-line proof, so you reach for align. You forget the ampersand placement, the output runs off the page, and you spend 20 minutes debugging a \end{align} that is missing a brace three lines up. Or you type $$ out of habit from your undergrad days and get a stern look from your collaborator who knows that $$ is plain TeX, not LaTeX, and breaks spacing in ways that are hard to diagnose.

Math typesetting in LaTeX is powerful — and unforgiving. The latex-math skill from the latex-skills pack removes the friction. Describe any formula, equation system, matrix, or proof in plain English or pseudo-notation, and get correct, production-ready LaTeX markup back instantly.


What Is latex-math?

latex-math is a Claude Code skill that specializes exclusively in mathematical typesetting. It knows every amsmath environment, understands when to use each one, and enforces the conventions that matter: no $$, no ** for multiplication, no // for fractions.

The skill handles:

  • Inline math with \(...\) — never $...$ for new documents
  • Display equations with \[...\] (unnumbered, standalone)
  • Numbered equations with the equation environment
  • Multi-line aligned proofs with align and align*
  • Piecewise functions with cases
  • Matricespmatrix, bmatrix, vmatrix, and their starred variants
  • Gathered equations with gather and gather*

It requires amsmath in your preamble. If you are not already loading it, the skill will remind you.

Want to understand what a LaTeX command does after the skill generates it? The latex-explain skill walks through any markup line by line.


How to Install

The latex-skills pack is a collection of Claude Code skills you copy into your project's .claude/skills/ directory.

bash
# Clone the pack
git clone https://github.com/formatex/latex-skills /tmp/latex-skills

# Copy the math skill into your project
cp /tmp/latex-skills/latex-math.md /your-project/.claude/skills/latex-math.md

Then invoke it inside Claude Code:

text
/latex-math Write the Cauchy-Schwarz inequality as a display equation

That is it. No configuration, no API keys beyond what Claude Code already uses. The skill is a plain Markdown file — you can read and edit it directly.

If your document has broken markup rather than a math question, the latex-fix skill is the right tool.


Environment Reference

Choosing the wrong environment is the most common math typesetting mistake. This table maps your intent to the correct LaTeX environment:

IntentEnvironmentNotes
Inline formula in a sentence\(...\)Never use $...$ in new LaTeX documents
Single display equation, no number\[...\]Shorthand for equation* without the environment overhead
Single display equation, numberedequationUse \label{} inside for cross-referencing
Multi-line with alignment, no numbersalign*Align on &; rows separated by \\
Multi-line with alignment, numberedalignEach row gets a number; suppress one row with \notag
Piecewise / case definitionscasesLeft brace auto-sized; right column is condition text
Matrix with round bracketspmatrix
Matrix with square bracketsbmatrix
Matrix with vertical bars (determinant)vmatrix
Several display equations, centered, no alignmentgather / gather*

If you need additional packages to handle a specific construct, the latex-packages skill will identify and explain the right ones.


Common Pitfalls

These are the mistakes latex-math is specifically trained to avoid — and to warn you about if it detects them in existing markup.

Never Use $$

$$ is plain TeX syntax. It works in many LaTeX engines by accident, but it breaks vertical spacing around display math, does not respect \displaystyle context properly, and will cause failures in certain document classes. Use \[...\] for unnumbered display math and the equation environment for numbered equations.

Never Use ** for Multiplication

LaTeX does not have a ** operator. For multiplication, use \cdot (centered dot), \times (cross product / dimensional notation), or simply juxtaposition. The skill will always pick the typographically correct option based on context.

Never Use // for Fractions

// is not valid LaTeX. Use \frac{numerator}{denominator}. For inline fractions where you want to avoid a tall fraction, use \tfrac{}{} (from amsmath). For display fractions in a restricted vertical space, \dfrac{}{} forces display size.

Braces for Multi-Character Subscripts and Superscripts

x_ij produces x with subscript i followed by j as a regular character. You want x_{ij}. The skill enforces braces on any subscript or superscript longer than one token.

Auto-Sizing Delimiters

Bare parentheses do not grow with their content. Always use \left( and \right) around tall expressions like fractions, matrices, or summations. The skill applies these automatically.

Text Inside Math Mode

Never type words directly in a math environment — they render in italic math font, which looks wrong. Use \text{...} (from amsmath) for words and phrases inside equations.


Practical Examples

1. Multi-Line Aligned Proof

Prompt:

text
/latex-math Show the expansion of (a+b)^2 step by step using align*

Output:

latex
\begin{align*}
(a + b)^{2} &= (a + b)(a + b) \\
            &= a^{2} + ab + ba + b^{2} \\
            &= a^{2} + 2ab + b^{2}
\end{align*}

The & anchors the alignment column at the equals sign. Each line breaks with \\. No equation numbers appear because of the star variant — if you need numbers for cross-referencing, switch to align.

2. Matrix Equation

Prompt:

text
/latex-math Write Ax = b where A is a 2x2 matrix with entries a11 a12 a21 a22, x is a column vector x1 x2, and b is b1 b2

Output:

latex
\[
  \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix}
  \begin{pmatrix} x_{1} \\ x_{2} \end{pmatrix}
  =
  \begin{pmatrix} b_{1} \\ b_{2} \end{pmatrix}
\]

Round brackets from pmatrix. Multi-character subscripts in braces. Auto-sized delimiters are not needed here because pmatrix handles its own sizing.

3. Piecewise Function with Cases

Prompt:

text
/latex-math Define the absolute value function as a piecewise using cases

Output:

latex
\[
  \lvert x \rvert =
  \begin{cases}
    x  & \text{if } x \geq 0 \\
    -x & \text{if } x < 0
  \end{cases}
\]

\lvert and \rvert instead of bare | — the vertical bar character has ambiguous spacing in math mode. \text{if } keeps the condition text in upright roman font with correct spacing.

For a deeper dive into math typesetting conventions and environment choices, see our guide on math typesetting in LaTeX.


Useful Packages

latex-math requires amsmath and will recommend additional packages when your formula needs them:

amssymb

Provides the full AMS symbol collection: \mathbb{R} for real numbers, \mathbb{Z} for integers, \leqslant for slanted less-than-or-equal, \nexists, and hundreds more. Load it alongside amsmath:

latex
\usepackage{amsmath}
\usepackage{amssymb}

mathtools

A superset of amsmath with fixes for known spacing bugs and extra environments: \coloneqq for definition-equals, \prescript for pre-subscripts and pre-superscripts, multlined for long lines inside align, and the \mathclap command for overlapping text. If your document uses amsmath heavily, mathtools is a worthwhile upgrade.

physics

Shorthand macros for physics notation: \dv{f}{x} for derivatives, \pdv{f}{x} for partials, \qty(...) for auto-sized delimiters, \bra{} and \ket{} for Dirac notation. Dramatically reduces boilerplate in physics documents.

siunitx

The standard package for numbers with units. \SI{9.81}{\metre\per\second\squared} renders correctly in both text and math mode, handles number formatting (decimal separators, significant figures, exponents), and keeps units upright. Never type units manually in a physics or engineering document.


The latex-skills pack covers the full document workflow. Once your equations are typeset correctly, you may need:


Compile Your LaTeX with FormatEx

Once your equations are correct, you need a LaTeX compiler. FormatEx provides a REST API for compiling LaTeX to PDF — no TeX Live installation required. Pass your .tex source, get a PDF back. Supports pdflatex, xelatex, lualatex, and latexmk.

See the getting started with FormatEx guide to make your first compilation request in under five minutes.

bash
curl -X POST https://api.formatex.io/api/v1/compile \
  -H "X-API-Key: YOUR_KEY" \
  -F "file=@document.tex" \
  --output document.pdf

Your amsmath equations, your matrices, your aligned proofs — compiled to pixel-perfect PDF without touching a local TeX installation.

\end{article}

Back to blog

\related{posts}

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy