Standalone producing cropped / truncated formulae

You can use the border=<len> class option to increase the width of the border around the cropped output:

enter image description here

\documentclass[border=1pt]{standalone}

\begin{document}

$2^5 = x_5 \times y^8$

\end{document}

As in your case, the border around the image is not present in the PDF, it's from my screen capture.

It is also possible to modify this border for left/right and top/bottom border using border={<l/r> <t/b>} or for each border specifically using border={<l> <b> <r> <t>}. These options are described in the standalone documentation (section 5.2 Class options).


Incorporating Stephan Lehmke's comment, this is what the bounding boxes around the objects in the equations look like:

enter image description here

\documentclass[border=1pt]{standalone}

\usepackage{xcolor}

\setlength{\fboxsep}{-\fboxrule}% Remove \fbox separation for tight bounding box
\newcommand{\bbox}[1]{%
  \color{red!50}\rlap{\fbox{$\phantom{#1}$}}%
  \color{black}#1%
}

\begin{document}

$\bbox{2^5} = \bbox{x_5} \times \bbox{y^8}$

\end{document}

By setting \fboxsep to -\fboxrule, the outer edge of the boxes represent the bounding boxes exactly. It is now noticeable that some elements protrude outside this, causing the problems when clipping.


Maybe this is not an answer to your question. In addition to be honest, I do not understand the philosophy of existence of standalone when pdfcrop exits. This is what I would do instead:

Create test.tex as follow:

  \documentclass{article}
  \thispagestyle{empty}
  \begin{document}
  $2^5 = x_5 * y^8$
  \end{document}

run pdflatex test.tex so that test.pdf is produced.

run pdfcrop test.pdf test-cropped.pdf


TeX itself doesn't know anything about the actual extent of the visible characters/glyphs. It only uses rough box metrics (height, depth, width, italic correction, etc.) stored in TFM files to align the text. Since the glyphs may exceed their corresponding box -- as you can see in this example, it's usually impossible to compute a perfect bounding box using TeX/LaTeX. That's why you have to adapt it manually or approximate it.

Nonetheless, some DVI drivers like dvisvgm offer an option to analyze the glyphs and derive a tight box for the resulting image.