# Re: [l2h] Re: getting \par in graphical output of listings environment

Hi Ross,

many thanks for your detailed answer.

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

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'
environments.

*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:

%begin{latexonly}
\lstnewenvironment{myverbatim}{}{}
%end{latexonly}

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

That is a nice idea -- I might consider that.

I'd prefer, however, latex2html to generate images as these would
represent the colourcoding of keywords in the source code that the
listings environment can do.

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.

That is not too bad as there is a command to set the listings
environment separately (\lstset{}) [and kind of globally].

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
*unknown*.

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,
Done that.

Unfortunately, there is an error message and I am not very good at
Perl. Can you see what is going on:

[EMAIL PROTECTED] sesa2006 $latex2html partestorg.tex Note: Loading /home/fangohr/.latex2html-init /home/fangohr/.latex2html-init did not return a true value at /usr/lib/latex2html/latex2html.pl line 162. Compilation failed in require at /usr/bin/latex2html line 39. where this is the content of /home/fangohr/.latex2html-init: sub do_env_lstlisting { local ($_) = @_;
my $env_id = ++$global{'max_id'};
$_ =~ s/\\par/\n\n/g; &process_undefined_environment('lstlisting',$env_id, \$_);
}

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

No probs, want to run this on Linux.

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

Correct on all accounts: ugly and works for image only.

Cheers,

Hans

_______________________________________________
latex2html mailing list
[EMAIL PROTECTED]
http://tug.org/mailman/listinfo/latex2html