l2p - create PNG images from LaTeX expressions


l2p [options...] -i '$latex_expression$'


l2p [options...] [expression_file]

expression_file contains an expression or expressions in (La)TeX format - one per line. If neither expression_file nor an -i option is given, the expression is read from standard input.


Convert expressions in LaTeX format into PNGs


l2p -i '$4x^2-7=\cos{2 \pi x}$' -o 'eqn4.png'

Produce a PNG image, named 'eqn4.png', of the equation described by the LaTeX expression '$4x^2 - 7 = \cos{2 \pi x}$'.

l2p -o big_equation.png big_hairy_equation

Produce a PNG image, called big_equation.png, from the LaTeX expression contained in the file big_hairy_equation (specifically, it contains '$x=2$'.) Note that this file is NOT a full LaTeX document - use the -F option for that.

l2p -d 250 -i '$\nabla \cdot \mathbf{D} = \rho$'

Produce a PNG image from the LaTeX code given with the -i argument (which happens to be one of Maxwell's equations), at 250 dots per inch. Since we did not specify an output file name with the -o option, the image will be 'eqn.png' (the default).

l2p -p amssymb -i '$\mho$' -o mho.png

Produce a PNG image of the Mho symbol (an upside-down capital omega), saving the image in the file 'mho.png'. We include the amssymb package, which defines that symbol.

l2p -B 20x30 -i '$\sum_{n=0}^{\infty}\frac{(-\phi^2)^n}{(2n)!}$' -o cosine.png

Produce an image of the indicated infinite summation, padded with a border that is 20 pixels on each side horizontally, and 30 pixels each side vertically. The color of this border region will be the same as the rest of the image background.


Many options have arguments that may contain characters, like '#' or spaces, that the shell considers special. Be sure to surround all such arguments with single or double quotes, so that the shell understands what is meant. (If unsure, it's always safe to use the quotes.)

-i ``$latex$''

Argument is an equation/expression in (La)TeX format. In most cases, you will want to enclose the argument in quotes to protect it from shell expansion.

-b ``rrggbb''

Background color. There are several ways to specify the color. See the section COLORS, below, for details.

-d dpi

Pixel density at which the equation is rendered, in dots per inch (default 300).

An image with a DPI of 600 will have twice as many pixels in each of the x and y directions than an image with a DPI of 300. The effect is different in the normal context of printing, where a higher DPI will leave the text with the same physical size, but with a finer resolution. This is because the physical size of a pixel is not really variable; so to have double the resolution, a symbol in an image must be double the size.

-f ``rrggbb''

Foreground color. There are several ways to specify the color. See the section COLORS, below, for details.


Show a help summary.

-o output.png

Name of output file. Default is 'eqn.png'.

-p packagename[,packagename2[,...]]]

Use additional LaTeX/TeX packages. You can specify several, separated by commas.

-B ``WIDTHxHEIGHT [color]''

or: -B ``SIZE [color]''

Pad the resulting image with a border of the indicated size, in pixels.

You can optionally specify a color for the border region. By default, the border will be the same color as the rest of the background. (See COLORS below for the format.)


Suppress automatic removal (cleanup) of temporary files. This will be useful if something goes wrong, or if you want to use the intermediate DVI or Postscript renditions. l2p will tell you which directory contains these files.


Supplied expression is a full LaTeX document, rather than just an expression fragment. Negates the -f, -b, -p, -B and -T options.

Note: l2p currently only converts full LaTeX documents that are relatively simple: only one page in length, and with no external dependencies (such as included graphics). If you need to convert a more complex document, you can generate a DVI file with latex like normal, then convert the DVI into a series of PNG images using convert from the ImageMagick distribution. See convert(1), or for more information.


Create an image with a transparent background.


Show version information.


Some options, such as -b and -f, take an argument specifying a color in RGB format. l2p will decipher most representations, such as:

A hexidecimal triplet. For example, '-f ``FF0000'' -b ``#ffffff''' gives a red foreground on a white background. Case is not important, and the ``#'' is optional.

Three decimal whole numbers, in the range of 0 to 255. These must be separated by spaces or punctuation (comma, semicolon or colon). For example, '-b ``0 127 255'' -f ``0,0,0''' is black on a nice bluish background.

Three fractions between 0 and 1, inclusive. At least one of the three numbers must contain a decimal point (to distinguish this format from the others), and they are separated by space or punctuation. For example, ``0.87 .78 .41'' is the same as the hex triplet ``DEC769'', and ``0, 1.0, 0'' is the color green. (Remember that decimal point. ``0, 1, 0'' will give you a nearly black color.)

Note that you may need to put single or double quotes around the color string, to ensure the shell interprets it correctly.


Error handling is imperfect. Among other things, If a needed LaTeX package is not included, l2p will silently produce a broken image.

On certain platforms, images produced with the -T option (transparent background) may leave pixels at the edges of symbols a mixture of the text color and some background color. This may not look good if the resulting image is put on a differently colored background. A workaround is to give a background color hint with the -b option; the edge pixels will then be a mixture of specified foreground and background colors.


Thanks to Jesse Merriman ( for providing a patch that improved transparent background support. Integrated in version 1.1.


This software is in the public domain.


Aaron Maxwell ( Comments, feature requests, and patches are welcome.