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

2004-10-25 Thread Hans Fangohr
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


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

2004-10-24 Thread Ross Moore
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
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'.
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
*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,
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/
/g;
  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.
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\lstset{backgroundcolor=\color{white},frame=single,emph={EMPTY},emphsty 
le=\color{white},}

\begin{document}
\begin{lstlisting}
print ``Hello World!''
EMPTY
print ``Done''
\end{lstlisting}
\end{document}

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

Thanks,
Hans

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
[EMAIL PROTECTED]
http://tug.org/mailman/listinfo/latex2html


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

2004-10-22 Thread Hans Fangohr
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.)
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:
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\lstset{backgroundcolor=\color{white},frame=single,emph={EMPTY},emphstyle=\color{white},}
\begin{document}
\begin{lstlisting}
print ``Hello World!''
EMPTY
print ``Done''
\end{lstlisting}
\end{document}

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.
Thanks,
Hans

On Thu, 21 Oct 2004, Hans Fangohr wrote:
Dear all,
I am trying to use html2latex on this document:
%--
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[frame=single]
print Hello World
print Done
\end{lstlisting}
\end{document}
%--
The graphical output (embedded in the html page) for the lstlisting
environment reads
print Hello World
\par
print Done
All is working great APART from that I get this \par for every empty
line in the listings environment.
I have scanned the archives but couldn't find any answer (although the
problem was reported in a more complicated context before:
http://www.tug.org/pipermail/latex2html/2002-October/002106.html)
Many thanks for your help,
Hans

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