Jupyter doesn’t run real LaTeX. It renders the maths part with MathJax, so equations work, but packages and text commands don’t. This guide shows what works and what to use instead.
What you’ll learn
- Write inline and display maths in Markdown cells
- Use multi-line environments, symbols and custom macros
- Show LaTeX from Python code
- Export the notebook to PDF
Set up Jupyter
Install JupyterLab or Notebook with pip (pip install notebook, then jupyter notebook), or through Anaconda. The Jupyter install page has all options.
The steps below also work in JupyterLab, VS Code notebooks and Google Colab text cells.
Write LaTeX in Markdown cells
Use this for equations in the explanatory text of a notebook.
- Add a cell and change its type from Code to Markdown in the toolbar drop-down, or press M in command mode.
- Type your text and maths.
- Run the cell with Shift + Enter to render it.
For inline maths, wrap the formula in single dollar signs. The famous equation is $E = mc^2$. renders as:

The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$. renders as:

For a display equation on its own line, use double dollar signs. $$\int_a^b f(x) \,dx = F(b) - F(a)$$ renders as:

$$\sum_{i=1}^{n} i = \frac{n(n + 1)}{2}$$ renders as:

Result: typeset equations inside your notebook text.
What works in a Markdown cell
| You write | Works? | Use instead |
|---|---|---|
$...$ and $$...$$ maths | Yes | |
\begin{aligned}...\end{aligned}, cases, matrix inside $$ | Yes, MathJax supports them | |
\text{...}, \mathbf{...}, \textbf{...} inside $...$ | Yes | |
\textbf{...}, \textit{...} outside maths | No, shown literally | Markdown **bold** and *italic* |
\small, \large, \huge outside maths | No, shown literally | Markdown headings |
\usepackage{...}, \documentclass | No | Not available |
MathJax only processes maths, so text-mode LaTeX outside dollar signs stays as plain text. Those commands do work in a real LaTeX document; see how to change the font size in LaTeX. The MathJax TeX macro list shows every supported command.
Inside maths, text commands do work. $$\textbf{This text is bold}$$ renders as:

and $$\textit{This text is italic}$$ as:
![]()
For text labels inside an equation, use \text{}. $$\text{Area} = \pi r^2$$ renders as:

Warning: Words typed in maths mode without
\text{}lose their spaces and turn italic. For example,$${\large{Important Note:}} \textit{...}$$renders the note as squashed italic letters:

Multi-line equations and custom commands
Use this for derivations and repeated expressions.
MathJax understands most amsmath environments. Inside $$, use aligned for aligned steps:
$$\begin{aligned}f(x) &= (x+1)^2 \\ &= x^2 + 2x + 1\end{aligned}$$Nesting align inside $$ can raise an “Erroneous nesting” error, so prefer aligned there. See multi-line equations with align for how the environments differ.
Common commands:
- Fractions:
\frac{a}{b} - Roots:
\sqrt{x}and\sqrt[3]{x} - Sums and integrals:
\sum_{i=1}^{n},\int_0^1 x^2 \,dx - Greek letters:
\alpha,\beta,\gamma - Arrows and operators:
\rightarrow,\leftarrow,\pm,\times,\div
$$\frac{1}{2}, \quad \sqrt{16}, \quad \sum_{i=1}^{5} i = 1 + 2 + 3 + 4 + 5, \quad \int_0^1 x^2 \,dx, \quad \alpha, \quad \beta, \quad \gamma$$
To define your own command, put \newcommand inside dollar signs so MathJax processes it. The definition then works in later cells:
$\newcommand{\force}{F = \frac{G m_1 m_2}{r^2}}$
$$\force$$
Display LaTeX from Python code
Use this to show calculated results as formatted maths in a code cell’s output.
IPython.display provides Math for a single formula and Latex for LaTeX with its own delimiters. Use raw strings (r"...") so backslashes aren’t treated as Python escapes:
import sympy as spfrom IPython.display import display, Math
x = sp.symbols('x')roots = sp.solve(x**2 - 3*x + 2, x)
display(Math(rf"x_1 = {sp.latex(roots[0])}, \quad x_2 = {sp.latex(roots[1])}"))Result: the output shows x₁ = 1, x₂ = 2 as a typeset equation.
sp.latex(expr)turns any SymPy expression into a LaTeX string.- Run
sp.init_printing()once and SymPy results display as typeset maths automatically. - The
%%latexcell magic renders a whole code cell as LaTeX, within the subset MathJax supports.
The IPython.display reference lists the other display classes.
Export a notebook with LaTeX to PDF
Use this when you need to share or print the notebook.
- Through LaTeX:
jupyter nbconvert --to pdf notebook.ipynb. This needs a TeX installation such as TeX Live or MiKTeX, plus Pandoc. - Through a browser:
jupyter nbconvert --to webpdf notebook.ipynb. No TeX needed; it requires thenbconvert[webpdf]extra, which installs a headless Chromium driver. - To Word: export the notebook to Markdown or LaTeX, then convert to Word with Pandoc.
Common errors
- Raw
$...$shown: the cell is still a Code cell, or you haven’t run it. - Literal
\textbf{...}shown: text-mode commands only work inside maths. Use Markdown formatting. - Dollar signs in prices break the text: escape them as
\$so MathJax doesn’t treat them as maths. SyntaxWarning: invalid escape sequence: a LaTeX string in Python isn’t raw. Prefix it withr.- Maths not rendered on GitHub or in other viewers: they use their own renderers and may not support every command. Check the notebook in Jupyter itself.
Browse the LaTeX guides for more LaTeX formatting help.