The translation of a LaTeX source file into HTML involves of loading tex4ht.sty and *.4ht style files, 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
where the first set of options is for the tex4ht.sty and *.4ht style files, the second set is for the tex4ht postprocessor, and the third for the t4ht postprocessor. For instance,
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 file of the information available for the style files in use. That information, among other things, also introduces additional values available for the first list of options.
The fields of option1 should be separated by commas. An ‘info’ field requests a listing in the .log file 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 configuration file.
The fields 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 first field of option2 should be empty or a subdirectory of ht-fonts (typically augmented with an exclamation mark ‘!’). A space should separate the first field from the second one, also when the first field is empty.
The underlying output formats of available htlatex-like commands are tailored into the commands through fields of option1. The names of these fields are defined in tex4ht.4ht and tex4ht.usr (see General Configuration 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" " -coo") |
To request a Unicode representation of symbols, the first 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"’.
TeX4ht has different configurations for different modes of output. It is distributed with pre-tailored base configurations for translating LaTeX math into MathML, and extra configurations for adjusting the outcome to Mozilla, MathPlayer, and PMathML CSS. Only presentational MathML is supported.
The mzlatex command is a short cut representation for the command ‘htlatex filename "xhtml,mozilla" " -cmozhtf"’. It take into account special needs of browsers. The xhmlatex command is a short cut representation for the command ‘htlatex filename "xhtml,mathml" " -cunihtf"’; 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.
A translation for an OpenOffice format can be requested by the ‘\oolatex’ command. The command is a variant of htlatex in which the first 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" " -coo"). The output of a command ‘oolatex filename’ is a zipped file 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/!"’ asks for HTML output tuned toward MicroSoft Word. Such a format, however, relies on bitmaps for mathematical formulas.
The following commands may be used for requesting DocBook and TEI output.
dbmlatex: | htlatex filename "xhtml,docbook-mml" " -cunihtf" |
dblatex: | htlatex filename "xhtml,docbook" " -cunihtf" |
teimlatex: | htlatex filename "xhtml,tei-mml" " -cunihtf" |
teilatex: | htlatex filename "xhtml,tei" " -cunihtf" |
JavaHelp is an online documentation system for use by Java-based applications. Such documents can be produced from LaTeX files through commands similar to ‘htlatex filename "html,3.2,javahelp"’ (see jhsample.tex).
The leading entry, in the first 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 configuration file. The extension ‘cfg’ is assumed for names of configuration files that are listed without their extension.
A configuration file should take the following form for LaTeX files.
It is up to the user to decide the distribution of entries between the \Preamble and the htlatex-like commands.
For instance, a definition of the form \renewcommand\mycommand{...} within a configuration file provided for the following LaTeX source.
Given a LaTeX file
the ‘htlatex filename’ command produces a call ‘latex filename’ to LaTeX on an implicit file of the following form.
Similarly, the command ‘htlatex filename "options"’ produces a call to a ‘latex filename’ command on an implicit file of the following form.
From the perspective of TeX4ht, the htlatex-like commands, and the \usepackage, are indirect approaches for getting LaTeX files of the following form. Such files can be explicitly provided for compilations requested through the ‘ht latex filename’ command.
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 file, after the preamble of the file where the document definitions reside (example). In the case of TeXi, such a code fragment is introduced implicitly.
The private configuration files are similar to those of LaTeX, with the instruction ‘\begin{document}’ excluded.
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.
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 files. Instead, they should place their modifications, to the default settings, within private configuration files to be loaded by htlatex-like commands.
On the other hand, it should be noted that hypertext markings should adhere to strict rules specified by different standards. Consequently, it is strongly advised to check the output obtained from the default configurations, before trying to tailor new ones.