PDF (letter size)
PDF (legal size)

Installation of Latex2html

Nasser M. Abbasi

July 1, 2015   Compiled on May 28, 2020 at 3:42am

A plain text version is also available of this page which was generated using the following catdvi command 1

catdvi -e 1 -U index.dvi | sed -re "s/\[U\+2022\]/*/g" | sed -re "s/([^^[:space:]])\s+/\1 /g" > index.txt

The file is index.txt

1 Installation on Linux

Installation of Latex2html is very easy on Linux. Used package manager (GUI interface) and select latex2html package. It will install everything needed making sure that texlive is also installed using the package manager so that latex2html style files can be seen by latex.

Once latex2html is installed, I then created a file called $HOME/.latex2html-init

This is my copy of my .latex2html-init


which fixes some issues mentioned below.

>which latex2html

In addition to the above, I had to edit the file /usr/share/latex2html/styles/more_amsmath.perl for the rendering bug described below.

That is all. now latex2html is ready to be used on linux.

2 Installation on windows with MikTex 2.8

After struggling with installation of Latex2html (l2h) on windows for many days, I have decided to write down the final layout showing graphically what the tree looks like. I think a graphical illustration to describe the installation is easier for me, and I suspect for many others, to see where things are.

The diagram below shows the final installed tree. This tree layout can be used as a guide for anyone who wants to install l2h on their windows system.

Figure 1:Installed tree

2.1 Installation steps

