In many situations you want to achieve slightly (or maybe even drastically) different behavior of the LaTeX code and the HTML-output. Hyperlatex offers several different ways of letting your document depend on the mode.
\texonly
or \htmlonly command. They ignore their argument, if in the
wrong mode, and otherwise simply expand it:
We are now in \texonly{\LaTeX}\htmlonly{HTML}-mode.
In cases such as this you can simplify the notation by using the
\texorhtml command, which has two arguments:
We are now in \texorhtml{\LaTeX}{HTML}-mode.
Another possibility is by prefixing a line with \T or
\W. \T acts like a comment in HTML-mode, and as a noop
in LaTeX-mode, and for \W it is the other way round:
We are now in \T \LaTeX-mode. \W HTML-mode.
The last way of achieving this effect is useful when there are large
chunks of text that you want to skip in one mode--a HTML-document
might skip a section with a detailed mathematical analysis, a
LaTeX-document will not contain a node with lots of hyperlinks to
other documents. This can be done using the iftex and
ifhtml environments:
We are now in
\begin{iftex}
\LaTeX-mode.
\end{iftex}
\begin{ifhtml}
HTML-mode.
\end{ifhtml}
In LaTeX, commands that are defined inside an enviroment are
"forgotten" at the end of the environment. So LaTeX commands
defined inside a iftex environment are defined, but then
immediately forgotten by LaTeX.
A simple trick to avoid this problem is to use the following idiom:
\W\begin{iftex}
... command definitions
\W\end{iftex}
Now the command definitions are correctly made in the Latex, but not in the Html version.
Instead of the iftex environment, you can
also use the tex environment. It is different from iftex only if
you have used \NotSpecial in the preamble.
The environment latexonly has been provided as a service to
latex2html users. Its effect is the same as iftex.
comment environment is ignored.
You can also have sections of your document that are included depending on the setting of a flag:
A flag is simply the name of a TeX command. A flag is considered set if the command is defined and its expansion is neither empty nor the single character "0" (zero).\begin{ifset}{flag} Flag flag is set!\end{ifset}\begin{ifclear}{flag} Flag flag is not set!\end{ifset}
You could for instance select in the preamble which parts of a document you want included (in this example, parts A and D are included in the processed document):
\newcommand{\IncludePartA}{1}
\newcommand{\IncludePartB}{0}
\newcommand{\IncludePartC}{0}
\newcommand{\IncludePartD}{1}
...
\begin{ifset}{IncludePartA}
Text of part A
\end{ifset}
...
\begin{ifset}{IncludePartB}
Text of part B
\end{ifset}
...
\begin{ifset}{IncludePartC}
Text of part C
\end{ifset}
...
\begin{ifset}{IncludePartD}
Text of part D
\end{ifset}
...
Note that it is permitted to redefine a flag (using \renewcommand)
in the document. That is particularly useful if you use these
environments in a macro.