Hello Hans,

On 23/10/2004, at 2:03 AM, Hans Fangohr wrote:

In the absence of any replies that would solve my problem I will
report an ugly hack which allows me to do what I need to do. (But it
is far from being good.)

Sorry, I've been away for the past few days, so have only now had a look at the problem.

There are several ways to tackle it, each depending upon
just what you want to produce for the HTML of the listing

If you want just a simple verbatim listing of the code,
set within  <PRE> ... </PRE> tags, then one approach is
to hook into LaTeX2HTML's treatment of 'verbatim-like'

*Any* environment which has either 'verbatim' or 'Verbatim'
in the name will be processed that way automatically.
So you could do:

  1.  place the following coding in the preamble:


2. change all of your usages of: \begin{lstlisting} to \begin{myverbatim} \end{lstlisting} to \end{myverbatim}

Now the document should process fine in both
LaTeX and LaTeX2HTML.
*Any* environment name containing 'verbatim' could be
used here' it doesn't have to be 'myverbatim'.

One problem with this solution is that an optional argument to the listing environment is not recognised as such by LaTeX2HTML. There's no simple way to overcome this without some edits to the coding of the 'texexpand' and 'latex2html' Perl scripts.

However, maybe you want the HTML to be an image of the
environment that LaTeX would produce, as at present
where the {lstlisting} environment is treated as being

In that case, best would be to write a short Perl
subroutine, named  do_env_lstlisting  as follows.

sub do_env_lstlisting { local ($_) = @_; my $env_id = ++$global{'max_id'}; $_ =~ s/\\par/\n\n/g; &process_undefined_environment('lstlisting', $env_id, $_); }

This could be placed in an initialization file, or in a file listings.perl for loading in response to the \usepackage{listings} command. Such a package module could then be expanded to provide greater support for the options and syntax defined in the listings.sty LaTeX package.

Hmm. That \n\n replacement may not work under DOS/Windows, where the line-ending character is different.

If that's a problem, try instead:

sub do_env_lstlisting { local ($_) = @_; my $env_id = ++$global{'max_id'}; $_ =~ s/\\par/

  &process_undefined_environment('lstlisting', $env_id, $_);

... or buy a Unix box. :-)

The trick to produce an empty line which should not appear as '\par' in latex2html's graphical output is to print something invisible in that line, for example a white word on white background. You can achieve this as follows:

Ouch; that's a pretty nasty kind of hack --- clever, mind you! --- and it only works for an image as output.


\lstset{backgroundcolor=\color{white},frame=single,emph={EMPTY},emphsty le=\color{white},}


print ``Hello World!''
print ``Done''

Note that the DVI output of this looks ugly (black boxes) but the PS
is okay (that is because the color-package does color using post
script commands so it is not expected to work for the dvi files).

Note also that the backgroundcolor for the listings environment has to
be set: listings seems to be quite clever and changes the background
to gray if you try to print something in white.

If anyone comes along a decent fix for this problem, please let me know.

The big question is "what do you want to see in the HTML?" an image, or preformatted text (i.e. <PRE> .... </PRE> tags?

Hope this helps,




------------------------------------------------------------------------ Ross Moore [EMAIL PROTECTED] Mathematics Department office: E7A-419 Macquarie University tel: +61 +2 9850 8955 Sydney, Australia fax: +61 +2 9850 8114 ------------------------------------------------------------------------

latex2html mailing list

Reply via email to