3  TeX2page commands

The previous chapter explained how a document that is acceptable to TeX​ ​may contain several commands that TeX2page does not inherently understand and for which suitable HTML-only definitions must be provided. The reverse problem also obtains: A document that is processed successfully by TeX2page may contain commands that plain TeX​ ​and LaTeX​ ​may not recognize.

As we have seen, TeX2page recognizes a mix of plain-TeX​ ​and LaTeX commands, and commands from external macro files besides. Thus, a plain TeX​ ​document could very well use LaTeX commands and pass through TeX2page without hitch. When running plain TeX​ ​on the document, of course, the LaTeX commands will fail, unless TeX-only definitions for the missing commands are provided. Examples of common LaTeX commands recognized by TeX2page include the commands for title, chapters and sections, footnotes, labels for cross-referencing, table of contents, verbatim text, itemizations, enumerations, index, and bibliography.

It is also possible that the document uses commands from external macro files without actually loading said files. TeX2page will be indulgent, but plain TeX​ ​and LaTeX​ ​won’t. In this case, simply loading the macro files should be enough. Thus, a plain TeX​ ​document using the \cite command should load btxmac.tex, and a LaTeX​ ​document that uses the \color and \definecolor commands should load the package color.sty.

A plain TeX​ ​document using macros provided by a LaTeX package may also be able to load the package in some cases, with the aid of the miniltx.tex macro file. To load color.sty, for instance:

\expandafter\def\csname Gin@driver\endcsname{pdftex.def}
% The above may not be needed in newer \TeX\ distributions,
% which will load the appropriate driver automatically.
% Replace pdftex.def with dvips.def if output print format
% is PostScript rather than PDF.

\input miniltx
\input color.sty

Although the above is only meant for TeX, it is not necessary (but not incorrect either) to wrap it inside \ifx\shipout\UnDeFiNeD\else ... \fi, as TeX2page knows enough to skip such loads.

Other useful LaTeX​ ​packages that can be loaded into plain TeX​ ​using miniltx are graphicx.sty and url.sty. (Unfortunately, one has to say \expandafter\def\expandafter\+\expandafter{\+} before \inputting url.sty.)

It is possible to \input several .sty files between the calls to \input miniltx and \resetatcatcode. However, miniltx is a bit of a compromise, and it causes each .sty file to re-evaluate the supposedly per-document commands in the driver file (e.g., pdftex.def), which can cause infinite loops. This is avoided by preceding the loading of the second and subsequent .sty files with \let\color\@ldc@l@r. E.g.,

\input miniltx
\input color.sty
\input graphicx.sty
\input url.sty

The LaTeX​ ​package path.sty can be loaded into plain TeX​ ​directly, without miniltx.

tex2page.tex and tex2page.sty

A collection of workable TeX​ ​definitions for TeX2page commands is provided in the macro file tex2page.tex in the TeX2page distribution. These allow your document to be processed by TeX, even if they do not (and sometimes should not) have the same effect in the DVI output as they do in the HTML output. It can be included in your TeX​ ​document as

\input tex2page

The file is also available under the LaTeX-friendlier name tex2page.sty, and can be loaded into LaTeX​ ​with:

\usepackage{tex2page} % if document is in LaTeX

The macros in tex2page.tex are just sample definitions of the TeX2page commands missing in TeX. You can either choose not to use these commands or to override their definitions with your own, better, definitions.

Note that TeX2page itself does not need the file tex2page.tex. Rather, plain TeX​ ​and LaTeX​ ​need the tex2page.tex macros in order to process files written using the extra commands supported by TeX2page. If your document does not use these extra commands, then you can do without tex2page.tex.