Turn off equation numbers when using 'preview' package

I am trying to export all of the equations from my document.

\usepackage[active,displaymath,tightpage]{preview}


then compiled, and then from a command line run:

pdfcrop output.pdf
gs -sDEVICE=png16m -dTextAlphaBits=4 -r300 -dGraphicsAlphaBits=4 -dSAFER -q -dNOPAUSE -sOutputFile=Equation_%d.png output-crop.pdf -dBATCH


but the result I get is a very long line with the equation as well as the equation number. Is there a way to turn off equation numbers only when running with this package (i.e. without changing every {equation} to {equation*}?)

Redefine the equation environment to sandwich the math expression with \preview$\displaystyle and $\endpreview.

Method 1

\documentclass{article}
\usepackage{amsmath}
\usepackage[tightpage,active]{preview}
\PreviewBorder=3pt\relax

\renewenvironment{equation}
{\preview$\displaystyle} {$\endpreview}

\begin{document}

This is a theorem in calculus.
$$F(b)-F(a)=\int_a^b f(x)\, \textrm{d}x$$

Do you know it?
$$E\ne mc^2$$

\end{document}


Method 2

\documentclass[preview,border=3pt,varwidth,multi]{standalone}
\usepackage{amsmath}

\renewenvironment{equation}
{\preview$\displaystyle} {$\endpreview}

\begin{document}

This is a theorem in calculus.
$$F(b)-F(a)=\int_a^b f(x)\, \textrm{d}x$$

Do you know it?
$$E\ne mc^2$$

\end{document}


PDF to PNG conversion

To convert all PDF pages to PNG images, use ImageMagick's command as follows.

convert -compose copy -bordercolor magenta -border 1x1 -density <value> -alpha <option> input.pdf output%02d.png


Remark:

• value is an interger. Use bigger/smaller value to enlarge/shrink the image.
• option can be one of 3 options: on (enable transparency) , off (disable transparency, but it produces bad output) , remove (remove transparency with good output).
• %02d means the output filename will be followed by 2 digit numbers. For example: output01.png, output02.png, ... output69.png.
• Important notes: don't use convert to convert PDF to EPS. Instead, use pdftops. Sep 19, 2013 at 18:09
• Thanks. Is there a difference between using Image Magick and that gs command that I has posted? Sep 19, 2013 at 18:23

It suffices to do

\makeatletter
\let\@eqnswtrue\@eqnswfalse
\makeatother


The standalone package provides automatic conversion with the included png option or the fully configurable convert options.

\documentclass[varwidth]{standalone}    % or …
%\documentclass{article}                % … and …
\usepackage{amsmath}
\makeatletter
\let\@eqnswtrue\@eqnswfalse
\makeatother
\begin{document}
This is a theorem in calculus.
$$F(b)-F(a)=\int_a^b f(x)\, \textrm{d}x$$

Do you know it?
$$E\ne mc^2$$
\end{document}


Output

• From what I just read, \makeatletter is needed because @ is typically not allowed outside of a package, and @ is usually needed to override functionality inside of a package. Is it not necessary to know which package eqnswtrue/false come from? Googling for those didn't turn up any hits - what do they stand for? eqn = equation obviously, but what about "swtrue"? Sep 19, 2013 at 19:28
• @DavidDoria For \makeatletter see What do \makeatletter and \makeatother do? I assume EqNsW stands for Equation Number Switch. I can’t a documentation on that switch but it is used in the source of amsmath to switch tags on and off. Sep 19, 2013 at 19:35