up

## Calling Commands

∙ From LaTeX to HTML ∙ Available Values for the Options ∙ XHTML and Unicode ∙ XHTML with MathML ∙ OpenOffice and MS Word ∙ DocBook and TEI ∙ JavaHelp ∙ Private Conﬁguration Files ∙ An Insight into the Commands ∙ A Deeper Insight ∙ TeX, ConTeXt, and TeXi ∙ Validation ∙ Recommendations

## From LaTeX to HTML

The translation of a LaTeX source ﬁle into HTML involves of loading tex4ht.sty and *.4ht style ﬁles, choosing the desirable options for the translation, compiling the source into dvi code with the native LaTeX engine, and postprocessing the outcome with the tex4ht and t4ht programs (see overview).

The htlatex command loads a script which takes on itself to invoke the different steps of the process, without user intervention. The command assumes the form

htlatex filename "options1" "option2" "options3" "options4"

where the ﬁrst set of options is for the tex4ht.sty and *.4ht style ﬁles, the second set is for the tex4ht postprocessor, the third for the t4ht postprocessor, and the last one is for the LaTeX compiler. For instance,

htlatex filename
  This command requests a translation according to the default conditions, which are set to produce HTML transitional 4.0 code.
htlatex filename "html,2,info"
  This command is equivalent to the previous one, specifying explicitly the option html for tex4ht.sty instead of doing so implicitly.

  In addition, the command requests a break up of the output into separate web pages, in accordance to the two top sectioning levels of the document.

  Moreover, it asks for a listing in the log ﬁle of the information available for the style ﬁles in use. That information, among other things, also introduces additional values available for the ﬁrst list of options.

htlatex filename "" "dbcs/!"
  This command requests the loading of the dbcs branch of Chinese hypertext fonts (on top of those already requested by the default setting).
htlatex filename "foo,frames" "" "-p"
  This command requests LaTeX to load a private conﬁguration ﬁle, named foo.cfg, and to place the content and table of contents in separate frames. In addition, it asks t4ht not to produce bitmaps for pictures.
htlatex filename "" " -ciso2htf" "" "-translate-file=il2-pl"
  This command invokes the LaTeX compiler with the instruction ‘latex -translate-file=il2-plfilename’.

## Available Values for the Options

The ﬁelds of option1 should be separated by commas. An ‘info’ ﬁeld requests a listing in the .log ﬁle of many of the the available values. If the list is not empty, it must start with the entry ‘html’, ‘xhtml’, or a name of a private conﬁguration ﬁle.

The ﬁelds of option2 and options3 should be separated by spaces. The available values can be listed by executing the postprocessors tex4ht.c and t4ht.c, respectively, without arguments (or with wrong sets of arguments).

The ﬁrst ﬁeld of option2 should be empty or a subdirectory of ht-fonts (typically augmented with an exclamation mark ‘!’). A space should separate the ﬁrst ﬁeld from the second one, also when the ﬁrst ﬁeld is empty.

The underlying output formats of available htlatex-like commands are tailored into the commands through ﬁelds of option1. The names of these ﬁelds are deﬁned in tex4ht.4ht and tex4ht.usr (see General Conﬁguration Files). These values should be of little interest to most users.

Different variants of the htlatex command may be invoked by introducing the commands as arguments to a driver named mk4ht. When provided without arguments, the driver lists the commands it recognizes.

mk4ht mzlatex filename "html,3" | (htlatex filename "html,3,xhtml,mozilla" " -cmozhtf")
mk4ht oolatex filename | (htlatex filename "xhtml,ooffice" "ooffice/! -coo")

Alternatively, a compilation ‘latex mkht-scripts.4ht’ produces different named scripts of similar functionality.

## XHTML and Unicode

The ‘xhlatex’ command is a variant of the ‘htlatex’ command requesting XHTML output. It consists just of a call to ‘htlatex’ with the entry ‘xhtml’ in the ﬁrst list of options and ‘-cvalidate’ in the third list. For instance, ‘xhlatex filename’ or ‘htlatex filename "xhtml"’.

