3

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

I have added

\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*}?)

1

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.
\begin{equation}
F(b)-F(a)=\int_a^b f(x)\, \textrm{d}x
\end{equation}

Do you know it?
\begin{equation}
E\ne mc^2
\end{equation}

\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.
\begin{equation}
F(b)-F(a)=\int_a^b f(x)\, \textrm{d}x
\end{equation}

Do you know it?
\begin{equation}
E\ne mc^2
\end{equation}

\end{document}

enter image description here

enter image description here

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.
| improve this answer | |
  • Important notes: don't use convert to convert PDF to EPS. Instead, use pdftops. – kiss my armpit Sep 19 '13 at 18:09
  • Thanks. Is there a difference between using Image Magick and that gs command that I has posted? – David Doria Sep 19 '13 at 18:23
4

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.

Code (borrowed from PGFTricksanswer)

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

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

Output

enter image description here

| improve this answer | |
  • 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"? – David Doria Sep 19 '13 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. – Qrrbrbirlbel Sep 19 '13 at 19:35

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.