Reply to comment

Fix the latex2html Black Line and PNG Transparency Bugs

The latex2html program is a wonderful and popular package for converting LaTeX to HTML. However, it suffers from a black line and a PNG transparency bug even with the latest version 2002-2-1 (1.71). You should be able to reproduce the bugs and use the workaround below in Ubuntu 6.10.

The Black Line and PNG Transparency Bugs

Try to create the following bugs.tex and then use latex2html to convert it:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\cos^2\theta+\sin^2\theta &= 1, \\
\cosh^2\omega-\sinh^2\omega &= 1.
\end{align}
\end{document}

Point your browser to bugs/index.html, and you may see something like this:

An illustration of the latex2html black line and PNG transparency bugs

Look at the ugly black borders and the grey background. The black lines appear in some images regardless of the image type (either GIF or PNG) you use. (Note: You can select the image type by passing the -image_type gif or -image_type png option.) It seems to appear only when I use the amsmath packpage, so the programming bug probably resides in amsmath.perl. Besides, some PNG images don't have a transparent background.

The Workaround

If you use the GIF format, you can refer to the solutions (here and here) by Clay S. Didier. To fix PNG images, you can use my workaround below, which is partly based on Clay S. Didier's idea. I personally recommend sticking to the PNG format because it is technical superior for such equations, and does not suffer from any patent problem like GIF does. (See the League for Programming Freedom GIF page for details.)

The workaround fixes the problems by post-processing the problematic PNG images generated by the latex2html. Create the following the eqnfix.shscript for fixing the images. Note that the script depends on some PNM utilities. In Ubuntu, they can be installed from the official netpbm package.

#!/bin/sh
# Fix the latex2html black line and PNG transparency bugs
#
# After latex2html has generated the PNG images, run this script
# for each directory that holds the problematic PNG images.
#
# Changes:
#   11-Jan-07: Included a fix for PNG transparency and some small improvements
#   15-Sep-05: Created this script

# Get the directory path
if [ -z "\$1" ]; then
  cat <<EOF
Fix the latex2html black line and PNG transparency bugs.
Usage: \$0 <directory_with_problematic_PNG_images>
EOF
  exit
fi

# Fix each PNG image
for file in \$1/*.png
do
  echo Fixing \$file...
  pngtopnm $file | \
    pnmcrop -black | \
    pnmtopng -transparent "#B3B3B3" > img_fixed.png
  mv -f img_fixed.png \$file
done

Simply invoke the script for each directory that holds the problematic PNG images. For the example above:

\$ latex2html bugs.tex
...omitted...
\$ eqnfix.sh bugs
Fixing bugs/img1.png...
pnmtopng: 16 colors found
Fixing bugs/img2.png...
pnmtopng: 11 colors found
Fixing bugs/img3.png...
pnmtopng: 17 colors found
Fixing bugs/img4.png...
pnmtopng: 9 colors found

After running the script, you should see the following in your browser now:

After fixing the problematic PNG images generated by latex2html

It's obviously what you want, right?

Remarks

The fix above post-processes the PNG images and is thus not a really proper solution. The fix can fail in some rare situations if you play around with the colors of the font and the background. The best solution is to fix the source code of latex2html directly. It can be tedious to fix the bug, and I'm also not an expert in latex2html source and Perl. Please share if you have a better solution. Your feedbacks are welcomed.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.