Some text you want to go only to TeX. Other text you want to go only to HTML. For such purposes, use the directives
\texonly ... for TeX only ... \endtexonly
and
\htmlonly ... for HTML only ... \endhtmlonly
The \texonly
and \htmlonly
directives are
defined in the macro file tex2page.tex
. Thus, you
must have your document \input
tex2page.tex
before you can use these
directives. If not, running the document through
TeX will produce errors of undefinition.
If you don't want to load the macros of
tex2page.tex
and would yet like to distinguish
between TeX-only and HTML-only text in your document,
you can exploit the fact that certain TeX control
sequences such as \shipout
have no definition
in TeX2page. Thus, the conditional
\ifx\shipout\undefined ... for HTML only ... \else ... for TeX only ... \fi
produces differing text in the DVI and HTML
output, without the need for tex2page.tex
.
\htmlonly
and \texonly
are more robust than
using conditionals such as \ifx\shipout
. If you
must use the latter approach, make sure that the
``then'' branch constitutes the HTML-only portion.
This is because any verbatim occurrence of \else
,
\fi
, or \if...
commands in the TeX-only portion
(to be sure, not a common situation) may cause TeX2page
to misread where the ``then'' branch ends and the
``else'' branch begins. (In general, you need to be
careful with \if...
nesting in TeX too [23, ch 20,
p 211], not just for TeX2page.)
Note that the text inside the HTML-only
portion is in TeX format. To specify some
of this text as raw HTML, enclose it in
\rawhtml
...
\endrawhtml
.
\htmlonly ... \rawhtml raw HTML text \endrawhtml ... \endhtmlonly
The \rawhtml
environment can
occur only within an HTML-only text
(whether described by \htmlonly
or
via \ifx\shipout
.)
The directives are used as follows: In cases where
the print and web content must differ, use
\texonly
and \htmlonly
. In cases
where the web content must use raw HTML features,
use \rawhtml
.
Use of these directives may seem to miss the point of
TeX2page. \texonly
and \htmlonly
violate the
principle of avoiding writing two documents, one
for HTML, the other for TeX. \rawhtml
violates the
principle of avoiding writing raw HTML at all.
\rawhtml
in particular is dangerous because it voids
the guarantee that the output pages will be valid HTML.
Nevertheless, these directives are often useful, as the
following examples show.
Many TeX macros, while crucial for printed copy,
are irrelevant to HTML, eg, the statement
\parindent=10pt
. Such macros are best
enclosed in a \texonly
, to avoid erroneous or
fruitless translation by TeX2page.14
The \evalsto
command we saw above (sec
5.1) was rather shabby. A better
alternative would be to exploit TeX's math
symbols, ie,
\def\evalsto{\leavevmode\hbox{$\Rightarrow$}}
or, better still (section 7.6),
\imgdef\evalsto{\leavevmode\hbox{$\Rightarrow$}}
which avoids generating a separate image file for each use
of \evalsto
.
While this will work, using an image for this token is probably overkill for your HTML output. So let's make this definition TeX-only:
\texonly \def\evalsto{\leavevmode\hbox{$\Rightarrow$}} \endtexonly
Now, the DVI version typesets as expected, but
the HTML verbatim has no access to any definition for
\evalsto
. In such situations, TeX2page will
use the name of the command. Thus, given
\scm{ (cons 1 2) |evalsto (1 . 2) }
the HTML output will be
(cons 1 2) (1 . 2)
Obviously, this is no improvement over our previous
\evalsto
definition. While we do not want the
full-fledged TeX definition, we do want some sort of
``poor man's equivalent'', eg,
\htmlonly \def\evalsto{\p{=>}} \endhtmlonly
With these definitions in place, the verbatim will now translate, in HTML, to
(cons 1 2) => (1 . 2)
While we may have relinquished TeX's niceties for our HTML
version of \evalsto
, we can certainly seek to compensate
by using HTML's own niceties. \rawhtml
comes in handy
for this:
\htmlonly \def\evalsto{\rawhtml<font color=blue><b>=></b></font>\endrawhtml} \endhtmlonly
The \evalsto
token now has a higher contrast against the
surrounding code.
(cons 1 2) => (1 . 2)
14 Actually,
\parindent
and other common print-specific
statements are automatically recognized as irrelevant for the Web
by TeX2page without the need
for an explicit \texonly
.