✅ Introduction

The Scimax VS Code extension provides comprehensive LaTeX preview functionality for org-mode documents, enabling inline rendering of mathematical equations and formulas. This feature brings publication-quality mathematics directly into your editing workflow without requiring manual compilation or external viewers.

✅ What is LaTeX Preview?

LaTeX preview is a system that automatically compiles and renders LaTeX mathematical expressions as images when you hover over them in your org-mode documents. This provides instant visual feedback for complex equations, matrices, and mathematical notation.

✅ Key Features

  • Hover Preview: Rendered equations appear in tooltips when hovering over LaTeX code

  • Multiple Syntax Styles: Support for both dollar-sign and backslash delimiters

  • Dark Mode Aware: Automatically adjusts rendering for light and dark themes

  • Smart Caching: Previously rendered equations are cached for instant display

  • Document Settings: Use custom LaTeX packages and preambles

  • Equation Numbering: Automatic numbering for equation environments

  • Live PDF Preview: Full document preview with bidirectional sync

✅ Math Syntax

✅ Inline Math

Inline math appears within text paragraphs and uses the following delimiters:

✅ Dollar Sign Delimiter: $...$

The most common inline math syntax. Text between single dollar signs is rendered as mathematics.

Example:

The quadratic formula is \(x ` \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\) for equation \(ax^2 + bx + c ' 0\).

Renders as: The quadratic formula is x (-b ± √(b² - 4ac)) / 2a for equation ax² + bx + c 0.

✅ Backslash-Parenthesis Delimiter: \(...\)

Alternative inline math syntax, preferred in some LaTeX style guides.

Example:

Einstein's mass-energy equivalence is \(E = mc^2\), where \(c\) is the speed of light.

Renders as: Einstein's mass-energy equivalence is E mc², where c is the speed of light.

✅ Currency Detection

The preview system intelligently avoids treating dollar amounts as math. Currency patterns like $100 or $5.99 are ignored.

✅ Display Math

Display math appears on its own line, centered and larger than inline math.

✅ Double Dollar Signs: $$...$$

Creates unnumbered display equations.

Example:

\[\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}\]

Renders as a centered display equation: ∫₋∞^∞ e^(-x²) dx = √π

Backslash Brackets: \[...\]

Alternative display math syntax, equivalent to $$...$$.

Example:

\[
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
\]

Renders as a centered display equation: ∑(n1 to ∞) 1/n² π²/6

Math Environments

LaTeX environments provide advanced layout and automatic numbering.

Equation Environment

Single numbered equations with automatic numbering.

Example:

\begin{equation}
E = mc^2
\end{equation}

Renders as: E = mc² (1)

Equation* Environment (Unnumbered)

Same as `equation' but without numbering.

Example:

\begin{equation*}
F = ma
\end{equation*}

Align Environment

Multi-line equations with alignment points (`&').

Example:

\begin{align}
x + y &= 5 \\
2x - y &= 1
\end{align}

Renders as: x + y = 5 (2) 2x - y = 1 (3)

Each line receives its own equation number.

Align* Environment (Unnumbered)

Multi-line alignment without equation numbers.

Example:

\begin{align*}
\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\
\nabla \times \mathbf{H} &= \mathbf{J} + \frac{\partial \mathbf{D}}{\partial t}
\end{align*}

Other Numbered Environments

All these environments support automatic equation numbering:

  • `gather' - Multiple centered equations

  • `multline' - Single equation split across lines

  • `eqnarray' - Legacy alignment (prefer `align')

  • `alignat' - Alignment with explicit spacing

  • `flalign' - Full-width alignment

Add an asterisk (*) after the environment name for the unnumbered version: gather*, multline*, etc.

Matrix Environments

Specialized environments for matrices and arrays:

Example:

$$
A = \begin{pmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
$$

Available matrix environments:

  • `matrix' - Plain matrix (no delimiters)

  • `pmatrix' - Matrix with parentheses ( )

  • bmatrix - Matrix with brackets [ ]

  • `vmatrix' - Matrix with single bars | |

  • `Vmatrix' - Matrix with double bars || ||

  • `smallmatrix' - Compact inline matrix

Previewing Math Fragments

Hover Preview

To preview any LaTeX math expression:

  1. Position your cursor over the math expression

  2. Wait briefly or hover with your mouse

  3. A tooltip appears showing the rendered equation

The preview displays:

  • The rendered equation as an image (SVG or PNG)

  • Equation number (if applicable)

  • The original LaTeX source code

Inline Previews (C-c C-x C-l)

C-c C-x C-l (scimax.org.latexPreview) draws math fragments as rendered equations in the editor, as org-latex-preview does in Emacs. The fragment's source is hidden and the equation is drawn in its place, in the editor's font size and a text color that suits the theme.

KeyWhat it does
C-c C-x C-lOn a fragment: toggle its preview (the cursor steps to the end of it)
Elsewhere: toggle the previews in the region or current section
C-u C-c C-x C-lRemove the previews in the section (or region)
C-u C-u C-c C-x C-lPreview every fragment in the file
C-u C-u C-u C-c C-x C-lRemove every preview in the file

The section is the text from the heading above the cursor to the next heading of any level, or the text before the first heading. Toggling a region or section removes its previews if any are showing, and otherwise previews all its fragments, so pressing C-c C-x C-l repeatedly switches the equations on and off.

Clicking an equation shows its LaTeX source so you can edit it. When the cursor leaves the source, the equation is drawn again, re-rendered if you changed it. If the edit leaves no math there (say you deleted a delimiter), the preview is removed.

All the fragment types the hover preview knows are previewed: $...$, \(...\), $$...$$, \[...\] and math environments such as \begin{equation}. Numbered environments show their equation number.

Editing a previewed fragment:

  • Moving the cursor into a preview shows its LaTeX source again; moving out shows the equation. A preview over several lines (an environment) shows its source while the cursor is on any of its lines.

  • Edits made while the source is showing are re-rendered when the cursor leaves it. (Org instead removes the preview.) An edit that runs across the fragment's edge, such as replacing a selection that includes it, removes the preview.

  • A fragment that fails to render gets a ⚠ after it; hover it for the LaTeX error.

Previewing when a file opens: #+STARTUP: latexpreview previews every fragment when the file is opened, and #+STARTUP: nolatexpreview turns that off for a file when scimax.latexPreview.startupWithPreview is on.

Differences from Emacs: VS Code cannot make a line taller, so an equation has to fit the lines its source takes up. A one-line fragment that is taller than a line (a big fraction or sum in \[...\]) is shrunk to the line height; give such equations their own lines in an environment to see them full size. An environment is drawn across its lines, so a three-line equation has three lines of room.

Inline Preview Settings

SettingDefaultDescription
scimax.latexPreview.overlayScale1Size relative to the editor font, like :scale in org-format-latex-options
scimax.latexPreview.overlayForeground"auto"CSS color of the equations; auto picks a grey for the theme
scimax.latexPreview.startupWithPreviewfalsePreview all fragments when an org file opens (org-startup-with-latex-preview)

Changing the theme, the editor font size or these settings re-renders the previews.

Preview Caching

Rendered equations are cached in your VS Code global storage directory. The cache:

  • Speeds up repeated hover previews

  • Persists between VS Code sessions

  • Automatically cleans up entries older than 7 days

  • Stores separate versions for light and dark modes

Clearing the Cache

To clear all cached equation renders:

  1. Open Command Palette (C-S-P / s-S-P)

  2. Run: Scimax: Clear LaTeX Cache

To view cache statistics:

  1. Open Command Palette

  2. Run: Scimax: Show LaTeX Cache Statistics

This displays:

  • Number of cached equations

  • Total cache size on disk

LaTeX Fragment Settings

Document-Level Configuration

Add LaTeX configuration at the top of your org file using #+LATEX_HEADER: keywords.

Custom Packages

Load additional LaTeX packages for special symbols or functionality:

Example:

#+LATEX_HEADER: \usepackage{physics}
#+LATEX_HEADER: \usepackage{siunitx}
#+LATEX_HEADER: \usepackage{chemformula}

Now you can use commands from these packages:

  • physics: \grad, \div, \curl, \laplacian

  • siunitx: \SI{10}{\meter\per\second}

  • chemformula: \ch{H2O}, \ch{CO2}

Custom Commands

Define your own LaTeX macros:

Example:

#+LATEX_HEADER: \newcommand{\RR}{\mathbb{R}}
#+LATEX_HEADER: \newcommand{\dd}[1]{\,\mathrm{d}#1}
#+LATEX_HEADER: \DeclareMathOperator{\Tr}{Tr}

Use in equations:

$$\int_{\RR} f(x) \dd{x} = \Tr(A)$$

Custom Preamble

For extensive customization, add multiple headers:

Example:

#+LATEX_HEADER: \usepackage{amsmath,amssymb,amsfonts}
#+LATEX_HEADER: \usepackage{mathtools}
#+LATEX_HEADER: \usepackage{bm}
#+LATEX_HEADER: \usepackage{physics}
#+LATEX_HEADER: \DeclareMathOperator{\sgn}{sgn}
#+LATEX_HEADER: \newcommand{\ve}[1]{\bm{#1}}

VS Code Settings

Configure global LaTeX preview behavior in your settings.

Enable/Disable Preview

Setting: scimax.latexPreview.enabled Type: boolean Default: true

Completely enable or disable hover previews.

Example in settings.json:

{
  "scimax.latexPreview.enabled": true
}

Cache Control

Setting: scimax.latexPreview.cacheEnabled Type: boolean Default: true

Enable or disable caching of rendered equations. Disabling may slow down previews but saves disk space.

Example:

{
  "scimax.latexPreview.cacheEnabled": true
}

Dark Mode Awareness

Setting: scimax.latexPreview.darkModeAware Type: boolean Default: true

When enabled, equations render with white text on dark backgrounds when using dark themes, and black text for light themes.

Example:

{
  "scimax.latexPreview.darkModeAware": true
}

Common LaTeX Math Commands

Greek Letters

Lowercase

CommandSymbolCommandSymbol
αανν
ββξξ
γγππ
δδρρ
εεσσ
ζζττ
ηηυυ
θθφφ
ιιχχ
κκψψ
λλωω
μμ

Uppercase

CommandSymbolCommandSymbol
ΓΓΞΞ
ΔΔΠΠ
ΘΘΣΣ
ΛΛΦΦ
ΥΥΨΨ
ΩΩ

Math Operators

CommandOutputDescription
\frac{a}{b}a/bFraction
\sqrt{x}√xSquare root
\sqrt[n]{x}ⁿ√xnth root
x2x²Superscript (power)
xixᵢSubscript
∫∫Integral
∑∑Summation
∏∏Product
\limlimLimit
∂∂Partial derivative
∇∇Nabla (gradient)
∞∞Infinity

Relations and Operators

CommandSymbolCommandSymbol
≤≤≥≥
≠≠≈≈
≡≡∼∼
∝∝∈∈
∉∉⊂⊂
⊃⊃∪∪
∩∩\wedge∧
\vee∨¬¬
××÷÷
±±∓∓
⋅·∘∘

Arrows

CommandSymbolDescription
→→Right arrow
←←Left arrow
⇒⇒Implies
⇐⇐Implied by
⇔⇔If and only if
↑↑Up arrow
↓↓Down arrow
→→Alternative for →
↦↦Maps to

Special Symbols

CommandSymbolDescription
\mathbb{R}ℝReal numbers
\mathbb{N}ℕNatural numbers
\mathbb{Z}ℤIntegers
\mathbb{Q}ℚRational numbers
\mathbb{C}ℂComplex numbers
∅∅Empty set
∀∀For all
∃∃There exists
ℓℓScript lowercase L
ℏℏReduced Planck constant

Delimiters

CommandOutputDescription
\left( \right)( )Auto-sized parentheses
\left[ \right][ ]Auto-sized brackets
\left\{ \right\}{ }Auto-sized braces
\left\right\vert \vertAuto-sized vertical bars
\langle \rangle⟨ ⟩Angle brackets
\lfloor \rfloor⌊ ⌋Floor function
\lceil \rceil⌈ ⌉Ceiling function

Accents and Decorations

CommandExampleDescription
\hat{x}x̂Hat accent
\bar{x}x̄Bar (mean)
\tilde{x}x̃Tilde
\dot{x}ẋDot (derivative)
\ddot{x}ẍDouble dot
\vec{x}x⃗Vector arrow
\overline{AB}AB̄Overline
\underline{x}x̲Underline

Example Equations

Calculus

Derivative definition:

\[f'(x) = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}\]

Fundamental theorem of calculus:

\[\int_a^b f'(x) \,dx = f(b) - f(a)\]

Integration by parts:

\[\int u \,dv = uv - \int v \,du\]

Linear Algebra

Matrix multiplication:

$$

\begin{pmatrix} a & b \\ c & d \end{pmatrix}
\begin{pmatrix} x \\ y \end{pmatrix}

=

\begin{pmatrix} ax + by \\ cx + dy \end{pmatrix}

$$

Determinant:

\[\det(A) = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc\]

Eigenvalue equation:

\[A\mathbf{v} = \lambda\mathbf{v}\]

Physics

Schrödinger equation:

\[i\hbar \frac{\partial}{\partial t}\Psi(\mathbf{r},t) = \hat{H}\Psi(\mathbf{r},t)\]

Maxwell's equations:

\begin{align*} \nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_0} \\ \nabla \cdot \mathbf{B} &= 0 \\ \nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\ \nabla \times \mathbf{B} &= \mu_0\mathbf{J} + \mu_0\epsilon_0\frac{\partial \mathbf{E}}{\partial t} \end{align*}

Statistics

Normal distribution:

\[f(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)\]

Bayes' theorem:

\[P(A|B) = \frac{P(B|A)P(A)}{P(B)}\]

Computer Science

Big-O notation:

\[T(n) = O(n\log n)\]

Recurrence relation:

\[T(n) = 2T\left(\frac{n}{2}\right) + O(n)\]

Troubleshooting Rendering Issues

Common Problems and Solutions

Problem: "pdflatex not found" Error

Cause: LaTeX is not installed on your system.

Solution: Install a LaTeX distribution:

After installation, restart VS Code.

Problem: Equations Not Rendering on Hover

Possible causes and solutions:

  1. LaTeX preview disabled

    • Open Settings (`C-,')

    • Search for "scimax.latexPreview.enabled"

    • Ensure it is set to `true'

  2. Syntax error in equation

    • Hover shows error message

    • Check the LaTeX source code shown in the tooltip

    • Common errors: unmatched braces, unknown commands, missing packages

  3. Missing LaTeX package

    • Add required package via #+LATEX_HEADER:

    • Example: #+LATEX_HEADER: \usepackage{physics}

Problem: Slow Hover Response

Solutions:

  1. Enable caching (if disabled): #+BEGIN_SRC json { "scimax.latexPreview.cacheEnabled": true } #+END_SRC

  2. Clear corrupted cache:

    • Command Palette → "Scimax: Clear LaTeX Cache"

  3. Simplify complex equations:

    • Break very long equations into smaller parts

    • Use fewer custom packages

Problem: Rendering Wrong in Dark Mode

Solution:

Enable dark mode awareness:

{
  "scimax.latexPreview.darkModeAware": true
}

The equation will automatically render with appropriate colors for your theme.

Problem: Equation Numbers Wrong

Cause: Counter cache may be stale after editing.

Solution: The counter cache automatically invalidates when you edit the document. If numbers still appear incorrect, save the file and hover again.

Problem: dvisvgm Not Available

Error message: "dvisvgm not found. SVG output will not be available, using PNG fallback."

Impact: Equations render as PNG instead of SVG (slightly lower quality when zooming).

Solution: Install dvisvgm (usually included with full LaTeX distributions):

  • `sudo apt-get install texlive-binaries' (Linux)

  • Included with MacTeX and full TeX Live installations

Problem: Currency Detected as Math

Example: $100 is rendering as math instead of currency.

Solution: This should not happen as the preview system detects dollar amounts starting with numbers. If it does occur:

  • Use \$100 to escape the dollar sign

  • Or use proper currency notation outside of math mode

Integration with Export

HTML Export

When exporting to HTML, LaTeX math is rendered using MathJax:

  1. Inline math: $E mc^2$= → Renders with MathJax in browser

  2. Display math: $$...$$ → Centered equation in HTML

  3. Environments: \begin{align}...\end{align} → Properly formatted

The export includes MathJax CDN automatically, so equations render perfectly in web browsers.

LaTeX/PDF Export

When exporting to LaTeX or PDF:

  1. Math expressions are passed through unchanged

  2. #+LATEX_HEADER: settings are included in preamble

  3. Equation numbering preserved

  4. All environments work natively

Export and Preview Consistency

What you see in hover preview should match the exported output, but note:

  • HTML export: Uses MathJax (may look slightly different from LaTeX preview)

  • PDF export: Uses your LaTeX compiler (exact match with preview)

  • Font differences: Preview uses default LaTeX fonts; exports may use custom fonts

Commands and Keybindings

Preview Commands

CommandDescriptionKeybinding
Scimax: Toggle LaTeX PreviewInline preview at point or sectionC-c C-x C-l
Scimax: Preview All LaTeX Fragments in FileInline previews in the whole fileC-u C-u C-c C-x C-l
Scimax: Remove All LaTeX Previews in FileRemove the inline previewsC-u C-u C-u C-c C-x C-l
Scimax: Clear LaTeX CacheClear all cached equation rendersNone (use Command Palette)
Scimax: Show LaTeX Cache StatisticsDisplay cache size and entry countNone

Live PDF Preview Commands

CommandDescriptionKeybinding
Scimax: Open LaTeX Live PreviewOpen live PDF preview of documentC-c C-e l v
Scimax: Sync PDF to Cursor PositionJump to cursor location in PDFC-c C-e l s
Scimax: Rebuild PDFManually trigger PDF rebuildNone
Scimax: Show LaTeX Build OutputShow compiler output and errorsNone

Markup Commands

CommandDescriptionKeybinding
Scimax: LaTeX Math (Markup)Insert inline math $...$None
Scimax: LaTeX Display Math (Markup)Insert display math \[...\]None

Using Commands

  1. Via Command Palette:

    • Press Cmd/C-S-P

    • Type "Scimax: Clear LaTeX Cache" (or any command name)

    • Press Enter

  2. Via Keybinding:

    • For commands with keybindings, simply press the key combination

    • Example: C-c C-e l v opens live preview

Custom Keybindings

To add custom keybindings for commands without defaults:

  1. Open Keyboard Shortcuts (`C-k C-s')

  2. Search for the command (e.g., "Clear LaTeX Cache")

  3. Click the + icon to add a keybinding

  4. Press your desired key combination

Example keybindings.json:

[
  {
    "key": "ctrl+alt+l",
    "command": "scimax.clearLatexCache",
    "when": "editorLangId == 'org'"
  }
]

Advanced Topics

Multi-line Equations

Use \\ to break equations across multiple lines within display math:

\[ f(x) = a_0 + a_1 x + a_2 x^2 + \cdots \\ = \sum_{n=0}^{\infty} a_n x^n \]

Aligned Equations at Specific Points

Use & in align environments to specify alignment points:

\begin{align*} x &= r\cos\theta \\ y &= r\sin\theta \end{align*}

The `&' symbols align vertically.

Cases and Piecewise Functions

Use the cases environment:

$$ f(x) = \begin{cases} x^2 & \text{if } x ≥ 0

\end{cases} $$

Chemical Formulas

With the chemformula package:

The reaction is \ch{2 H2 + O2 -> 2 H2O}.

or with `mhchem'

The reaction is \ce{2 H2 + O2 -> 2 H2O}.

Physics Notation

With the physics package:

#+LATEX_HEADER: \usepackage{physics}

$$\dv{f}{x} = \lim_{h \to 0} \frac{f(x+h) - f(x)}{h}$$

$$\grad V = \left(\pdv{V}{x}, \pdv{V}{y}, \pdv{V}{z}\right)$$

SI Units

With the siunitx package:

#+LATEX_HEADER: \usepackage{siunitx}

The speed is \SI{3e8}{\meter\per\second}.

Best Practices

Document Organization

  1. Place all #+LATEX_HEADER: lines at the top of your org file, before the first heading

  2. Group related packages together with comments

  3. Define custom commands early for use throughout the document

Example:

#+TITLE: Research Notes
#+AUTHOR: Your Name
#+DATE: 2026-01-13

# Standard math packages
#+LATEX_HEADER: \usepackage{amsmath,amssymb,amsfonts}
#+LATEX_HEADER: \usepackage{mathtools}

# Physics
#+LATEX_HEADER: \usepackage{physics}

# Custom commands
#+LATEX_HEADER: \newcommand{\RR}{\mathbb{R}}
#+LATEX_HEADER: \newcommand{\dd}[1]{\,\mathrm{d}#1}

* First Section

Writing Maintainable Math

  1. Use meaningful variable names in comments: #+BEGIN_EXAMPLE \[v = v_0 + at\] # velocity equation #+END_EXAMPLE

  2. Break complex equations into multiple lines: #+BEGIN_EXAMPLE \begin{align*} E\text{total} &= E\text{kinetic} + E\text{potential}
    &= \frac{1}{2}mv^2 + mgh \end{align*} #+END_EXAMPLE

  3. Use consistent notation throughout your document

  4. Define reusable commands for frequently used symbols

Performance Tips

  1. Keep custom packages minimal - only load what you need

  2. Use caching (keep scimax.latexPreview.cacheEnabled true)

  3. Simplify very complex equations - LaTeX compilation can be slow for intricate formulas

  4. Avoid excessive hover - let the cache build up naturally

Accessibility

When sharing documents:

  1. Provide text descriptions for complex equations

  2. Export to HTML for web accessibility (MathJax is screen-reader friendly)

  3. Use semantic math rather than visual formatting

Quick Reference Card

Math Delimiters

TypeSyntaxDescription
Inline$...$Dollar signs
Inline\(...\)Backslash parens
Display$$...$$Double dollar
Display\[...\]Backslash brackets
Environment\begin{...}\end{...}LaTeX environment

Common Environments

EnvironmentNumberedDescription
equationYesSingle equation
equation*NoSingle equation
alignYesMulti-line aligned
align*NoMulti-line aligned
gatherYesMulti-line centered
gather*NoMulti-line centered
matrixN/APlain matrix
pmatrixN/AMatrix with ( )
bmatrixN/AMatrix with [ ]

Essential Commands

CategoryExamples
Greek\alpha \beta \gamma \delta \lambda \sigma \omega
Operators\frac \sqrt \sum \int \prod \lim
Relations\leq \geq \neq \approx \equiv \in
Arrows\to \rightarrow \Rightarrow \Leftrightarrow
Sets\mathbb{R} \mathbb{N} \mathbb{Z} \emptyset
Logic\forall \exists \wedge \vee \neg
Calculus\partial \nabla \infty
Delimiters\left( \right) \left[ \right] \left\{ \right\}

Keybindings

ActionKeybinding
Inline LaTeX previewC-c C-x C-l
Open live previewC-c C-e l v
Forward syncC-c C-e l s
Export dispatcherC-c C-e

Settings

SettingDefaultDescription
scimax.latexPreview.enabledtrueEnable hover previews
scimax.latexPreview.cacheEnabledtrueCache rendered equations
scimax.latexPreview.darkModeAwaretrueAdapt to theme

Additional Resources

Scimax VS Code Documentation

Navigation