From Christoph's Personal Wiki
Jump to: navigation, search

tex2im is a simple tool that converts LaTeX formulas into high resolution pixmap graphics for inclusion in text processors or presentations. With tex2im you can write files containing only the formula in latex mathmode and transform them to many different graphic formats. latex2html can do something similar, but only on whole documents. This is the direct solution.


tex2im [options] inputfile

The content of input file should be plain latex mathmode code. Alternatively, a string containing the latex code can be specified.


show version
show help
-o file 
specifies output filename, default is inputfile with new extension
-f expr 
specifies output format; possible examples: gif, jpg, tif (all formates supported by "convert" should work; default: png
-r expr 
specifies desired resolution in dpi; possible examples: 100x100, 300x300, 200x150; default is 150x150
-b expr 
specifies the background colour; default: white
-t expr 
specifies the text colour; default: black
-x file 
file containing extra header lines of latex; default: ~/.tex2im_header
transparent background; default: off
no-formula mode (do not wrap in eqnarray* environment); default: off
change status of antialiasing; default is on for normal mode and off for transparent mode

For user specific default values, tex2im reads the file '.tex2imrc' in your home-directory. To change a value, put inside one or more of the following 5 commands:


In the file '~/.tex2im_header', additional latex header lines can be put, for example '\usepackage{amsmath}' or your own definitions.

The transparency implementation of ImageMagick has some problems in combination with antialiasing. Therefore, by default, antialiasing is off in transparent mode. If you switch it on via the -a flag you can expect pixels with something between background and text colour around the letters. This can look good if the background used in tex2im and the one of your document are identical, but also very bad if this is not the case. True antialising with transparency seems not to be possible. Just play around a bit to find the optimal settings.


Note: The following examples were taken directly from the official tex2im website with some slight modifications.

Example 1

Generate a file, called "formula1.tex", containing the following:

\psi_{tot}(x,-t_0,r) = \frac{1}{(2\pi)^2} \int\!\!\!\int
\tilde\Psi_{tot}\left(k_x,\frac{c}{2}\sqrt{k_x^2 + k_r^2},r=0\right)

Note that you should not put any \begin{document} or \begin{equation} in the file. Just plain latex mathmode code is required.

Then type on the command line:

% tex2im formula1.tex

The output will be the file "formula1.png" which has the following content: Tex2im example1.png

Example 2

Q = 1 + \sum_{i=1}^n\sum_{k=1}^n\sigma\left(\prod_{j=i}^kS_j\right)
\exp\left\lbrace\frac{-K}{RT}\left(\Delta Lk - \left[\sum_{j=i}^k0.36j\right]
- 0.8\right)^2\right\rbrace

yields Partition function.png

Example 3

You can also use colour. Generate a file "formula2.txt", containing the following:

[C_3] = {\color{red} \langle \vec k_{3L} \vec k_{3L}^{\:\adj} \rangle }=
\left[ \begin{array}{rrrr}
S_{11} & S_{21} & S_{31} \\
S_{12} & S_{22} & S_{32} \\
S_{13} & S_{23} & S_{33} \end{array} \right]

Then type on the command line:

% tex2im -b yellow -t blue formula2.tex

And you'll get this:

Tex2im example2.png

Example 4

Finally, you can use tex2im without input file by specifying the latex-code directly on the command line:

% tex2im "\sum_{i=0}^5 x_i^2"

generates a file "out.png" in the local directory (as long as you do not specify another output filename), containing:

Convert to SVG

Once one has the TeX code, one can produce an SVG file via the following, which assume the TeX file is called comm.tex:

latex comm.tex
dvips -E -y 2500 -o comm.eps comm.dvi
eps2eps -dNOCACHE comm.eps comm2.eps
pstoedit -f sk comm2.eps comm.sk
inkscape -z -f comm.sk -l comm.svg

Tex2im example3.png

Download and install

Note: To use tex2im, you need latex and convert (part of ImageMagick) installed.

To install tex2im, download the archive, uncompress it, and place the contained script "tex2im" in a directory in your path and make it executable.

For example:

tar xzf tex2im-1.8.tar.gz
mv tex2im/tex2im /path/of/your/choice
chmod 755 /path/of/your/choice/tex2im

See also

External links