To request a Unicode representation of symbols, the ﬁrst list of options should include the ‘uni-html4’ entry, and the second list should include the ‘-cunihtf’ entry preceded by space. For instance, ‘xhlatex filename "xhtml,uni-html4" " -cunihtf"’.

Unicode representations of symbols in UTF-8 encoding may be requested with the entry ‘-utf8’ added to the second list. For instance, ‘xhlatex filename "xhtml,uni-html4" " -cunihtf -utf8"’.

## XHTML with MathML

TeX4ht has different conﬁgurations for different modes of output. It is distributed with pre-tailored base conﬁgurations for translating LaTeX math into MathML, and extra conﬁgurations for adjusting the outcome to Mozilla, MathPlayer, and PMathML CSS. Only presentational MathML is supported.

mzlatex filename
mzlatex filename "html,pmathml"
mzlatex filename "html,mathplayer"
mzlatex filename "html,mathml-"
xhmlatex filename

The mzlatex command is a short cut representation for the command ‘htlatex filename "xhtml,mozilla" " -cmozhtf" "-cvalidate"’. It take into account special needs of browsers. The xhmlatex command is a short cut representation for the command ‘htlatex filename "xhtml,mathml" " -cunihtf" "-cvalidate"’; it does not make any compromizes toward browsers.

It might be worthwhile to notice some of the more common sources of problems for MathML. The ‘mathml-’ options asks for a degraded MathML output that sidetracks some of the problems.

## OpenOffice and MS Word

A translation for an OpenOffice format can be requested by the ‘\oolatex’ command. The command is a variant of htlatex in which the ﬁrst list of options holds the entries ‘xhtml,ooffice’, the second list holds the entry ‘-cmozhtf’ preceded by a space, and the third list contains ‘-coo’ (htlatex filename "xhtml,ooffice" "ooffice/! -cmozhtf" "-coo" "-cvalidate"). The output of a command ‘oolatex filename’ is a zipped ﬁle named with a ‘.sxw’ extension.

The OpenOffice code employs MathML for formulas, and XSL-FO for formatting. It can be viewed by the OpenOffice word processor which, in turn, can export RTF and other MicroSoft-based formats (see also, Maarten Wisse, “Hacking TeX4ht for XML Output: The Road toward a TeX to Word Convertor”, MAPS 28 (2002), pp. 28-35).

A command of the form ‘htlatex filename "html,word" "symbol/!" "-cvalidate"’ asks for HTML output tuned toward MicroSoft Word. Such a format, however, relies on bitmaps for mathematical formulas.

## DocBook and TEI

The following commands may be used for requesting DocBook and TEI output.

dbmlatex: | htlatex ﬁlename "xhtml,docbook-mml" " -cunihtf"
dblatex: | htlatex ﬁlename "xhtml,docbook" " -cunihtf"
teimlatex: | htlatex ﬁlename "xhtml,tei-mml" " -cunihtf"
teilatex: | htlatex ﬁlename "xhtml,tei" " -cunihtf"

## JavaHelp

JavaHelp is an online documentation system for use by Java-based applications. Such documents can be produced from LaTeX ﬁles through commands similar to ‘htlatex ﬁlename "html,3.2,javahelp"’ or ‘htlatex ﬁlename "html,3.2,javahelp,unicode" " -cmozhtf -u10"’ (see jhsample.tex). The ‘-u10’ asks for entity references in base 10—JavaHelp doesn’t seem to support hexadecimal representations.

## Private Conﬁguration Files

The leading entry, in the ﬁrst list of options of the htlatex-like commands, can equal ‘html’ or ‘xhtml’. If this is not the case, the entry is assumed to be the name of a conﬁguration ﬁle. The extension ‘cfg’ is assumed for names of conﬁguration ﬁles that are listed without their extension.

A conﬁguration ﬁle should take the following form for LaTeX ﬁles.

...early deﬁnitions...
\Preamble{options}
...deﬁnitions...
\begin{document}
...insertions into the header of the html ﬁle...
\EndPreamble

It is up to the user to decide the distribution of entries between the \Preamble and the htlatex-like commands.

