# LaTeX HTML package - control your output

The LaTeX "html" package (html.sty) can be very useful for the times that you want to conditionally controlling the output in LaTeX documents, but very specifically, when you want one set of output for normal Latex processing (LaTeX PDF output), and another set of output for LaTeX HTML processing.

Here's a very simple example of how you can use this LaTeX HTML package to conditionally control what is output by the LaTeX processor:

\documentclass[a4paper,11pt]{article}
\author{Al Alexander}
\title{}

\usepackage{html}

\begin{document}
\maketitle
\tableofcontents

% print this output when processing by a Latex-only processor (like "pdflatex"):
\latex{This document has been processed by something like pdflatex.}

% longer latex example
\begin{latexonly}
Some more PDF text here.
Something longer than you want to include in a
simple command, something like this
multiline example.
\end{latexonly}

% when processing this doc using Latex2HTML do this:
\html{<p>This document has been processed by something like Latex2HTML.</p>}

% longer html example
\begin{htmlonly}
<pre>
Some more HTML text here.
Something longer than you want to include in a
simple command, something like this
multiline example.
</pre>
\end{htmlonly}

\end{document}

In this example the LaTeX PDF document that results when I run pdflatex has this output:

This document has been processed by something like pdflatex.
Some more PDF text here.
Something longer than you want to include in a
simple command, something like this
multiline example.

The important thing here is that the HTML output is not included here. That output will only be included if I run latex2html. This is a very powerful control mechanism that I use in several areas when creating documents that need to appear in both LaTeX PDF and LaTeX HTML formats.

The commands here are \latex and \html, and the environments are controlled by the \begin{latexonly}, \end{latexonly}, \begin{htmlonly}, and \end{htmlonly}.

If you're going to be producing HTML documents from your LaTeX source files, it's important to know that the LaTeX HTML package includes many more useful features.

tags: