Written and maintained by CASRAI Editorial Board
Last updated
Jupyter Notebook LaTeX integration enables researchers, computational scientists, and data analysts to embed publication-quality mathematical notation within interactive computing documents. Through built-in support for MathJax in Markdown narrative cells, programmatic equation display in Python via IPython.display, and automated document conversion using nbconvert, the platform connects executable code directly with formal mathematical exposition. This eliminates manual transcription between analysis scripts and scholarly manuscripts while supporting computational reproducibility.
What it is used for in research
In quantitative disciplines such as statistics, machine learning, physics, econometrics, and computational biology, scientific communication requires exact mathematical expressions alongside exploratory code, tabular data, and diagnostic charts. Incorporating LaTeX directly into Jupyter environments serves three distinct research workflows:
Writing LaTeX in Jupyter Notebook Markdown cells
Researchers author narrative documentation, derivations, and methodology sections using standard MathJax LaTeX syntax directly in Markdown cells. Mathematical statements can be authored inline alongside explanatory text or formatted as centered display equations with numbering and multi-line alignments. By embedding mathematical context directly next to data cleaning, hypothesis testing, and simulation routines, investigators ensure analytical decisions remain transparent to collaborators and peer reviewers.
Programmatic equation generation in computational workflows
Beyond static documentation, computational research often requires reporting statistical estimates, regression coefficients, or symbolic mathematical formulas derived dynamically from runtime data. Using the IPython.display module in Python code cells, analysts programmatically generate LaTeX markup that reflects active dataset values—such as mean vectors, confidence bounds, or covariance matrices—without hardcoding numerical strings into narrative text.
Converting a Jupyter Notebook to LaTeX for publication
When preparing submissions for peer-reviewed journals, grant sponsors, or institutional repositories, researchers frequently export interactive notebooks into standalone LaTeX (.tex) manuscripts. The official nbconvert utility translates Markdown narrative blocks, syntax-highlighted code cells, structured Jupyter Notebook markdown tables, and embedded graphics into structured document classes, preserving complete provenance to strengthen computational reproducibility across research teams.
Install or access (official source only)
Jupyter Notebook and its associated LaTeX rendering and export tools are free, open-source software packages maintained under Project Jupyter. Access is available through official local package managers and distributed research computing infrastructures:
- Python Package Index (pip): Install the standard Jupyter Notebook environment, the IPython kernel, and the document conversion utility via the official Python packaging system:
pip install notebook nbconvert ipython - Conda / Mamba (conda-forge): For scientific computing environments requiring binary dependency management, install through Conda:
conda install -c conda-forge notebook nbconvert ipython pandoc - Centralized Multi-User Servers: High-performance computing clusters and research institutions provide authenticated, browser-based Jupyter environments via JupyterHub deployments, ensuring consistent software libraries across research teams.
- Hosted Cloud Notebooks: Hosted research environments run in modern browsers without local configuration, as evaluated in our comparison of Google Colab vs Jupyter Notebook.
Export Dependencies: While MathJax renders math in web browsers without additional software, converting notebooks to LaTeX source files requires Pandoc. Compiling directly to PDF via the command line further requires a functional TeX distribution (such as TeX Live, MacTeX, or MiKTeX) containing the xelatex or pdflatex engine.
Step-by-step task (numbered, with menu names or commands exactly as in the current docs)
The following step-by-step instructions demonstrate how to author inline and block mathematical notation, render dynamic equations from Python data, and export the finished notebook to a LaTeX document.
- Set Cell Type to Markdown for Equation Editing:
- In the Jupyter Notebook interface, select the target cell.
- Press
Mon your keyboard in command mode (or click the cell-type dropdown in the toolbar and select Markdown, or navigate to Cell > Cell Type > Markdown).
- Write Inline Mathematical Expressions:
- Enclose mathematical symbols, variables, or short formulas within single dollar signs (
$ ... $). - Example:
The sample estimator $\hat{\theta} = \frac{1}{n} \sum_{i=1}^{n} X_i$ is unbiased.
- Enclose mathematical symbols, variables, or short formulas within single dollar signs (
- Write Display and Multi-Line Aligned Equations:
- Enclose standalone, centered mathematical blocks within double dollar signs (
$$ ... $$):$$ f(x|\mu, \sigma^2) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left( -\frac{(x - \mu)^2}{2\sigma^2} \right) $$ - For multi-line derivations with alignment anchors, author an
alignenvironment directly inside the cell without outer dollar signs:\begin{align} \nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} \\ \nabla \cdot \mathbf{B} &= 0 \\ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \end{align} - Press
Shift + Enter(or click the Run button in the top toolbar) to execute the cell and render the mathematical typesetting.
- Enclose standalone, centered mathematical blocks within double dollar signs (
- Render Dynamic Equations Programmatically in Python Code Cells:
- Switch to a Python Code cell (press
Yin command mode). - Import
Mathanddisplayfrom theIPython.displaymodule. - Use Python raw f-strings (
rf'...') to inject computed variables directly into LaTeX syntax without backslash corruption:from IPython.display import display, Math import numpy as np sample_data = np.array([23.4, 25.1, 22.8, 24.6, 23.9]) mean_val = np.mean(sample_data) std_val = np.std(sample_data, ddof=1) display(Math(rf'\bar{{x}} = {mean_val:.2f}, \quad s = {std_val:.2f}')) - Run the cell with
Shift + Enterto display the formatted mathematical output below the code.
- Switch to a Python Code cell (press
- Export the Notebook to a LaTeX Manuscript via nbconvert:
- Save your active notebook in the web interface by selecting File > Save and Checkpoint (or File > Save Notebook).
- Open your local terminal or bash console and execute the
nbconvertcommand specifying the LaTeX format:jupyter nbconvert --to latex analysis_notebook.ipynb - To generate a formal report layout with chapter divisions and a table of contents, apply the built-in
reporttemplate:jupyter nbconvert --to latex --template report analysis_notebook.ipynb
- Compile Directly to PDF (Optional):
- If a complete TeX Live or MiKTeX distribution is installed on the system, compile directly to a publication-ready PDF:
jupyter nbconvert --to pdf analysis_notebook.ipynb
- If a complete TeX Live or MiKTeX distribution is installed on the system, compile directly to a publication-ready PDF:
Output and how to read it
Working with LaTeX in Jupyter generates distinct visual and file-based outputs across each authoring layer:
- Rendered Markdown Display: Upon running a Markdown cell, MathJax parses the TeX control sequences and renders sharp, scalable mathematical typography directly in the web browser. Right-clicking any rendered equation opens the interactive MathJax contextual menu, allowing users to view the underlying TeX source code (via Show Math As > TeX Commands) or configure rendering speed and math zoom magnification.
- IPython Display Output: In code cells, calling
display(Math(...))creates an output element tagged with the MIME typetext/latex. The notebook frontend renders this container as a centered display equation immediately beneath the code block, facilitating dynamic automated reporting. - Generated LaTeX Document (
.tex): The file generated byjupyter nbconvert --to latexis a complete, standalone LaTeX document containing:- A preamble importing standard American Mathematical Society packages (
amsmath,amssymb,amsfonts), document geometry, and hyperlinking configurations. - Markdown headers translated directly into corresponding LaTeX structural commands (
\section,\subsection,\subsubsection). - Code input cells formatted in syntax-highlighted
Verbatimenvironments. - Visual outputs and computational plots saved as individual graphics in an adjacent directory (
notebook_name_files/) and referenced via standard\includegraphics{}commands.
- A preamble importing standard American Mathematical Society packages (
Troubleshooting
When authoring LaTeX expressions or exporting notebooks in Jupyter, investigators may encounter the following common failure modes:
| Symptom / Error | Underlying Cause | Resolution |
|---|---|---|
| Raw dollar signs and LaTeX syntax displayed literally | The cell is set to “Code” or “Raw NBConvert” rather than “Markdown”, or the Markdown cell has not been executed. | Select the cell, press M to change the type to Markdown, and press Shift + Enter to trigger MathJax rendering. |
SyntaxError or missing backslashes in IPython.display.Math |
Standard Python strings treat backslashes as escape sequences (e.g., \\t as tab, \\n as newline, corrupting \\tau or \\nabla). |
Prefix string literals with r (raw string), such as Math(r'\\tau = \\frac{1}{2}'), so Python preserves all backslashes verbatim. |
MathJax rendering error or [Math Processing Error] |
Unbalanced curly braces {...}, unclosed dollar signs, or leading/trailing whitespace inside single dollar signs (e.g., $ x $). |
Inspect equation syntax for matching braces and remove whitespace immediately adjacent to dollar delimiters (write $x$ instead of $ x $). |
nbconvert failed: Pandoc wasn't found |
Pandoc is not installed on the system or its binary is not present in the system PATH environment variable. |
Install Pandoc using your package manager (e.g., conda install -c conda-forge pandoc or sudo apt-get install pandoc) and restart your Jupyter server. |
xelatex not found or PDF conversion aborts during --to pdf |
Direct PDF compilation requires a full TeX distribution (TeX Live or MiKTeX), which is absent or missing required packages. | Export to LaTeX source first using --to latex, verify the generated .tex file, and compile locally using your preferred LaTeX distribution or cloud compiler. |
Free alternatives (table)
Research laboratories and data scientists evaluating computational notebook platforms and reproducible mathematical authoring tools can assess the following free, open-source alternatives:
| Software / Framework | Syntax & Engine | Execution Model | Scholarly Publishing Fit | Open License |
|---|---|---|---|---|
| Quarto | Pandoc Markdown + Knitr / Jupyter | CLI and multi-language engine (Python, R, Julia) | Excellent; native multi-format output (PDF, HTML, Word, Typst, LaTeX) with automated citations | GPL-2.0 |
| R Markdown (knitr) | R Markdown + Pandoc | R / Posit session execution | High; standard for biostatistical reports, dynamic tables, and parameterized reproducible documents | GPL-3.0 |
| Typst | Modern markup + native Typst compiler | Fast local CLI compiler and web application | High; streamlined alternative to LaTeX with instant compilation and built-in math syntax | Apache-2.0 |
| Google Colab | Jupyter notebook interface | Hosted cloud runtime with GPU / TPU hardware | Moderate; collaborative cloud notebook execution with MathJax rendering and PDF export | Free tier cloud service |
FAQ
How do you write inline versus block LaTeX in Jupyter Notebook?
To write inline LaTeX, enclose your equation within single dollar signs ($ ... $) directly within a Markdown cell paragraph. To write block or display LaTeX, enclose your mathematical expression within double dollar signs ($$ ... $$) on dedicated lines, which centers the formula and enlarges summation and integral operators.
Why does LaTeX in Python code output show invalid escape sequence warnings?
Python interprets backslashes in standard string literals as escape sequences, such as \\t for tab or \\n for newline. When passing LaTeX control sequences like \\theta or \\frac to IPython.display.Math, always prefix the string literal with r (e.g., r'\\theta') to declare a raw string literal and prevent string escaping errors.
How do you export a Jupyter Notebook directly to a LaTeX file?
Open a terminal prompt and run the command jupyter nbconvert --to latex notebook_name.ipynb. This invokes the Project Jupyter conversion utility to translate Markdown narrative blocks, syntax-highlighted code cells, and output figures into a standalone .tex source manuscript suitable for publication compilation.
Does Jupyter Notebook support custom LaTeX packages in Markdown cells?
Markdown cells render mathematics through MathJax in the browser, which natively supports core TeX and AMS-LaTeX mathematical environments (such as amsmath and amssymb) but cannot execute arbitrary external .sty macro packages like TikZ. For advanced document formatting requiring specialized packages, export the notebook to a LaTeX file via nbconvert and compile it within a standard TeX distribution.
Sources (official docs)
- Project Jupyter, Jupyter Notebook Documentation: “Working With Markdown Cells — Mathematics”, Project Jupyter, https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Working%20With%20Markdown%20Cells.html (accessed 2026-11-10).
- Project Jupyter, nbconvert Documentation: “Converting Notebooks to other formats — LaTeX”, Project Jupyter, https://nbconvert.readthedocs.io/en/latest/usage.html (accessed 2026-11-10).
- IPython Documentation: “IPython.display: Public API for display tools in IPython”, The IPython Development Team, https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html (accessed 2026-11-10).
- SymPy Documentation: “SymPy Tutorial — Printing: IPython/Jupyter Notebook”, SymPy Development Team, https://docs.sympy.org/latest/tutorials/intro-tutorial/printing.html (accessed 2026-11-10).







