The companion Perl script, tex_to_html.pl
, can be used to produce
a collection of html files, one per chapter and one per section, to
present the book on the web. The script works primarily by doing
pattern matching in the $\TeX$ source files and translating to
html. This is not particularly robust, so that more-or-less equivalent
$\TeX$ source will not always provide good html output, and perfectly
reasonable book sources may not render properly if they go beyond what
the script knows about.
Many $\TeX$ macros are simply ignored by the script; if you use a macro
that the script doesn't know how to translate and doesn't know to
ignore, it will probably show up as the literal macro name in the
output. If it should be ignored, you can wrap it in a texonly
environment:
\texonly
\unknownmacro...
\endtexonly
There is a similar \htmlonly
…endhtmlonly
environment;
the contents will be ignored by $\TeX$ but processed by
tex_to_html.pl
. This is very useful for providing html versions
of figures, which may, for example, be interactive figures.
The script includes support for JSXGraph, three.js, and Sagecells in
the html files it produces. A variety of Javascript and CSS files are needed
for support.
The script assumes the book is produced in accord with the format
described here, but in addition, certain guidelines must be
followed. The chapter files must be named chapterxx.tex
, where
xx
is the chapter number, and likewise section files are
sectionxx.tex
. The main $\TeX$ file must include a sequence of
lines like \input chapterxx
. Each chapter file must include
optionally some introductory material, and then a sequence of lines
like \input sectionxx
. Subsections are to be contained within the
section files.
If the main file contains \input preface
before \input
chapter01
it will be translated as if it were a chapter, and appear
before chapter 1.
Other $\TeX$ files, like appendices, are ignored. These can
be inserted by telling tex_to_html.pl
that they are chapters, as
described below.
The script is invoked as
tex_to_html.pl mainfile.tex output_directory
For my books, I have a subdirectory of the main book directory called
html
, which contains soft links to all the needed $\TeX$ files, at
least the main file and the chapter and section files. Then I invoke
the script as
tex_to_html.pl html/mainfile.tex output_directory
The script assumes that there is a subdirectory called
html_figures
(so in my case this would be a subdirectory of
html
) containing html code that will be incorporated into the
output verbatim; this is primarily used to include figures.
The script also assumes that there is a file called
front_page.html
which will be the first page in the book. This
might contain copyright and contact information, for example.
To include an appendix you must make it appear to the script to be a
chapter. First, create a pointer from the html
subdirectory to
the appendix $\TeX$ file, but name the link chapterxx.tex
, where
of course xx
is one larger than the last chapter of the book.
Then in the main $\TeX$ file, include this where the appendix file was
input:
\htmlonly
\input chapterxx
\endhtmlonly
You will also presumably need to modify appendix.tex to include something like
\texonly
\appendix{Appendix Title}
\endtexonly
\htmlonly
\chapter{Appendix Title}{}
\endhtmlonly
Then the macro \appendix{Appendix Title}
will only be processed
by $\TeX$ and \chapter{Appendix Title}{}
will only be processed by
tex_to_html.pl
.
The script was originally written to process an open source calculus book, which comes in multiple flavors: single variable or multivariable, early transcendentals or late transcendentals. The script also knows about these; the default is to produce the multivariable, early transcendentals version. This can be changed at the command line:
tex_to_html.pl -s
will produce the single variable version, and
tex_to_html.pl -l
will produce the late transcendentals version. Both switches may be given. The versions are identified in the $\TeX$ source using something like this:
\iflatetranscendentals
...
\elselatetranscendentals
...
\filatetranscendentals
and
\ifmultivariable
...
\elsemultivariable
...
\fimultivariable
These macros are not included in bookmacros.tex
; they are
in calcmacros.tex
in the source for the calculus
book. These could be repurposed for processing any variants of a book,
although it would make more sense to use different names for the
macros, and then to alter the script to match.
The html pages will include a search box, which uses Google to do the
searching. For this to work properly, you will need to provide the
correct search path for the document in a file called
search_path.txt
in the directory containing the html input files;
in my case, this is in the subdirectory called html
. The file
should consist of a single line giving the site url, something like
www.whitman.edu/mathematics/book_macros/
.