[l2h] latex2html

Ross Moore ross@ics.mq.edu.au
Thu, 13 Sep 2001 09:41:56 +1000 (EST)


> Hi,
> 
> I have a lot of problems with latex2html. We moved from SuSe Linux 6.2
> (latex2html 98.1p7) to SuSe Linux 7.1 (latex2html 99beta8). Meanwhile 
> we upgraded latex2html to 2K.1 beta (1.55) from CTAN.
 

After looking at the rest of your message, and the example coding,
it appears to me that you are using macros  \latex  and  \html
to selectively choose large amounts of material, according to whether
the processor is LaTeX or LaTeX2HTML.

This is *not* a good idea.
Instead, you should be using conditional environments:

 \begin{htmlonly}
  ....
 \end{htmlonly}

 \begin{latexonly}
  ...
 \end{latexonly}

and wherever possible, use conditional comments:
 %begin{latexonly}
  ....
 %end{latexonly}

The \html, \latex and \latexhtml  commands should *only* be used
as shorthand macros/commands for conditional coding when the
contents are not complicated; e.g. slight rewordings according
to the output format.


Technically, it is question about the order of expansion of 
environments and macros.
Whereas (TeX-based) LaTeX processes a single stream of tokens,
making macro-expansions and executing commands (executable tokens)
in the order in which the tokens arrive, this is *not* the way
it works with LaTeX2HTML.

Instead, LaTeX2HTML works in a more *inside-out* fashion.
It processes environments as a whole, placing the correctly nested
HTML tags around the result. Within an environment, it processes
sub-environments before individual commands.

Thus with coding:

\begin{center}
 \latex{Here is a picture.}
 \html{There is no picture.}
 \latex{\begin{figure}\includegraphics{mypic}\end{picture}}
\end{center}

you will get the correct message: "no picture" for HTML.
However, the {figure} environment is still processed.
The effect of the \latex command is to discard the HTML code resulting
from that processing.
The complete processing itself *is* still done.
This probably explains the kind of "Cannot find file" messages that you
encountered, since you didn't want that image to be processed for HTML.

> - graphics
> 	latex2html complains that a lot graphics (included with
> 	\includegraphics) are not available:
> 
> 	Error while converting image
> 
> 	Error: Cannot read 'exercises_x4htmlimg83.gif': Datei oder Verzeichnis
> 	nicht gefunden
> 	Converting image #56
> 	pstoimg: Error: Cannot find file "/tmp/l2h6959/image056.ps": Datei oder
> 	Verzeichnis nicht gefunden
>  

Better coding would have been:

\begin{center}
 \latex{Here is a picture.}
 \html{There is no picture.}
%begin{latexonly}
 \begin{figure}\includegraphics{mypic}\end{picture}
%end{latexonly}
\end{center}

This is better, because the contents of the  %begin{latexonly}
comments is discarded *at the very beginning* of the LaTeX2HTML job.
It is *not* retained (in memory, or on disk) as part of the processing
of the surrounding {center} environment.


Note that LaTeX2HTML's expansion model means that it must retain large
strings in memory, which it scans for familiar LaTeX-like constructions.
Thus it is a good idea to clearly mark those parts of your document
source which are not needed, so they can be identified early and discarded.

This is the primary purpose of the %begin{latexonly} ... %end{latexonly}
comments.
You should avoid having such conditional coding and environments
as part of the expansion of macro definitions...

  ...not because it won't work, but because it is less efficient,
and can cause extra processing to no effect.


> A lot of documents which worked under 98.1p7 do not work under the 99-
> or 2K-version anymore. We have experienced several problems:
 

> 	A colleauge of mine found a solution to this problem, if I delete all
> 	\latex{...} commands from my document then it runs without problems
> 	under 2K.1. But of course i do not want to do this.
> 
> 	I also get the following:
> 
> 	Unknown commands: begin item

If these occured inside \latex commands, 
or if you tried to use code such as:

 \latex{\begin{itemize}\item}
 ...
 ...
 \latex{\end{itemize}}

then this might well occur.

 
> - LaTeX macros
> 
> 	We have a large set a LaTeX Macros and some do not work anymore as
> 	expected, e.g.
> 
> 	\newcommand{\glref}[3]{%
> 	\label{#2}
> 	\html{
> 	\begin{rawhtml}
> 	<!----- LINKFORWARD
> 	Lecture
> 	@
> 	\end{rawhtml}
> 	\glreftitle
> 	\begin{rawhtml}
> 	@
> 	0
> 	@
> 	-
> 	@
> 	0
> 	@
> 	\end{rawhtml}
> 	#3
> 	\begin{rawhtml}
> 	@
> 	-
> 	@
> 	lecturelink
> 	@
> 	\end{rawhtml}
> 	#1
> 	\begin{rawhtml}
> 	@
> 	\end{rawhtml}
> 	\htmlref{#1}{#3}
> 	\begin{rawhtml}
> 	LINKFORWARD ----->
> 	\end{rawhtml}
> 	}\ \\[2mm]}
> 
> 	It works well with 98.1p7, but under 99- or 2K-version I get 
> 	instead of @ a lot of garbage there. And again I noticed that 
> 	under unknown commands appears 'begin'.

This might work better using \begin{htmlonly}...\end{htmlonly} inside
the definition. However, a better approach is to make the definition 
itself be conditional; e.g.

%%%
%%% macro definitions, for use in LaTeX only
%%%
%begin{latexonly}
 \newcommand{\glref}[3]{\label{#2}\ \\[2mm]}
  ...
  ...  other such LaTeX-only definitions
  ...
%end{latexonly}

%%%
%%% macro definitions, HTML version for use with LaTeX2HTML
%%%
\begin{htmlonly}
 \newcommand{\glref}[3]{\label{#2}%
  \begin{rawhtml}
   ....
   ....
   ...  etc ...
 \ \\[2mm]}
  ...
  ...  other such HTML-only definitions
  ...
\end{htmlonly}


Another good approach is to read macro definitions from a separate file.
Use different files for the LaTeX and HTML versions:

%begin{latexonly}
 \input myLaTeXdefs.tex
%end{latexonly}
\begin{htmlonly}
 \input myHTMLdefs.tex
\end{htmlonly}


> Anything I could do ??? I also would like to understand why I get
> "Unkown commands" and how can I figure out where it comes from and 
> how I can repair it.

Basically, you need to understand the HTML structure of how your
document should look, and make your macros definitions so that
this structure is preserved in your markup commands.
Also, use the *conditional code* structures provided by LaTeX2HTML
(via the  html.sty  package) in a better way, so as to minimize
the code that LaTeX2HTML needs to look at.


> Thanks for any help

Hope this helps,

	Ross Moore


> 	Sigbert Klinke
> _______________________________________________
> latex2html mailing list
> latex2html@tug.org
> http://tug.org/mailman/listinfo/latex2html