how to get mathematical equations into image in latex? I want the code that convert all equations into image in the pdf file after compile the tex file.

# [Tex/LaTex] how to get mathematical equations into image in latex

equationsgraphicspdftex

Skip to content
# [Tex/LaTex] how to get mathematical equations into image in latex

equationsgraphicspdftex

how to get mathematical equations into image in latex? I want the code that convert all equations into image in the pdf file after compile the tex file.

## Best Answer

I suppose you could write a package that compiles equations in subjobs, like so (call this package

`imageeqn.sty`

):This package (which I wrote by modifying

`python.sty`

) defines an environment`imageeqn`

, which takes the equation inside of it, generates a tex file, compiles it to png, and then includes the resulting png using`\includegraphics`

. This can be used as follows (let's call this file`image.tex`

):Compile this with the command line:

The result is a pdf file that has the two equations embedded as rasterized images. I'm not sure why you would ever want to do this, but I enjoyed myself trying to figure out how to do this anyway :)

This implementation is pretty limited by the way: first of all, it won't compile if you put

`\end{imageeqn}`

on a new line. Second of all, it turns equations into text-style math (in dollar signs), so equation numbering, aligning, etc., are not supported.Solving the newline problemThe first problem can be fixed, at least on Linux, by preprocessing the subjobs with

`sed`

. This can be done by replacing:in the above code by:

Using preprocessing to make`\[`

,`\begin{equation}`

workMaking

`\[`

,`\]`

,`\begin{equation}`

,`\end{equation}`

work can be done by preprocessing the input with`sed`

:Perhaps

`lualatex`

may be of help here, but I don't know anything about that.