TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using tex4ht to produce XHTML files from a LaTeX file. The XHTML file I obtain uses images for some equations which tex4ht could not convert directly to XHTML.

Problem: images of equations have very bad quality.

What I want: Better quality images.

More info on attempts & system:

I'm using MikTeX 2.9 under Windows Vista. I go to the command line and type htlatex document.tex "xhtml" to get the resulting XHMTL file.

After doing some search on the web, I tried to change the file tex4ht.env as mentioned in here (changing -density 110x100 to -density 220x220 -geometry 50%) in all locations I could find in my system (within the MikTeX path and also in the AppData windows directory) but the results are the same. I obtain during the compilation of hlatex the following line (among others):

System call: mgs -sDEVICE=pngalpha -sOutputFile=Untitled11x.png -r110x110 -dEPSC rop -dBackgroundColor=16#ffffff -dTextAlphaBits=2 -dGraphicsAlphaBits=2 -q -dbat ch -dNOPAUSE zzUntitled1.ps -c quit

In particular, I would guess that the -r110x110 means resolution was still set to 110x110, despite my changes to the file tex4ht.env.

Any suggestions on how to improve the quality of equations images?

share|improve this question
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – adn Feb 8 '12 at 5:40
up vote 13 down vote accepted

The env file is stored in %texmf-home%/texmf-dist/tex4ht/base/unix or %texmf-home%/texmf-dist/tex4ht/base/win32, depending on your operating system. For testing purposes, it is best to make copy of that file in your working directory.

The structure of this file is little bit strange:

Gsome command and the parameters
 Ganother command
GNext command
 Gcommand again

Spaces are important. All lines with space at the beginning are ignored. Tagged sections are sometimes ignored. Quoting tex4ht.env itself:

Tagged script segments ... are scanned only if their names are specified within -ctag switches of tex4ht.c and t4ht.c. When -c switches are not supplied, a -cdefault is implicitly assumed.

In the example, only GNext command is actually executed. If you look at actual tex4ht.env file, you can see that there are several configurations for output of images. Default is

 Gdvips -E -q -Ppdf -f %%1 -pp %%2 > zz%%4.ps
 Ggs -sDEVICE=pngalpha -sOutputFile=%%3 -r110x110 -dEPSCrop -dBackgroundColor=16#ffffff -dTextAlphaBits=2 -dGraphicsAlphaBits=2 -q -dbatch -dNOPAUSE zz%%4.ps -c quit
 Grm zz%%4.ps    
Gdvips -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.eps
Gpstoedit -f svg zz%%4.eps %%3      
Gdvips -E -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2  > zz%%4.ps
Gconvert -trim +repage -density 110x110 -transparent '#FFFFFF' zz%%4.ps %%3


Gdvips -E -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2  > zz%%4.ps
Gconvert -trim +repage -density 110x110 -transparent '#FFFFFF' zz%%4.ps %%3

means, that default conversion uses dvips command to convert picture to the eps file and then using convert to the final output format.

There is also section

Gdvipng -T tight -x 1440 -D 96 -bg Transparent -pp %%2:%%2 %%1 -o %%3
Gdvipng -T tight -x 1440 -D 96 -bg Transparent -gif -pp %%2:%%2 %%1 -o %%3
Gdvips -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.ps
Gconvert -crop 0x0 -density 110x110 -transparent '#FFFFFF' zz%%4.ps %%3
Grm zz%%4.ps

Which uses dvipng instead of convert and dvips and in my opinion the output is better. So to use this configuration, just erase spaces before <convert> and </convert>, and add space at the beginning of <dvipng> and </dvipng>

Another opinion is to use svg images instead of the png. Just add :

Gdvisvgm -n -p %%2 -c 1.2,1.2 -s %%1 > %%3

Create the file myconfig.cfg:


and call:

htlatex file "myconfig"


Another option is to to use make4ht build system. You can specify image conversion command in the build file, see the chapter on that matter

share|improve this answer
thanks for the info! I tried what you suggested and managed to get better quality images with dvipng. – Daniel Feb 8 '12 at 17:08
The bizarre thing is that it worked opposite to what you said. In the original file my <convert> had a space, while <dvipng> hadn't. I switched the spaces and everything went fine, except for a warning. I tried your suggestion with dvisvgm, but did not manage to obtain the svg files of equations. I went to SourceForge, downloaded dvisvgm, copied it to d:\texmf\miktex29\miktex\bin, but that didn't worked either. – Daniel Feb 8 '12 at 17:15
I use texlive, so it is possible there are differences in the default configuration. – michal.h21 Feb 8 '12 at 17:26
can you run dvisvgm from the command line? – michal.h21 Feb 8 '12 at 17:26
you are right, I corrected my answer – michal.h21 Feb 9 '12 at 16:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.