Example The command ‘htlatex myfile "mycfg,2"’ requests the compilation of a ﬁle named myﬁle.tex, in the presence of a conﬁguration ﬁle named mycfg.cfg. The conﬁguration ﬁle might have the following content.
\Preamble{html}
\begin{document}
\Css{body { color : red; }}
\EndPreamble
Notes

- Notice that for a LaTeX ﬁle the \begin{document} instruction should be present both in the conﬁguration ﬁle and the source ﬁle.

- Instructions deﬁned within a source ﬁle may be redeﬁned in a conﬁguration ﬁle. Such a feature enables to keep source ﬁles intact for compilation to different formats by different tools.

  For instance, a deﬁnition of the form \renewcommand\mycommand{...} within a conﬁguration ﬁle provided for the following LaTeX source.

  \documentclass{...}
  \newcommand\mycommand{...}
  \begin{document}
  Use \mycommand{...}
  \end{document}

## An Insight into the Commands

Given a LaTeX ﬁle

\documentclass{article}
\begin{document}
..................
\end{document}

the ‘htlatex ﬁlename’ command produces a call ‘latex ﬁlename’ to LaTeX on an implicit ﬁle of the following form.

\documentclass{article}
\usepackage{tex4ht}
\begin{document}
..................
\end{document}

Similarly, the command ‘htlatex ﬁlename "options"’ produces a call to a ‘latex ﬁlename’ command on an implicit ﬁle of the following form.

\documentclass{article}
\usepackage[options]{tex4ht}
\begin{document}
..................
\end{document}
The command ‘ht latex ﬁlename ’ may be used, instead of the ‘htlatex ﬁlename "options"’ command, in cases that the \usepackage instruction is explicitly introduced into the source ﬁles.

## A Deeper Insight

From the perspective of TeX4ht, the htlatex-like commands, and the \usepackage, are indirect approaches for getting LaTeX ﬁles of the following form. Such ﬁles can be explicitly provided for compilations requested through the ‘ht latex ﬁlename’ command.

\documentclass{article}
.....
\input tex4ht.sty
.....
\Preamble{options}
.....
\begin{document}
.....
\EndPreamble
..................
\end{document}

## TeX, ConTeXt, and TeXi

Commands similar to those offered for LaTeX are also offered for TeX (dbmtex, dbtex, ht, httex, mztex, ootex, t4ht, teimtex, teitex, tex4ht, xhmtex, xhtex) and TeXi (dbmtexi, dbtexi, httexi, mztexi, ootexi, teimtexi, teitexi, xhmtexi, xhtexi). In the case of TeX, the fragment of code ‘\csname tex4ht\endcsname’ should be introduced into the source ﬁle, after the preamble of the ﬁle where the document deﬁnitions reside (example). In the case of TeXi, such a code fragment is introduced implicitly.

The private conﬁguration ﬁles are similar to those of LaTeX, with the instruction ‘\begin{document}’ excluded.

...
\Preamble{options}
...
\begin{document}
...
\EndPreamble
...
The ‘ht tex ﬁlename ’ and ‘ht texi ﬁlename ’ commands may apply for TeX and TeXi sources that embed such code fragments in their body. The embeded code should replace the ‘\csname tex4ht\endcsname’ fragment in TeX sources, be palces at the strat of the ﬁles in TeXi sources, and not include the \begin{document} instruction.

For ConTeXt similar instructions apply with suffixes ‘context’ instead of ‘latex’, ‘tex’, or ‘texi’. For instance, ‘htcontext’ .

## Validation

The outcome of the translations should be checked by validators for proper syntax. Typically, with the presence of validators, errors are easy to detect and correct, but they require human intervention.

TeX4ht doesn’t offer a built-in parser to verify the correctness of the outcome. However, external validator(s) can quite easily be integrated into the compilation process.

## Recommendations

To keep with the spirit of LaTeX and hypertext, in which style is assumed to be separated from content, the users are encouraged to avoid inserting TeX4ht code into their source ﬁles. Instead, they should place their modiﬁcations, to the default settings, within private conﬁguration ﬁles to be loaded by htlatex-like commands.

On the other hand, it should be noted that hypertext markings should adhere to strict rules speciﬁed by different standards. Consequently, it is strongly advised to check the output obtained from the default conﬁgurations, before trying to tailor new ones.