Crop equations with preview package

Is it possible to avoid left space from equations previewed with preview package?

\documentclass{minimal}
\usepackage{amsmath}
\usepackage[active,tightpage,displaymath]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}
$x=3+y^2$
\end{document}


The result is:

I would like a clipped (cropped?) equation. Is it possible?

Do you know a better solution to extract equations as images?

-

You can use the pdfcrop Perl script.

-
I didn't know about it, thanks. It crops every page, so I still need package preview to produce pages with one mathematical expression on them. After that pdftk can split the document in individual pages. –  Ignasi Mar 22 '11 at 14:23
the preview package will generate one equation per page, and pdftk can split them into one file per page. The command is pdftk latex_output.pdf burst. –  cheshirekow Sep 7 '13 at 20:35

The left space is caused by the display style. You could use in-text style ($...$ or $$...$$) instead and use \displaystyle in it to get the same result without the space. You need to wrap the equation manually in a preview environment:

\documentclass{minimal}
\usepackage{amsmath}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}
\begin{preview}
$\displaystyle x=3+y^2$
\end{preview}
\end{document}


Even shorter would be the use of the standalone class which uses preview internally. Note that the border option is only available since v0.4 2011/02/28. Before that you would need to set \PreviewBorder manually.

\documentclass[border=5pt]{standalone}
\begin{document}
$\displaystyle x=3+y^2$
\end{document}

-
your solution works perfect for one line equations but not for multiline expressions (split, gather, ...). At least I don't know how to do it. May be my minimal working example was too minimal. –  Ignasi Mar 22 '11 at 14:12
\documentclass{minimal}
\usepackage{amsmath}
\usepackage[active,tightpage,textmath]{preview}
\setlength\PreviewBorder{5pt}%

\begin{document}
$x=3+y^2$
\end{document}


Use textmath option instead of displaymath and use $...$ math environment.

-