# DLL for convert latex equation to image

I need to convert a latex equation to image format. The better if i can find a DLL (i found a mention of such possibility here: https://stackoverflow.com/questions/10137105/delphi-component-or-library-to-display-mathematical-expressions/10140214 but can not find DLL) that take a latex equation string and return any image format. If it not possible what is a minimum set of files that can do such task, the TeX distributive is large enough, the conversion need only for equations.

• Are you looking for something like LaTeXIt ? – user30471 Nov 10 '16 at 23:07
• Only part that convert latex to image format, no other. The better if they will have a smaller size as possible. – Denis Sletkov Nov 10 '16 at 23:14

If you're willing to move your equation into a separate file, you can use the tools provided by your TeX distribution and need nothing else. I assume you're using TeXlive.

First, you need a file containing your equation with no page numbers, e.g.:

\documentclass{article}
\usepackage{amsmath}
\pagestyle{empty}

\begin{document}
\Huge
\begin{equation*}
a^2+b^2=c^2
\end{equation*}

\end{document}


Run pdflatex on this file (say, temp.tex).

Next, run pdfcrop on the generated temp.pdf getting temp-crop.pdf.

Last, run ghostscript on temp-crop.pdf to generate an image file. ghostscript is shipped with TeXlive and the binary is called rungs. A sample invocation can be like this:

rungs -q -dBATCH -dNOPAUSE -dTextAlphaBits=4 -dGraphicsAlphaBits=4
-sDEVICE=png256 -r600x600 -sOutputFile=temp.png temp-crop.pdf


Check this link for usage options and this one for devices/formats.

• The TeX distribution is very large. I need a simple and rather small solution, like a latex2png.com but in DLL and in-memory transform without using files. – Denis Sletkov Nov 11 '16 at 16:45

There are lighter TeX distributions, and you could probably strip those down further. Or MikTeX can install packages as required, meaning you could start with a minimum installation. These would still all use an executable with file I/O rather than calling a function in a DLL, because TeX works in a Unix-style way, where passing through files is the norm. It also was developed for systems with very little memory.

Defining the minimum set of files required isn't simple -- it depends what you need in your equations. Do you, for example, need blackboard bold numerals, or triangle symbols, and the ability to combine them. Both of these arbitrary examples would require the ability to add \usepackage to the preamble. You could dump all of the classes except standalone, many of the fonts, TikZ (probably) etc. and save a lot of disk space, but disk space is cheap.