Type Equations in LaTeX standalone Document

Nov. 13, 2025 in Buffalo, United States • Updated Nov. 15, 2025

In LaTeX standalone Document, if we want to directly type equations:

1
2
3
4
5
6
7
8
9
10
11
12
13
\documentclass{standalone}
\usepackage{amsmath}

\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}

\begin{document}
	
\begin{equation}
	c = a+b
\end{equation}

\end{document}

we’ll get errors:

1
2
3
doc.tex: error: 9: Missing $ inserted. \begin{equation}
doc.tex: error: 11: You can't use `\eqno' in math mode. \end{equation}
doc.tex: error: 11: Missing $ inserted. \end{equation}

To solve this problem, we can use the preview option of standalone class1:

1
2
3
4
5
6
7
8
9
10
11
12
13
\documentclass[preview]{standalone}
\usepackage{amsmath}

\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}

\begin{document}
	
\begin{equation*}
	c = a+b
\end{equation*}
	
\end{document}

png-1

The preview will put the content into a preview environment2:

image-20251112193827386

where the preview package is to extract a certain environment as graphic3:

image-20251112194142520

Right now, the equation works, but as can been it seems that preview option will influence other appearance. For example, in above case, the colored page background can’t be displayed normally. And another problems is, blank spacing will fill between the equation and left and right sides.


So, I think another method is more elegant, that is put the equation in a tikzpicture environment as a node content4. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
\documentclass[tikz]{standalone}
\usepackage{amsmath}

\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}

\begin{document}
	
\begin{tikzpicture}
	\node {$c = a+b$};
\end{tikzpicture}

\end{document}

png-1

And of course, like we insert equations in TikZ pictures, at this time we can also use other complicated equation environments:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\documentclass[tikz]{standalone}
\usepackage{amsmath}

\usepackage[x11names]{xcolor}
\pagecolor{AntiqueWhite1}

\begin{document}
	
\begin{tikzpicture}
	\node {$
	\begin{aligned}
		c &= a+b\\
		c &= a+b\\
		c &= a+b\\
	\end{aligned}
	$};
\end{tikzpicture}

\end{document}

png-1


References