[l2h] listings and figures

Ross Moore ross@ics.mq.edu.au
Thu, 10 Oct 2002 09:11:12 +1000 (EST)


Hello Manual,

You wrote:
> 
>     Hello.  I have a couple of questions regarding problems and how I
> solved them.  I have been using LaTeX2HTML quite heavily ovr the last
> years, and although I am very happy with it, the latest version
> exhibited an unexpected behavior in a couple of points.  I am using
> LaTeX2HTML Version 2002-2-1 (1.70).
> 
>     The problems (and solutions) where:
> 
>     * pstoimg was giving seek errors; I traced this back to the .ps
> files for every image being generated as just black rectangles.
> Eventually I discovered that images.tex was including
> \usepackage[usenames,dvips]{color} while, at the same time I was using
> in the main file \usepackage{colordvi} (included from a .tex file).
> The combination of both two was confusing the image generation.  I
> solved this by defining
> 
> $LOAD_LATEX_COLOR = " ";
> $LATEX_COLOR = " ";
> 
> in the l2hconf.pm file _AND_ by commenting the line 6845 in the
> LaTeX2HTML script to read
> 
> #	$LOAD_LATEX_COLOR = "\n\\usepackage[dvips]{color}";
> 
>     Is the latter needed?  Any other recomendation?  I would prefer

Yes, it is necessary for the color package to be loaded, for 
use with images.tex , with standard LaTeX2HTML jobs.

If you are loading it anyway, then there should be no problem
requesting it twice with the same driver ('dvips' here),
except that there may be a problem with any other options, depending
upon which call comes first in images.tex .

Can you determine exactly why the combination of calls:

  \usepackage[usenames,dvips]{color}
  \usepackage{colordvi}

caused a problem, and in which order ?
Doesn't  colordvi  require  color  with the dvips  driver anyway?

Or have I mis-interpreted what you said?
Maybe  colordvi  was not loaded at all for  images.tex
but some \special commands were still making it into that job,
 --- without the proper package support ???



> not touching the source code ---even in this very slight form.

The $LOAD_LATEX_COLOR  variable is used here only:

    $preamble .= $LOAD_LATEX_COLOR."\n" unless ($preamble =~ /[,\{]color[,\}]/);

This means that it should *not be used* at all if your document
preamble already contains strings such as:  
  \usepackage{color}
  \usepackage[<options>]{color}
  \usepackage{color,<other packages>}
  \usepackage{<other packages>,color}
  \usepackage[<options>]{<other packages>,color,<other packages>}
etc.

So $LOAD_LATEX_COLOR should have had no effect when the preamble
contains  \usepackage[usenames,dvips]{color} ,
but it would be used with   \usepackage{colordvi} .

It looks like the above line of coding could be usefully extended
to become:  

    $preamble .= $LOAD_LATEX_COLOR."\n"
        unless ($preamble =~ /[,\{]color(dvi)?[,\}]/);
                                        ^^^^^^


Perhaps this should be extended further to allow spaces; e.g.
to recognise also
  \usepackage[<options>]{<other packages>, color ,<other packages>}
or
  \usepackage[<options>]{<other packages>,
     color,
    <other packages>}
etc.


An alternative is to alter the automatic setting of $LOAD_LATEX_COLOR
to become:

  $LOAD_LATEX_COLOR = "\n\\usepackage[dvips]{color}"
	unless (defined $LOAD_LATEX_COLOR);

which would give another method of overriding the standard behavior.

 
>     * One of the documents I want to convert to HTML has quite a lot
> of \begin{listing}{}...\end{listing}.  These are (after the
> modifications above) converted to images and rendered quite nicely;
> but blank lines are translated into '\par' commands.  While this is OK
> for (most of) LaTeX code, the listings environment interprets them as
> strings (and not LaTeX code) and they appear verbatim in the final
> figures.  I could bug the listings environment into interpreting LaTeX
> code, but then I would have to escape all underscores, instead of just
> cutting and pasting.  I fiddled around (again) with LaTeX2HTML and
> changing the line
> 
>     s/((\%|$comment_mark\d*)|.)(\r*\n[ \t]*){2,}[ \t]*/$1\n\\par \n/og;
> 
> in the subroutine substitute_pars to
> 
>     s/((\%|$comment_mark\d*)|.)(\r*\n[ \t]*){2,}[ \t]*/$1\n\n/og;

This is the only way LaTeX2HTML recognises paragraph separations
in running text, so it is not a good idea to change it in this way,
as you discovered ....
 
> (i.e., forgetting about the \par command) solved the listings
> problems, but sometimes different paragraphs in the LaTeX code do not
> appear as such in the HTML output.  Any hint on how to tell LaTeX2HTML
> not to preprocess code which from which an image is going to be
> generated?  I looked at the places where verbatim appears, and they
> are a lot...


Try adding 'listings' to the following regular-expression;
currently:

 $verbatim_env_rx = "\\s*(\\w*[Vv]erbatim|rawhtml|imagesonly|tex2html_code)[*]?";

revise to read:

$verbatim_env_rx = "\\s*(\\w*[Vv]erbatim|rawhtml|imagesonly|tex2html_code|listings)[*]?";

The following achieves the same effect, and is perhaps more elegant:

	$verbatim_env_rx =~ s/\)/|listings$&/;

or

       $verbatim_env_rx =~ s/\)/|$MY_VERBATIM_ENVS$&/ if ($MY_VERBATIM_ENVS);

where $MY_VERBATIM_ENVS can be defined as a separate list, with | as delimiter;
e.g.
  $MY_VERBATIM_ENVS = 'listings';
or
  $MY_VERBATIM_ENVS = 'listings|pascalcode|cppcode';
etc.


You should make these definitions is an initialisation file, so that it will
override the current definition from  latex2html .

Indeed most changes to LaTeX2HTML can be done this way,
rather than directly editing the latex2html script.
This is true even of whole subroutines, since the initialisation file
are read after the latex2html script has been read and compiled.



Please explore the above ideas.
Whatever you find to be the most effective can be easily incorporated
into the latex2html script.


Hope you find some useful ideas here,

	Ross Moore


> 
>     Thanks for all and any help.  
> -- 
> +--------------------------------------------------------------------------+
> |Manuel Carro -- Facultad de Inform_tica -- U. Polit_cnica de Madrid (UPM) |
> |  Email: mcarro@fi.upm.es --- Ph: +34-91336-7455 --- FAX: +34-91336-7412  |
> |http://lml.ls.fi.upm.es/~boris --- http://clip.dia.fi.upm.es/Software/Ciao|
> _______________________________________________
> latex2html mailing list
> latex2html@tug.org
> http://tug.org/mailman/listinfo/latex2html