[Tex/LaTex] How to make a standalone document with one equation

equationsstandalone

I was surprised to find that standalone package can not compile a document with an equation:

\documentclass{standalone}
\begin{document}
\begin{equation} % not working!
F(V, T) = E(V) + D(T)
\end{equation}
\end{document}

Is there an option or some workaround that allows this? The current error is something like:

! Missing $ inserted.

in line 4. (The idea of course is that the including (main) document can just \input the standalone without knowing if is going to be an equation or something else)

Best Answer

The 1.0 version of standalone changed the default option from preview to crop. The latter has several benefits for the use-case the author (me) deemed most common, but forces restricted horizontal mode, which doesn't allow for lists or paragraphs. This causes an error for certain environments which require these.

One easy way is to enable the preview mode manually by using it as a class option (\documentclass[preview]{standalone}). You can also reenable this option as default using the standalone.cfg file as described in the manual. However, with preview you get a full line-wide PDF with the equation number (1) at the right, which is not really what you want, is it?

\documentclass[preview]{standalone}
\begin{document}
\begin{equation} % works now!
F(V, T) = E(V) + D(T)
\end{equation}
\end{document}

Instead it is better to use inline math mode using $ .. $ or \( .. \), which will work with crop and doesn't produce a full line nor a number. You can add \displaystyle if you need it:

\documentclass{standalone}
\begin{document}
$\displaystyle
F(V, T) = E(V) + D(T)
$
\end{document}

There is also the varwidth option which will wrap the content in a varwidth environment (varwidth package), which is a variable width minipage. This also allows for paragraph breaks etc. and might be better for multi-line equations. varwidth takes an option length argument as text width.

Related Question