# Exporting equations from LaTeX to transparent png files

# Preview package

Refer to this so post: http://tex.stackexchange.com/questions/14974/exporting-all-equations-from-a-document-as-individual-svg-files

First, add the following to your LaTeX file. Include the other environments you want to include.

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

Burst the pdf file

```
pdftk yourfile.pdf burst
```

Then move the resulting files to a separate directory, and run the following to obtain:

```
for i in *.pdf do; convert -density 300 $i $i.png;
```

# Extracting without numbers

For extracting without equation numbers, check out @Damiens’s answer from the SO post:

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"
sed -i 's/begin{equation}/begin{equation*}/g' $file
sed -i 's/end{equation}/end{equation*}/g' $file
done
```

The individual equations can be extracted using:

```
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{equation*}
\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

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