13

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?

adn
  • 11,233
Daniel
  • 389
  • 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 08 '12 at 05:40

1 Answers1

15

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:

<tag>
Gsome command and the parameters
 Ganother command
</tag>
 <anothertag>
GNext command
 Gcommand again
 </anothertag>

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

 <convert>
 G.png
 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    
G.svg
Gdvips -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.eps
Gpstoedit -f svg zz%%4.eps %%3      
G.
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
 </convert>

lines

G.
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

<dvipng>
G.png
Gdvipng -T tight -x 1440 -D 96 -bg Transparent -pp %%2:%%2 %%1 -o %%3
G.gif
Gdvipng -T tight -x 1440 -D 96 -bg Transparent -gif -pp %%2:%%2 %%1 -o %%3
G.
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
</dvipng>

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 :

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

Create the file myconfig.cfg:

\Preamble{xhtml}
\Configure{Picture}{.svg}
\begin{document}
\EndPreamble

and call:

htlatex file "myconfig"

Edit:

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

michal.h21
  • 50,697
  • thanks for the info! I tried what you suggested and managed to get better quality images with dvipng. – Daniel Feb 08 '12 at 17:08
  • The bizarre thing is that it worked opposite to what you said. In the original file my had a space, while 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 08 '12 at 17:15
  • I use texlive, so it is possible there are differences in the default configuration. – michal.h21 Feb 08 '12 at 17:26
  • can you run dvisvgm from the command line? – michal.h21 Feb 08 '12 at 17:26
  • Yes. I tested it on a dvi file and the conversion was successful. I guess I need to experiment a little with dvisvgm using your (very useful) suggestions. I may also try to install texlive in my system. – Daniel Feb 08 '12 at 19:23
  • I finally understood what went wrong. As stated above, everything which is within ... is ignored, as long as '' and '' are not preceeded by a space. So, to omit the default, you have to remove the spaces before '' and '</convert'. To switch to dvipng for image convertion, one has to add a space and , just the opposite of what was said above (a gap?). I also installed TexLive. Results for images are better than MikteX, at least for the default mode (not using dvipng). dvisvgm now works correctly :) – Daniel Feb 09 '12 at 16:02
  • 1
    you are right, I corrected my answer – michal.h21 Feb 09 '12 at 16:07
  • Tip for Windows users: tex4ht.env is in %texmf-home%/texmf-dist/tex4ht/base/win32 only for TexLive. Users of MikTex will also have a copy of tex4ht.env on the MikTeX directory, but it is not the file used during compilation. The system uses a local copy of tex4ht.env available on C:\Users\UserName\AppData\Roaming\MikTeX.. (I don't recall the rest of the path, since I uninstalled MikTeX). I think (but did not test) you can copy tex4ht.env to the location of the .tex file you are converting. This file will have precedence over all tex4ht.env files found on the system. – Daniel Feb 09 '12 at 16:11
  • Enabling <dvipng> and adding the 2 lines for svg seems to work for me with TeXLive under Ubuntu, but results in a 80MB svg file starting from a 60 kB eps image, which I'm not even able to view due to an underpowered Ubuntu running on VirtualBox. – mmj Dec 02 '13 at 17:16
  • @mmj this is probably caused by -n option, this converts character glyphs to paths. this may cause a bigger size. try to replace -n with --no-fonts=0. if that doesn't work, drop the -n option completely. – michal.h21 Dec 02 '13 at 18:31
  • Replacing -n with --no-fonts=0 or dropping it seems that I run into font problems, probably due to the fact that I use accented chars, greek chars, and math symbols. – mmj Dec 03 '13 at 00:35