5

I'm using this solution to generate images:

\ifdefined\formula
\else
\def\formula{E = m c^2}
\fi
\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\usepackage{varwidth}
\begin{document}
\begin{varwidth}{\linewidth}
\[ \formula \]
\end{varwidth}
\end{document}

Everything works perfect when I have a large multi-level formula, say something like this pV=\frac{m}{M}RT.

However, when the formula gets more flat, like p=mv, I get extra space at the top. Looks like the document has some kind of a min height … How do I remove it? So that the resulting img/pdf will be exactly the size of my formula + border?

9

The space comes from \baselineskip, inserted by the displayed equation.

The following example does not use \[...\], but simulates it via inline math and setting \displaystyle:

\ifdefined\formula
\else
\def\formula{p=mv}
\fi
\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\usepackage{varwidth}
\begin{document}
\begin{varwidth}{\linewidth}
$\displaystyle\formula$%
\end{varwidth}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.