Exporting all equations from a document as individual svg files

I'm currently a presentation based on a paper originally written in Latex. Currently, I use Kile and Ubuntu for my work.

What I'm finding is that I need a large number of the equations from the original paper scattered around the presentations (and are using them to annotate diagrams etc). My current method of screenshots + gimp is rather slow :)

So, what I would like to do is compile the tex document and instead of creating a pdf/dvi, I would like it to spit out a number of files, which each file being one of the equations from the document, preferably in a vector format, but I will live with a PNG if I have to, so long as it's of high enough resolution.

I've had a look at a number of utilities.

The following web utility: http://www.codecogs.com/latex/eqneditor.php does more or less what I want for an individually typed equation. However, I've used a lot of mactros in equations that make it a little messy to use (for example)

\newcommand{\SkewSymmetric}[1]{\ensuremath{ \left[ #1 \right]_{\times}}}


I've had a look at pdf2svg, but it doesn't quite do what I want - I still need to crop out the equation of interest.

Is there anything else I should look at?

• Are you not writing your presentation in LaTeX? – Loop Space Apr 5 '11 at 8:30
• I'm embarrassed to admit it, but no :) – Damien Apr 6 '11 at 0:55

Check out the preview package. E.g., including

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{equation}


prints all equation environments and nothing else, each cropped, one to a page. It's equally effective with DVI and pdf output. Embedded macros in equation (or whatever) environments are handled transparently and properly.

The pdf can then be converted to SVG images with the following command:

pdf2svg filename.pdf output-page%03d.svg all

• the option displaymath should do it anyway. – user2478 Apr 5 '11 at 5:57
• Almost... The equation number is still embedded in each equation. Is there a way to automatically get rid of it? – Damien Apr 6 '11 at 0:49
• @Damien: sure, assuming your document is based on one of the standard LaTeX classes, define the equation number out of existence thus: \makeatletter\renewcommand\@eqnnum{}\makeatother. – Kilgore Apr 6 '11 at 11:59
• Not sure what I've done wrong. I've placed the suggested \makeatletter command before \begin{document} and after. It seems not to make a difference, even with a standard template. Any ideas? – Damien Apr 7 '11 at 12:36
• I have included some additional notes in a new answer below to get rid of the whitespace and embedded equation numbering. – Damien Aug 19 '11 at 7:45

To extend the answer from @Kilgore:

To get rid of the equation numbers (AND you have an excellent backup of the original file(s)!), yon can do the following:

#!/bin/bash

files=find . | grep -e '\.tex$' for file in$files ; do

echo "Stripping: $file" # Create a copy of the existing file cp$file file.strip_backup sed -i 's/begin{equation\*}/begin{align*}/g'file
sed -i 's/end{equation\*}/end{align*}/g'   file sed -i 's/begin{equation}/begin{align*}/g'file
sed -i 's/end{equation}/end{align*}/g'   file sed -i 's/begin{align}/begin{align*}/g'file
sed -i 's/end{align}/end{align*}/g'   file done  The individual equations can be extracted using: \usepackage[active,tightpage]{preview} \PreviewEnvironment{align*}  (Note the addition of the *) To remove the excessive whitespace, use the following utility: pdfcrop output.pdf  And, finally, you can split this into individual svg files mkdir output-equations pdf2svg filename.pdf output-equations/output-page%03d.svg all  If the svg images are still not properly cropped, Inkscape can fix that: inkscape -z --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose output-equations/*.svg  Make a Metapost file with one figure per equation, with each equation in an "unboxed box": beginfig(1) boxit.a(btex $$e^{i\pi}+1=0$$ etex); a.c = (0,0); drawunboxed(a); endfig(1); beginfig(2) boxit.a(btex $$F={G m_1 m_2 \over d^2}$$ etex); a.c = (0,0); drawunboxed(a); endfig(2);  Run mptosvg, which will generate one SVG file per figure, with the right bounding boxes. \documentclass{article} \usepackage[active,tightpage]{preview} \usepackage{amsmath} \pagestyle{empty} \begin{document} $$1-\strut\displaystyle\frac{2\,M}{r}, \quad \text{for}\, r>R,$$ foo xy=f(x) $bar foo $dy=g(x)$ bar \end{document}  Latex to SVG cmd $latex test.tex
\$dvisvgm.exe -n -p 1-5 -c 1.2,1.2 test.dvi

• Have you tested this with a document with multiple equation environments to see that it does what the OP calls for? (And please format code blocks properly so others can easily cut and paste.) – Ethan Bolker Jun 27 '16 at 13:47
• Welcome to TeX.SX! Thank you anyway for sharing your knowledge! To format code, you can indent lines by 4 spaces or enclose words in backticks `, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). – ebosi Jun 27 '16 at 14:29