The following are the main points to watch out for in order to minimize installation problems

  1. Install the software components needed on the same drive, where your data is and where you will be working, because if you install the software on the C: drive, and your data is on another driver, then you will find that things might not work (this was in my case).
  2. Start by downloading all the software components and install them one after the other. These are the components needed and where I downloaded them from
  3. Now install MikTex, perl, netpbm, ghostcript, gsview into the directories as shown in the tree.
  4. untar latex2html into folder latex2html-initial/
  5. Edit latex2hml-initial/prefs.m and add/change the corresponding lines as the following
               $prefs{'EXTRAPATH'} = 'C:\\texmf\\gsAFLP\\gs8.54\\bin;C:\\texmf\\GnuWin32\\bin';
               $prefs{'PREFIX'} = 'C:\\texmf\\latex2html';
               $prefs{'TEXPATH'} = 'C:\\texmf\\MiKTeX2.8\\tex';
               $prefs{'TMPSPACE'} = 'C:\\texmf\\tmp';
  6. Edit latex2html-initial/config.bat and add/change the corresponding lines as the following set PERL=c:\texmf\perl\bin\perl.exe
  7. Add the following to the PATH environment variable on windows (Using Computer-¿Properties-¿Advanced)
  8. Add a new environment variable GS_LIB and give it the following value

    Notice that the above is sufficient to make latex2html happy as far as GS_LIB is concerned, and hence there is no need to edit the file cfgcache.pm and set this value there as well, which if you check the file now, most likely this variable will be empty

             $cfg{'GS_LIB'} = q'';

    but this was OK on my system, since it is now defined in an environment variable. But it should do no harm to also replace the above with

              $cfg{'GS_LIB'} = q'.;C:\\texmf\\gsAFLP\\gs8.54\\lib;C:\\texmf\\gsAFLP\\fonts';

    Even though I did not have to do it on my system as I mentioned above.

  9. Add a new environment variable RGBDEF and give it the following value
  10. There is no need to define an environment variable TEXINPUTS since install.bat when run will copy the latex2html style files and put them in location within MikTex folder where they can be located by MikTex latex.exe without the need to define such an environment variable.
  11. Start a new DOS terminal to make sure the effect of setting the above environment variable is now in effect.
  12. There is one bug that shows up if you are using the package amsmath which causes the generated HTML to contain extra text showing up inside the images. To fix this 2 , cd to the folder G:\texmf\latex2html-initial\styles note: the this file on my linux box was located in /usr/share/latex2html/styles/more_amsmath.perl and edit the file called more_amsmath.perl as follows

    ----- From here -----
    *** styles/more_amsmath.perl.ORG        Sat Dec  2 15:15:01 2000
    --- styles/more_amsmath.perl    Fri Oct  1 08:42:49 2004
    *** 95,100 ****
    --- 95,101 ----
          } else { $tag = ';SPMnbsp;;SPMnbsp;;SPMnbsp;' }
    +     $scan =~ s/($comment_mark\d+) /$1\n/g;
          if ($labels) {
            $labels =~ s/$anchor_mark/$tag/o;
            ($labels , $scan);
    ----- To here -----
  13. cd back to latex2html-initial/, run config.bat. If no errors then go to the next step.
  14. run install.bat. Now latex2html will be installed to C:\texmf\latex2html
  15. run latex2html-initial/test.bat and look for any errors.
  16. If all is well, that is all. Now you are ready to use latex2html. Go to next step
  17. Perform post installation configuration. Edit the file c:\texmf\latex2html\l2hconf.pm and make any changes needed. The following are the changes I made to my l2hconf.pm to make the generate HTML and images look better for me.

    $FONT_SIZE = "12pt";
    $LOCAL_ICONS = 1;
    $SHORTEXTN = 1;
    $ANTI_ALIAS = 1;
    $HTML_VERSION = '4.0';
    $NO_SUBDIR = 1;
    $DISCARD_PS = 0;
  18. On Linux/Unix system, the above commands can be put in $HOME/.latex2html-init

    Make sure to end the file with "1;" This is my file as an example

    cat .latex2html-init

    $FONT_SIZE = "12pt";
    $LOCAL_ICONS = 1;
    $SHORTEXTN = 1;
    $ANTI_ALIAS = 1;
    $HTML_VERSION = '4.0';
    $NO_SUBDIR = 1;
    $DISCARD_PS = 0;
    $DVIPSOPT = '-E';
    $LATEX_COLOR = "";

  19. one final step is important. This step is needed to allow you to run miktex on latex files that include the package html. Since html.sty comes with latex2html, trying to compile latex file that uses the html package using miktex itself will fail, since miktex does now know where these style files are. Hence we need to tell miktex where these files are and register the root using miktex GUI.

    To do that, create a folder such as c:\myStyleFiles\tex\latex\misc

    It is very important that the path contain tex\latex in it. The folder misc can be names anything, as this is where you will copy the latex2html style files to. Once you create the above directories, the copy all the style files from latex2html tree, and they are located in the folder texinput in your latex2html installation tree. Copy all these style files to the directoy c:\myStyleFiles\tex\latex\misc

    You should now have

    $ dir
  20. Now that the latex2html style files are put in a TDS compliant tree structure, we can register this tree with Miktex. Start the Miktex GUI options, Using Miktex->Maintenance->Setting and now click on Roots in the menu, and click on Add... and select the folder c:\myStyleFiles making sure you just select this root, and do not select the whole path below it. Just stop at the root when selecting. Click OK

    Figure 2:Selecting root
  21. Now that latex2html style files are registered with Miktex, we can use programs such as TexMaker or any other program to compile the latex files. We can also use Latex2html to compile the same latex files to html.

2.2 Some errors and possible solution

  1. If you get this error when running test.bat that looks like something as the following

    pstoimg.bat: Error: Ghostscript returned error status 1
    pstoimg.bat: Error: Couldn't find pnm output of G:\texmf\tmp\l2h1716\image002.ps

    Then check that you have defined GS_LIB environment variable correctly to point to the ghostscript lib/ and font/ directly as shown above.

  2. if you get an error from test.bat that looks like something as the following
                 pstoimg.bat: Error: pnmtopng.exe -interlace -trans gray85 < p3704.pnm > img1.png" failed: No such file or directory

    Then make sure that you have defined the env. variable RGBDEF as described above.

  3. some of the bitmap images produced for the mathematics in the document have a solid dark bar, usually at the bottom or the side of the bitmap image. The reason for this is unknown. But I found by trial and error that setting the following values in my l2hconf.pm eliminated most if not all of these

    On my system, any value less than 1.8 for the above, with everything else is fixed, produced the side solid edges again.

    This problem needs to be fixed.

    See also this page https://ccrma.stanford.edu/ jos/webpub/Eliminating_Black_Rules_Equation.html which mentions a solution to removing black bars from under equations.

  4. Some mathematics equations are still underlined, even after doing the above. I found this was the case when I was using linux. If you still see the underlines, then try the following: edit l2hconf.pm and set the value of DVIPSOPT as follows
             $DVIPSOPT = '-E' ;
  5. Some mathematics formula have gray color in background. I noticed this on some equations having gray background. In this case, edit l2hconf.pm and set the following:
            $LATEX_COLOR = "";

    The above should remove the gray background. If the above does not remove the gray background then try the following: In your latex document itself, add the following 2 lines 3 in the document preamble


    Then try again. This should, hopefully, remove the gray background. The above trick did it for me when I moved to new Linux OS and found the gray background came back, even though I was using the same .latex2html-init file as before.

  6. Watch out for the -no_resuse option to latex2html. If one is also using -no_subdir, then Latex2html will ask the user if they want the images in the current folder deleted:

              latex2html -no_reuse -no_subdir foo.tex

              This is LaTeX2HTML Version 2008 (1.71)
              Cannot create directory .\: File exists
              (r) Reuse the images in the old directory OR
              (d) *** DELETE *** the images in .\  OR
              (q) Quit ?

    And if you select option (d) then it will delete all the images in the current folder. This can include any images that were not related to latex2html earlier runs at all, and it could be your own images that you did not want deleted. This happened to me, but I had a backup copy. So, if you intend on using -no_subdir then it is safer to not use -no_reuse.

  7. l2h does not support the package ragged2e. I use HTML CSS style to change the alignment of the table cells. The following code will not work as expected in l2h


    \begin{tabular}{|P{2in}|P{2in}|}  %notice UPPER case P here
    jfadlkfj lkfjdsl fdasfad fkjdsklfja&
    djflkjads;flkajds;flk dsafjdads\tabularnewline\hline

    jfadlkfj lkfjdsl fdasfad&
    djflkjads;flkajds;flk dsafjdad\tabularnewline\hline

  8. An error ! LaTeX Error: File `html.sty' not found. is generated when compiling the latex file due to including the html package \usepackage{html} using another program such as texmaker’s pdflatex.

    html.sty file is part of latex2html, and hence some programs that run your latex file will not know where it is. First, try to run texhash

    >sudo texhash
    [sudo] password for me:
    texhash: Updating /usr/local/share/texmf/ls-R...
    texhash: Updating /var/lib/texmf/ls-R-TEXLIVEMAIN...
    texhash: Updating /var/lib/texmf/ls-R-TEXLIVEDIST...
    texhash: Updating /var/lib/texmf/ls-R-TEXMFMAIN...
    texhash: Updating /var/lib/texmf/ls-R...
    texhash: Done.

    and try again. If you still have the error, it could mean that you have installed texlive from one source, and latex2html from another source and texmf is not coordinated. When I had this problem on linux, the reason was that l2h was installed using apt and latex was installed directly from a tar file.

    To resolve this, apt was used to install both texlive and also latex2html. Now the problem went away. Hence the suggestion is, on linux, to use apt or the package manager to install both latex and latex2html. This way, all the path and texmf setting is correct, and this error should be not show any more.

2.3 Making your latex code latex2html friendly

These are few things that I found that helped in using latex2html

  1. Always include html package
  2. l2h does not support tabularx package. Either just use tabular or as a work around add the following to the preamble

  3. In addition, l2h will not recognize this
  4. l2h does not support listings.sty, therefore if the latex code already does something as

    then it will not work with l2h. The solution is to add the following4


    I found one problem in the above. If the file has an absolute path on it, then it will not be included. But if the file is in the same folder as the latex file, then it will be included. So, the following will not work

  5. Some images that I use were too large for inclusion in PDF without being scaled, even though the size looked OK for html.

    So I wanted a way to use conditional logic so that when the latex file is run by pdflatex, it will scale the image, but when it is run by latex2html, the image is not scaled. I settled at this solution.





  6. Wanted a way to modify the <HEAD> META tags in the HTML file generated by latex2html. I settled on this method for now. May be there is a better way? Thanks for old posts I found on the net by Thomas Anders and Ross Moore which helped in finding this solution.

    1. created a file called l2h_init.pl in the same folder where my latex file is. This file looks like this

      $MY_KEYWORDS = "Latex2html, HTML, MikTex";
      $MY_DESCRIPTION = "This describes Latex2html";
      sub meta_information {
          local($_) = @_;
          if (not defined $MY_KEYWORDS) { $MY_KEYWORDS   = "$FILE"; }
          if (not defined $MY_DESCRIPTION) { $MY_DESCRIPTION = "$_"; }
          do { s/<[^>]*>//g;
               "<!-- Do not edit here - edit TeX file $FILE.tex instead -->\n" .
               "<META NAME=\"description\" CONTENT=\"$MY_DESCRIPTION\">\n" .
               "<META NAME=\"keywords\" CONTENT=\"$MY_KEYWORDS\">\n" .
               "<META NAME=\"resource-type\" CONTENT=\"document\">\n" .
               "<META NAME=\"distribution\" CONTENT=\"global\">\n" .
               "$MY_META" } if $_;
      1;      # This must be the last line
    2. Now run latex2html to convert my latex file to html. Suppose my latex file is called foo.tex, then the command I used is
                       latex2html -init_file l2h_init.pl foo.tex
    3. now I looked at the generated HTML file foo.htm, and I see the header as follows
      <!-- Do not edit here - edit TeX file index.tex instead -->
      <META NAME="description" CONTENT="This describes Latex2html">
      <META NAME="keywords" CONTENT="Latex2html, HTML, MikTex">
      <META NAME="resource-type" CONTENT="document">
      <META NAME="distribution" CONTENT="global">

      <META NAME="Generator" CONTENT="LaTeX2HTML v2008">
      <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

  7. do not use the following \href instead, use the following

    And remember to always include the html package using

  8. do not enclose the image in a frame using \fbox. This will cause the image not to show up correctly. i.e. do not do something as the following

    But instead just write

  9. I had the following problem when using l2h when it creates a subdirectory to put all the resulting HTML and image into. This is because the hyperlinks inside the HTML would now all be off by one level.

    Assuming you are at folder called A/ and you run l2h on a latex file called B.tex which contains hyperlinks to other places in your site, and these links are added so that they are relative hyperlinks. i.e. the hyperlinks are relative the folder A. When l2h process the file B.tex, it would by default create a sub folder and put the result into it. This folder is called A/B/.

    However, from B/ the hyperlinks are now not correct as the case would be if the file was still in A/. Therefore, I now add the following option to my l2h command -no_subdir. This means the current folder A/ will contain all the output from the l2h run, which can make the folder too messy.

    However, this for me was a better solution than having to change all the hyperlinks in the latex file or to make them all absolute links (which I do not think is a good idea).

    I think the correct solution is to make l2h behave the same way as when Microsoft WORD saves a document as a web page, where it would leave the html file at the same level as the word document, but would then create a special folder called document_files which contains all the images and other html files generated.

  10. Use a css file to customize the look of the resulting HTML instead of adding HTML code in the latex file using l2h special latex commands. Once you create a css file, you can tell l2h to use it with the option
             latex2html -style="myfile.css" myfile.tex
  11. When running latex2html on a file called say foo.tex, it will create also a file index.htm in addition to foo.htm and link to foo.htm from index.htm. This can cause a problem if one already has an index.htm in the same folder and hence it will be overwritten.

    To make latex2html create only foo.htm the option -no_auto_link can be used which is what I currently do.

  12. Including animated GIF files. To include an animated gif file, one can not include a gif file in latex, i.e. one can not just type

    I have a file called foo.gif, an animated file, which I want to have as a thumbnail, and run as animated, and wanted to also click on it if I wanted to see the animation in actual size. By trial and error, I found the following solution which worked for me



    When running the above through latex2html, I would get a warning about a ”bad file descriptor” and ”could not copy foo.gif to tree” type messages, but the latex2html did complete, and I ignored these. The generated HTML did work, and that is what important.

  13. to support both latex2html and pdflatex do the following


      %l2h only

    %\begin{latexonly}    % WARNING, SPECIAL COMMENT DO NOT REMOVE
         %for pdflatex only
    %\end{latexonly}      % WARNING, SPECIAL COMMENT DO NOT REMOVE


2.4 log files

In here I have links to the output generated from running config.bat, install.bat and test.bat.

I also have link to my l2hconf.pm. Notice that on my PC, I have installed everything on the G:\ drive under a folder I called LATEX and not under C:\texmf as I showed in the diagram, but as long as you have installed everything on the same drive, it does not have to be the C: drive and can be anything else.

  1. output_from_config.txt
  2. output_from_install.txt
  3. output_from_test.txt
  4. l2hconf.pm

3 installation on cygwin

These are the steps I did to install latex2html under cygwin.

  1. I downloaded cygwin from http://www.cygwin.com/ and installed it on windows. I installed EVERYTHING. Used Unix mode. (not DOS mode).
  2. made sure the following is installed after the above is completed
           > which latex

           > latex -v
           pdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4)
           kpathsea version 3.5.4

           > which pdflatex

           > pdflatex -v
           pdfeTeX 3.141592-1.21a-2.2 (Web2C 7.5.4)
           kpathsea version 3.5.4

           > cygcheck -c | grep -i tex
           tetex-base                      3.0.0-3                 OK

           > which perl

           > perl -v
           This is perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int
           (with 12 registered patches, see perl -V for more detail)

            > cygcheck -c | grep -i perl
            perl                            5.10.1-3                OK

            > which gs

           > gs -v
          GPL Ghostscript 8.63 (2008-08-01)
           Copyright (C) 2008 Artifex Software, Inc.  All rights reserved.
  3. Looked to make sure netpbm package allready installed from above installation of cygwin, to check, I lookeded for one of its programs

           > which pngtopnm

           > cygcheck -c | grep -i netpbm
             libnetpbm-devel                 10.49.2-1               OK
             libnetpbm10                     10.49.2-1               OK
             netpbm                          10.49.2-1               OK
  4. downloaded latex2html version 2008 from http://www.ctan.org/tex-archive/support/latex2html/ and untar it in some directoy.
  5. cd to latexhtml and edit the file L2hos.pm, replace the line (near the end)
           @ISA = load('L2hos', $^O);


           @ISA = load('L2hos', 'unix');
  6. edited prefs.pm and set location of tmporary disk space. This step is not needed, but I like to be more sure where temporary disk space for latex2html is.
           $prefs{'TMPSPACE'} = '/cygdrive/G/LATEX/TMP';
  7. run configure

    Noticed that it did not use TMP defined above in prefs.pm, which is not I want TMP to point to. So I edited the file generated by running configure above, which is called cfgcache.pm located in the same folder, and forced it to use my TMPSPACE by changing the line as follows:

          $cfg{'TMPSPACE'} = q'/cygdrive/G/LATEX/TMP';
  8. run the command make
  9. run the command
           make install
  10. run the command
           make test

    cd to the test directory and check the output to make sure it is OK.
    As of today (June 6, 2010), there is a problem with cygwin installation which is not yet resolved. Cygwin generates an error coming from one of the perl file (L2h/Unix.pm). I send a bug report to cygwin on this. Until this is fixed, I am not able to run Latex2html under cygwin

    Installed cygwin 1.7.5 on windows 7 (64 bit OS), and when I run some
    command which uses perl, I get the following error:

    0 [main] perl 2528 C:\cygwin\bin\perl.exe: *** fatal error - Internal
    error: TP_NUM_W_BUFS too small.


    I installed cygwin, all of it on windows 7, 64 bit os.
    All went ok.

    Then I installed latex2html, and I am trying to use latex2html under
    cygwin, which uses perl. (latex2hml is a PERL script)

    When I run latex2html command on some latex file, I get many of the
    above errors each time perl is called:

    $ uname -a
    CYGWIN_NT-6.1-WOW64 me-PC 1.7.5(0.225/5/3) 2010-04-12 19:07 i686 Cygwin

    $ cygcheck -c | grep perl
    perl                            5.10.1-3                OK
    perl-Error                      0.17016-1               OK
    perl-ExtUtils-Depends           0.302-1                 OK
    perl-ExtUtils-PkgConfig         1.12-1                  OK
    perl-Graphics-Magick            1.3.7-2                 OK
    perl-Image-Magick                    OK
    perl-libwin32                   0.28-3                  OK
    perl-Locale-gettext             1.05-11                 OK
    perl-ming                       0.4.3-1                 Incomplete
    perl-SGMLSpm                    1.03ii-2                OK
    perl-Tk                         804.028-3               OK
    perl-Win32-GUI                  1.06-3                  OK
    perl-XML-Simple                 2.18-10                 OK
    perl_manpages                   5.10.1-3                OK
    postgresql-plperl               8.2.11-1                OK
    subversion-perl                 1.6.11-1                OK

    $make test
    Converting image #2
           1 [main] perl 3104 C:\cygwin\bin\perl.exe: *** fatal error -
    Internal error: TP_NUM_W_BUFS too small.

    Error while converting image

    This is the file where this error comes from Unix.pm This is a more detailed error message:

    > 262: my ($self,$cmd,$in,$out,$err) = @_;
    > 263: carp qq{Debug (syswait): Running "$cmd"\n} if($Verbose);
    > 265: my $status;
    > 266: my $child_pid;
    > 267: if ($child_pid = fork) {
    > 268: $status = waitpid($child_pid, 0);
    > 274: unless(exec($cmd)) {
    > 0 [main] perl 4524 C:\cygwin\bin\perl.exe: *** fatal error - Internal error: TP_NUM_W_BUFS too small.
    > 269: carp "Debug (syswait): Finished child process: #$child_pid\n"
    > 270: if($Verbose);
    > 271: $child_pid = 0;
    > 272: return($?);
    > exited L2hos::Unix::syswait

3.1 log files

In here I have links to the output generated from running above commands:

  1. This is output from cygwin configure
  2. This is output from make install

4 the problem with the verb command

When using Latex2html from Linux hosted inside a virtual machine such as Oracle VBox, and when the latex files sits on windows shared folder, then I found that Latex2html does not generate code for the \verb command.

This note describes this problem. As of now, there is no solution to this other than copying the latex source file to the Linux file system.

Here is another note on the same problem above that I wrote before

5 Using graphics in latex2html

These notes are really my cheat sheet on how to including graphics in Latex, and not specific to Latex2html. I put them here so they are all in the same place.

Generally, I use graphicsx package for everything. To go from .tex file to .dvi file, one uses the latex command. To go from .tex to .pdf file, one uses the pdflatex command. But depending on which is used, different graphics are supported as show in this diagram

        foo.tex ---- latex---------------------->  foo.dvi
                       | \usepackage[]{graphicx}
                       | \includegraphics[]{a}

        foo.tex ---- pdflatex ------------------>  foo.pdf
                       | \usepackage[pdftex]{graphicx}
                       | \includegraphics[]{a.png}

Note the use of \usepackage[pdftex]{graphicx} when the input image is .png or .jpg type. Without this, then pdflatex will complain that it does not know the image size (no BoundingBox) error.

Unless I put an explicit size. Like this

        foo.tex ---- pdflatex ------------------>  foo.pdf
                       | \usepackage[]{graphicx}
                       | \includegraphics[natheight=1in,natwidth=5in,height=2in,width=5in]{a.png}

6 References