This manual documents dvipng, a program to translate a DVI (DeVice Independent) file into PNG (Portable Network Graphics).
This file documents dvipng version 1.6
Corrections or perhaps rewrites of sections are very welcome.
Jan-Åke Larsson
This program makes PNG and/or GIF graphics from DVI files as obtained from TeX and its relatives.
If GIF support is enabled, GIF output is chosen by using the `dvigif' binary or with the `--gif' option.
It is intended to produce anti-aliased screen-resolution images as fast as is possible. The target audience is people who need to generate and regenerate many images again and again. The primary target is the preview-latex (X)Emacs package, a package to preview formulas from within (X)Emacs. Yes, you get to see your formulas in the (X)Emacs buffer, see http://preview-latex.sf.net.
Another example is WeBWorK, an internet-based method for delivering homework problems to students over the internet, giving students instant feedback as to whether or not their answers are correct, see http://webwork.math.rochester.edu.
Other applications may also benefit, like web applications as latex2html and WYSIWYG editors like LyX.
The benefits of `dvipng'/`dvigif' include
Installing dvipng should be simple: merely ./configure
,
make
, and make install
.
The drawing library `libgd' is necessary, and is downloadable at http://www.boutell.com/gd, and there are binary packages for most operating systems from their respective distributors. In any case, the latest version of the library installs using `autoconf' so it should not be difficult for you to install it from source, and then proceed with installing dvipng.
Kpathsea is most likely included in your LaTeX installation, but it may happen that ./configure does not find it; see below. If you do not have it, download it from http://www.ctan.org and compile it. I have no experience with this, so I cannot help much here.
While not strictly necessary, you may want to have FreeType 2 or T1lib available. Their presence will enable direct support for PostScript fonts in dvipng, rather than using `gsftopk' for rendering the fonts. If you have PostScript versons of Computer Modern installed, there will be no need to generate bitmapped variants on disk of these. Then, you can render images at different (and unusual) resolutions without cluttering the disk with lots of bitmapped fonts. If both FreeType 2 and T1lib are present, FreeType will be internally preferred by dvipng, but T1lib can be chosen at runtime.
To be able to compress and write PNG files to disk, dvipng (or really libgd) uses libpng which in turn uses libz. These should be available on any modern system, if not, download them and install them.
texinfo
package
This is needed for building the documentation.
The first step is to configure the source code, telling it where various files will be. To do so, run
./configure options
(Note: if you have fetched dvipng from CVS rather than a regular
release, you will have to first generate ./configure by running
autoconf
2.53 or later in the preview directory.)
On many machines, you will not need to specify any options, but if
configure
cannot determine something on its own, you'll need to
help it out. For a list of the options type
./configure --help
On some machines, the libraries will be installed in directories that are not in the linker's search path. This will generate an error when running ./configure, indicating that it cannot find libgd or libkpathsea (most likely). You then need to specify the path to the respective library's object files. They are typically called e.g., libgd.a or libgd.so. If they are located in e.g., /sw/local/lib, do
./configure LDFLAGS=-L/sw/local/lib
If the library is available as a shared object file (.so), the runtime linker may also need to be told where to find the library, then use
./configure LDFLAGS='-L/sw/local/lib -R/sw/local/lib'
When either of these is necessary, it is likely that the C header files are also installed in directories that are not in the C preprocessor's search path. This will also generate an error when running ./configure, indicating that it cannot find e.g., gd.h or kpathsea.h (most likely). You then need to specify the path to the respective library's C header files. If they are located in e.g., /sw/local/include, do
./configure CPPFLAGS=-I/sw/local/include
On my SUN Solaris workstation, I had to combine this into
./configure CPPFLAGS='-I/sw/local/include -I/sw/tex/teTeX/1.0/include'\ LDFLAGS='-L/sw/local/lib -R/sw/local/lib -L/sw/tex/teTeX/1.0/lib/'
where the backslash denotes a continuation of the line.
Once configure has been run, simply enter
make
at the prompt to compile the C code, and build the documentation files. To install the files into the locations chosen earlier, type
make install
You may need special privileges to install, e.g., if you are installing into system directories.
In some cases, a dvipng binary installed outside the texmf tree will not be able to find virtual fonts, or the PostScript font maps (normally used by dvips). This may be because only $SELFAUTOLOC, $SELFAUTODIR, and $SELFAUTOPARENT are used in the texmf tree configuration file `texmf.cnf'. If so, give the switch `--enable-selfauto-set' to `./configure'. This will make dvipng adjust these three internally so that kpathsea thinks that dvipng is installed in the texmf tree.
Often people without system administration privileges want to install software for their private use. In that case you need to specify more options to the configure script, usually this is done by using the `--prefix' option to the configure script, and let it point to the personal home directory. In that way, resulting binaries will be installed under the bin subdirectory of your home directory, manual pages under man and so on. That way, it is reasonably easy to maintain a bunch of additional packages, since the prefix argument is supported by most configure scripts.
You'll have to add something like /home/myself/bin to your
PATH
shell variable, if it isn't there already, and similarly set
the INFOPATH
variable to be able to access the documentation.
To use dvipng at its simplest, simply type
dvipng foo
where foo.dvi is the output of TeX that you want to convert to PNG format. If there are four pages in foo.dvi, those pages will be output as foo1.png, foo2.png, foo3.png, and foo4.png, respectively.
If you have enabled the PostScript font support (via FreeType or T1lib), fonts will be rendered as they are needed. Otherwise, if you use fonts that have not been used on your system before, they may be automatically generated; this process can take a few minutes, so progress reports appear by default. The next time the same font is used, it will have been saved on disk, so rendering will go much faster. (If dvipng tries to endlessly generate the same fonts over and over again, something is wrong. See Unable to generate fonts.)
Many options are available (see the next section). For a brief summary of available options, just type
dvipng --help
dvipng has a plethora of command line options. Reading through this section will give a good idea of the capabilities of the driver.
Here is a handy summary of the options; it is printed out when you run dvipng with no arguments or with the standard `--help' option.
This is dvipng 1.6 Copyright 2002-2005 Jan-Ake Larsson Usage: dvipng [OPTION]... FILENAME[.dvi] Options are chosen to be similar to dvips' options where possible: -d # Debug (# is the debug bitmap, 1 if not given) -D # Output resolution -l # Last page to be output --mode s MetaFont mode (default 'cx') -M* Don't make PK fonts -o f Output file, '%d' is pagenumber -O c Image offset -p # First page to be output -pp #,#.. Page list to be output -q* Quiet operation -r* Reverse order of pages -T c Image size (also accepts '-T bbox' and '-T tight') -v* Verbose operation -x # Override dvi magnification - Interactive query of options These do not correspond to dvips options: -bd # Transparent border width in dots -bd s Transparent border fallback color (TeX-style color) --bdpi # Set the base (Metafont) resolution -bg s Background color (TeX-style color or 'Transparent') --depth* Output the image depth on stdout --dvinum* Use TeX page numbers in output filenames -fg s Foreground color (TeX-style color) --follow* Follow mode --gamma # Control color interpolation --gif Output GIF images (dvigif default) --height* Output the image height on stdout --noghostscript* Don't use ghostscript for PostScript specials --nogssafer* Don't use -dSAFER in ghostscript calls --picky When a warning occurs, don't output image --png Output PNG images (dvipng default) --strict When a warning occurs, exit --t1lib* T1lib font rendering (default on) --truecolor* Truecolor output -Q # Quality (T1lib and PK subsampling) -z # PNG compression level # = number f = file s = string * = suffix, '0' to turn off c = comma-separated dimension pair (e.g., 3.2in,-32.1cm)
Many of the parameterless options listed here can be turned off by suffixing the option with a zero (`0'); for instance, to turn off page reversal, use `-r0'. Such options are marked with a trailing `*'.
One may want to adjust this to fit a certain text font size (e.g., on a web page), and for a text font height of font_px pixels (in Mozilla) the correct formula is
dpi = font_px * 72.27 / 10 [px * TeXpt/in / TeXpt]
The last division by ten is due to the standard font height 10pt in your document, if you use 12pt, divide by 12. Unfortunately, some proprietary browsers have font height in pt (points), not pixels. You have to rescale that to pixels, using the screen resolution (default is usually 96 dpi) which means the formula is
font_px = font_pt * 96 / 72 [pt * px/in / (pt/in)]
On some high-res screens, the value is instead 120 dpi. Good luck!
<IMG SRC="filename.png" STYLE="vertical-align: -depthpx">
The depth is a negative offset in this case, so the minus sign is
necessary, and the unit is pixels (px).
\frontmatter
, one in \mainmatter
, and one
in \backmatter
). In case of several pages matching, `-pp
firstpage-lastpage' will render all pages that
matches the specified range, while `-p firstpage -l
lastpage' will render the pages from the first occurrence
of firstpage to the first occurrence of lastpage.
This is the (undocumented) behaviour of dvips. In dvipng you can give
both kinds of options, in which case you get all pages that matches the
range in `-pp' between the pages from `-p' to `-l'. Also
multiple `-pp' options accumulate, unlike `-p' and `-l'.
The `-' separator can also be `:'. Note that `-pp -1'
will be interpreted as "all pages up to and including 1", if you want a
page numbered -1 (only the table of contents, say) put `-pp -1--1',
or more readable, `-pp -1:-1'.
Currently, valid values range from 0 - 9, corresponding directly to the zlib compression levels 0 - 9 (0 - no compression, 9 - "maximal" compression). Note that tests have shown that zlib compression levels 3-6 usually perform as well as level 9 for PNG images, and do considerably fewer calculations. In the future, these values may not correspond directly to the zlib compression levels.
You've gone through all the trouble of installing dvipng, carefully read all the instructions in this manual, and still can't get something to work. The following sections provide some helpful hints if you find yourself in such a situation.
Bug reports should be sent to dvipng@nongnu.org.
Questions, suggestions for new features, pleas for help, and/or praise should go to dvipng@nongnu.org. For more information on this mailing list, send a message with just the word `help' as subject or body to dvipng-request@nongnu.org or look at http://lists.nongnu.org/mailman/listinfo/dvipng.
Offers to support further development will be appreciated. For developer access, ask on dvipng@nongnu.org.
For details on the TeX path-searching library, and mktexpk
problems, see Common problems.
The `-d' flag to dvipng helps in tracking down certain errors. The
parameter to this flag is an integer that tells what errors are
currently being tracked. To track a certain class of debug messages,
simply provide the appropriate number given below; if you wish to track
multiple classes, sum the numbers of the classes you wish to track. To
track all classes, you can use -1
.
Some of these debugging options are actually provided by Kpathsea (see Debugging).
The classes are:
stat
calls
The most common problem with including graphics is an incorrect bounding box. Complain to whoever wrote the software that generated the file if the bounding box is indeed incorrect.
An additional problem is that the image in dvipng is always clipped to the bounding box. This is because the image is rendered by GhostScript by an internal call and then copied to the dvipng image. At present no workaround is known, but there may be one for a future GhostScript. We'll see.
To support color, dvipng recognizes a certain set of specials. These specials start with the keyword `color' or the keyword `background', followed by a color specification.
The color specification supported by dvipng is by-value or by-name. The by-value spec starts with the name of a color model (one of `rgb', `hsb', `cmy', `cmyk', or `gray') followed by the appropriate number of parameters. Thus, the color specification `rgb 0.3 0.4 0.5' would correspond to the color that is `0.3 0.4 0.5' in its red, blue and green values. The color used internally in dvipng is `RGB' (discretized to 256 levels), for details on the formulas used in conversion, see the `xcolor' documentation.
By-name color specifications are single (case-dependent) words and are compared with color names defined in `dvipsnam.def' (from the `graphics' bundle), `svgnam.def' and `xcolor.sty' (from the `xcolor' bundle).
On the command-line, the name `Transparent' can also be used in as an argument to `--bg' to choose transparent background. See Option details.
We will describe `background' first, since it is the simplest. The `background' keyword must be followed by a color specification. That color specification is used as a fill color for the background. The last `background' special on a page is the one that gets used, and is used for the whole of the page image. (This is possible because the prescan phase of dvipng notices all of the color specials so that the appropriate information can be written out during the second phase.)
The `color' special itself has three forms. The first is just `color' followed by a color specification. In this case, the current global color is set to that color; the color stack must be empty when such a command is executed.
The second form is `color push' followed by a color specification. This saves the current color on the color stack and sets the color to be that given by the color specification. This is the most common way to set a color.
The final version of the `color' special is just `color pop', with no color specification; this says to pop the color last pushed on the color stack from the color stack and set the current color to be that color.
dvipng correctly handles these color specials across pages, even when the pages are rendered repeatedly or in reverse order.
A number of persons have contributed, if I forget to mention someone, I apologize. First and foremost we have David Kastrup whose preview-latex project provided the incentive to write this program. There is also a number of people who have contributed by reporting bugs and suggesting improvements as the thing has evolved. These include but is perhaps not limited to (in semi-random order): Thomas Esser (teTeX), Christian Schenk (MIKTeX), Brian R Furry (debian package), Angus Leeming (LyX), Thomas Boutell (libgd), John Jones (first user report), Uwe Kern (xcolor), Alan Shutko, Reiner Stieb, Nick Alcock, Adam Buchbinder, Svend Tollak Munkejord, James Longstreet, Bernhard Simon, Bob McElrath, Georg Schwarz, Jason Farmer, Brian V. Smith, Samuel Hathaway, Thomas R. Shemanske, Stephen Gibson, Christian Ridderström, Ezra Peisach, William H Wheeler, Thomas Klausner, Harald Koenig, Adrian Bunk, Kevin Smith, and Jason Riedy.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Copyright © 2002-2005 Jan-Åke Larsson
mktexpk
, avoiding: Option details