-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tex
3813 lines (3231 loc) · 117 KB
/
index.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% This is a plain TeX file, and can be TeX’d as usual,
% but it can also be converted into an HTML document. To do
% this latter, run
%
% tex2page index
% tex2page is available at
% http://ds26gte.github.io/tex2page/index.html
\input tex2page-doc-mac
\ifx\TZPtitle\UnDeFiNeD
\def\TZPtitle{TeX2page}\fi
\title \TeX2page
\smallskip
\c{\urlh{http://ds26gte.github.io}{Dorai Sitaram}}
%
\ifx\shipout\UnDeFiNeD
\c{Download
\urlh{https://github.com/ds26gte/tex2page}{Version \fmtversion}}
\else
\c{2023-01-01} %last change
%\ifx\shipout\UnDeFiNeD
%\c{(A copy is included in
%\urlh{http://www.plt-scheme.org}{PLT Scheme})}
\fi
%
%\medskip
\ifx\shipout\UnDeFiNeD
\centerline{\htmladdimg{t2p.png}}
\fi
{\obeylines\raggedleft
\ifx\shipout\UnDeFiNeD\small\else\eightfont\fi
{\it Making books is a skilled trade,
like making clocks.}
— Jean de la Bruyère (†1696)
}
%French original:
%“C’est un métier que de faire un livre,
%comme de faire une pendule.”
%JdlB’s lifespan: 1645–1696.
\medskip
%\index{plain TeX}
%\index{LaTeX}
\n
\TeX2page
makes Web pages
from \TeX~\cite{texbook} manuscripts.
It reads an
input document that is marked up in
plain \TeX\ or \LaTeX~\cite{latex,latex-companion}
and
produces an output document with the functionally
equivalent HTML markup.
\TeX2page uses the same input
file syntax, calling conventions, and error-recovery
mechanisms as \TeX. Thus, \TeX2page demands no additional
expertise of a user already familiar with \TeX.
\TeX2page runs on Common Lisp and modern Schemes.
%However, for the user who wants more, \TeX2page
%provides Scheme as an extension language.
There are several advantages to keeping the document
source in \TeX\ and leaving the task of converting to
HTML to \TeX2page: There is no need to write and
maintain two separate documents, one for paper and the
other for the screen. Indeed, there is no need to
learn a {\em new} input format, as \TeX2page reuses a
format already in wide and stable use for printed
documents~\cite{tug,ctan}. Creating \TeX\
source requires no special-purpose software; any text
editor will do. Furthermore, an ecology of powerful and
reliable tools such as \BibTeX~\cite{bibtex},
MakeIndex~\cite{makeindex}, and
MetaPost~\cite{metapost,mfbook} has developed around \TeX, and
its benefits can be enjoyed by \TeX2page too.
Finally, \TeX, unlike HTML, is a {\em programming}
language, which lets the composer of the document
exercise a fine control over its structure and
presentation. A converter such as \TeX2page that can
convert \TeX\ macro definitions in addition to basic \TeX\
markup enables the format converted to to also benefit
from \TeX’s extensibility. For the cases where
\TeX2page’s implementation of the \TeX\ macro system is
not manipulable enough, the document writer can use the
\TeX2page {\em extension language}, which is full Common Lisp or
Scheme
augmented with all the \TeX2page procedure definitions.
The rest of this manual is organized as follows:
\medskip
\xrdef{ToC}
\tableofcontents
\beginchapter 1 Running \TeX2page
\xrdef{usage}
\index{running \TeX2page!from system command-line}
%
\TeX2page is invoked in much the same way as \TeX.\f{Hereafter,
we will use “\TeX” to mean
any format of \TeX, and “plain \TeX” when we
specifically mean the “plain” format. We will use “Lisp” to refer
to the implementation language of the \TeX2page script under
discussion, although this can be either Common Lisp or Scheme,
with near-identical behavior. For the minor differences, see
Appendix A (p.~\ref{scheme}).}
For instance, given a plain-\TeX\ document file
\p{|meta[wherever-it-is/jobname].|meta[ext]}, which can
be either a full pathname or a pathname relative to either the
working directory or some directory in `TEXINPUTS`, where
\p{|meta[jobname]} is the {\em basename} of the file
and \p{.|meta[ext]} is its extension, you type
\begintt
tex |meta[wherever-it-is/jobname].|meta[ext]
\endtt
%
at the operating-system command line.\f{The executable `tex` expects
its input file to be marked up in plain \TeX. For a \LaTeX\ document, the
executable to use is `latex`. Modern \TeX\ engines such as
Lua\TeX~\cite{luatex}, \XeTeX~\cite{xetex}, and pdf\TeX\ have
executables named `luatex`, `xetex`, `pdftex` for the plain
format, and `lualatex`, `xelatex`, and `pdflatex` for \LaTeX.} You do not need to mention the extension
\p{.|meta[ext]} if it is `.tex`. This creates the output DVI file,
\p{|meta[jobname].dvi}, in the working directory.\f{The modern \TeX s
Lua\TeX, \XeTeX, and
pdf\TeX\ produce PDF rather than DVI. In the rest of this manual,
whenever we refer to the output DVI file, the reader using the PDF versions
of \TeX\ should read PDF for DVI.}
\index{tex2page (c@`tex2page` (command)}
\TeX2page is called analogously. To create the HTML
version of the same file
\p{|meta[wherever-it-is/jobname].|meta[ext]}, type
\begintt
tex2page |meta[wherever-it-is/jobname].|meta[ext]
\endtt
%
Again, the \p{.|meta[ext]} is optional if it is `.tex`. This
creates \p{|meta[jobname].html} in the working directory.
\index{story.tex@`story.tex`}
To try this out, call \TeX2page on the example file
\urlh{texample.html}{`story.tex`}
provided in all \TeX\ distributions:
\begintt
tex2page story
\endtt
%
\index{log file}
%
\TeX2page will get cracking\f{\TeX2page, like \TeX, will find the
file `story.tex` from your distribution as it is in your default `TEXINPUTS`.
If it’s too confusing operating on a file that you don’t see in
your immediate space, copy the file manually to your working
directory. You can find its location with `kpsewhich story`.} on `story.tex`, providing
the following commentary, or {\em log}, on your console:
\medbreak
\verbatiminput story.hlog
\medbreak
\n \TeX2page is now done, and the result of its labors
is the HTML file
\urlh{story.html}{`story.html`}\ifx\shipout\UnDeFiNeD\ (click
to see)\fi.
\index{bye@`\bye`}
\index{end@`\end`}
\index{hlog@`.hlog`|see{log file}}
\index{log file}
The {\em log file} `story.hlog`
contains a copy of the above log, and is useful
if you didn’t or couldn’t keep track of the console
(perhaps because the log was too long).
The log says that `story.tex` lacked a
document-ending command such as `\end` (or `\bye`)
and that \TeX2page assumed one anyway. Also, only
{\em one} HTML page was created, and its name is
`story.html`. \TeX2page could in some cases produce
auxiliary HTML pages in addition to
the main HTML page \p{|meta[jobname].html} (especially
for larger documents). The auxiliary HTML pages
are reachable from \p{|meta[jobname].html}
by navigation links (p.~\ref{eject}). As each
auxiliary HTML page is completed, the log will show the
bracketed numbers `[1]`, `[2]`, etc. The `[0]`
in this log refers to the only HTML file created, viz.,
`story.html`.
All this is of course almost exactly analogous to the
way you type `tex story` (or `luatex story` or `xetex story` or `pdftex story`) to get
`story.dvi` (or `story.pdf`)
from `story.tex`, with the log going into
`story.log`.
\medbreak
\verbatiminput story.log
\medbreak
\n The only real difference is
that \TeX\ will not add the missing `\end` on its
own, but instead waits for the user to supply it
explicitly from the console.\f{The file `story.tex`
lacks an `\end` only to demonstrate some interactive
capabilities of \TeX, which are not relevant for
\TeX2page.} Note that the bracketed numbers now refer
to the pages as numbered in the printed document.
Thus, from one \TeX\ source file, you can get both a printable `.dvi` and a
browsable `.html` document, using the same calling
conventions.\iffalse \f{Quite a few documents profit from
being available additionally as plain text, either as a man page, or as
tagged text on a general-purpose text editor, instead of requiring an HTML
browser. The scripts `t2p2man`,
`t2p2txt`, and `t2p2info`, included in the \TeX2page distribution,
help accomplish this.
Each of these scripts takes as argument the main HTML
file \p{|meta[jobname].html} created by \TeX2page, and generate the
corresponding man page \p{|meta[jobname].1},
the Vim help file \p{|meta[jobname].txt}, and the
Info file
\p{|meta[jobname].info}
respectively. While the man page is always a single page, the Info and
Vim-help output is composed of multiple files if the HTML document contains
pagebreaks.}\fi
%can be used to create such “low-tech” but
%easy-access hypertext that is readable on any
%tags-capable text editor.
\index{kpathsea@`kpathsea`}
\index{TEXINPUTS@`TEXINPUTS` (environment variable)}
\index{TEX2PAGEINPUTS@`TEX2PAGEINPUTS` (environment variable)}
When \TeX\ encounters a filename \p{|meta[f]}, it
searches for it
in a standard list of
directories, which can be modified by the user via the
environment variable `TEXINPUTS`.
The filename \p{|meta[f].tex} is tried before
\p{|meta[f]} itself is tried. In most modern \TeX s, the
search is performed using the `kpathsea` library.
\TeX2page also looks for files using the same `kpathsea`
mechanism as \TeX. However, it first looks at a
different list of search directories given in the environment
variable `TEX2PAGEINPUTS`.
It may be useful to have
files in `TEX2PAGEINPUTS` shadow files from
`TEXINPUTS`, because the latter are not really
HTML-specific, and can thus be unsuitable for
HTML-minded parsing by \TeX2page.
In \TeX s without the `kpathsea` library,
`TEX2PAGEINPUTS` is the only way to get \TeX2page to
automatically access files outside the working
directory. Note that `TEX2PAGEINPUTS` should be a
simple list of directory names, colon-separated in Unix
and semicolon-separated in Windows. It cannot use the
enhanced syntax (viz., `*` and `//`) that is
typically permitted for `TEXINPUTS`.
Error recovery in \TeX2page is also exactly analogous to
\TeX, but we will postpone that discussion to
p.~\ref{recovery}.
\beginsection Non-file arguments
\index{help@`--help` (command-line option)}
%
\index{version@`--version` (command-line option)}
%
Like most recent versions of \TeX, \TeX2page also
supports the standard self-identification
arguments `--help` and `--version`. These
arguments elicit help only if there isn’t an input file
(e.g., `--help.tex`) that could match them.
\TeX2page called without an argument displays a help
message and exits. Unlike \TeX, \TeX2page will not try
to conjure up an input document based purely on console
chitchat with an increasingly befuddled user.
In all these cases, the help displayed on the console
is also saved in the specially named log file
`texput.hlog`.
\beginsection Calling \TeX2page from Lisp
\index{running \TeX2page!from Common Lisp}
\index{tex2page:tex2page (Common Lisp f)@\q{tex2page:tex2page} (Common
Lisp function)}
%
If, for any reason, it is not possible to call `tex2page`
from your operating-system command line, you may load the
file `tex2page` into your Lisp
and call the
{\em procedure} \q{tex2page:tex2page} with the name of the \TeX\ file
as argument:
\begintts
(load "tex2page") ;use appropriate pathname
(tex2page:tex2page |meta[filename])
\endtt
You can call the procedure
\q{tex2page:tex2page} several times from the same Lisp
session, on the same file or on different files.
Note that we’ve used a package-qualified name, as the Common
Lisp \TeX2page is provided as a Common Lisp package \q{tex2page}
whose one exported symbol is \q{tex2page}. (But see Appendix A if
using the Scheme version of \TeX2page.)
\beginsection Specifying a target directory
%\label{hdir}
\index{hdir file@`.hdir` file}
\index{tex2page.hdir@`.tex2page.hdir` file}
%
By default, \TeX2page generates the output HTML files
and other auxiliary files (p.~\ref{auxfile}) in the
current working directory. You can tell \TeX2page
to place its output and auxiliary files in a different
directory and thus avoid cluttering up your working
directory.
The files used for specifying the target directory are:
\p{|meta[jobname].hdir} in the working directory,
`.tex2page.hdir` in the working directory, and
`.tex2page.hdir` in the user’s `HOME` directory.
The first line of the first of these files that exists
is taken to be the name of the target directory.
If none of the files exists, the current working
directory is the target directory.
For example, if `story.hdir` contains the filename
`story` as its first line, the HTML and aux files are
created in a subdirectory `story` of the
current directory.
\index{jobname@`\jobname`}
The filename may contain the \TeX\ control sequence
`\jobname`, which expands to the basename of
the \TeX\ document. To always use an auxiliary
subdirectory with the same name as the basename of the
\TeX\ document, have `~/.tex2page.hdir` contain the
line “`\jobname`” (without quotes).
\iffalse
beginsection Info files
If a \TeX2page-generated set of HTML files is largely text, it can be
read using text-based browsers such as Lynx~\cite{lynx}. However, many
people would rather view it as an Info~\cite{texinfo} document. Info files can be
browsed very rapidly in a text editor or a lightweight console browser;
allow convenient regex search across the entire document; and can
be read as plain text as they have much less markup than the
corresponding HTML.
The \TeX2page distribution includes a script `t2p2info` for converting
\TeX2page-generated HTML into Info. `t2p2info` takes as argument the
filename of the main HTML file generated by \TeX2page, e.g.,
\begintt
t2p2info jobname.html
\endtt
The result is one or more Info files, the first of them named
`jobname.info`.
\fi
\iffalse
Split following into two chapters, “\TeX\ commands”, about
commands that \TeX2page doesn’t recognize,
and
“\TeX2page commands”, about commands that \TeX\ doesn’t
recognize, without help, i.e. (The latter may simply be
because the command is from a different format. \TeX2page
recognizes both formats, but one format may not recognize
the commands of the other. Esp., plain \TeX\ won’t understand
\LaTeX\ cmds.
Perhaps “Paper and Screen” chapter can be rolled into these
two chapters. Can probably eliminate or at least
drastically shorten the chapters about
Sections, Verbatim, Cross-references, Color.
Readers of this manual and users of this program will
already know (La)TeX. It is not this manual’s job to
introduce them to what’s possible in (La)TeX.
\fi
\beginchapter 2 \TeX\ commands
%\label{texcmds}
\index{LaTeX@\LaTeX} \index{plain TeX@plain \TeX}
%
A \TeX\ document is a text file. Most of the text
represents the content of the document, but a few
characters are used specially to embed {\em markup
commands} within the text. When
the program \TeX\ is called on a \TeX\
document, it uses the markup commands in the document
to create an appropriately typeset version of the
document in a {\em DVI} file, which can then be
printed. The \TeX\ program, which
recognizes a list of primitive commands, is invariably
called with a {\em format}, which is essentially a
preloaded set of definitions of some additional
commands. The two most popular formats
are plain \TeX~\cite{texbook} and
\LaTeX~\cite{latex,latex-companion}.
%\index{texi2p.tex@`texi2p.tex` (\TeX2page macro file)}
\TeX2page understands many of the commands of
plain \TeX,
\LaTeX, Eplain~\cite{eplain}, OPmac~\cite{opmac}, and
`manmac`~\cite[app.~E]{texbook}.\f{%
%
\index{footnote@`\footnote`}
\TeX2page processes both plain \TeX\
and \LaTeX\ commands, without the need for a format file
parameter. It can even process documents written in a
mix of plain \TeX\ and \LaTeX. This is not an uncommon
scenario, with \LaTeX\ users frequently using plain \TeX\
commands, and plain \TeX\ users frequently implementing
their own version of sectioning and other commands
using the \LaTeX\ names. In the few cases where the same
command name (e.g., `\footnote`) is used in both
formats but with differing behavior, \TeX2page will
choose the correct behavior based on which format it
thinks the overall document is in. The plain \TeX\ and
\LaTeX\ document structures are sufficiently different
(as human readers can readily testify by reading just a
few opening lines) to allow this disambiguation.}
%
It
uses this understanding to convert a \TeX\ document to
its HTML version, much the same way that \TeX\ converts
the same document into its DVI version.
In addition to the usual smörgåsbord of sectioning, itemization and
enumeration macros,
\TeX2page also recognizes some commonly used commands
that are not part of the formats but
are loaded from \LaTeX\ packages (e.g.,
`color.sty`, `epsfig.sty`, `graphicx.sty`, `luamplib.sty`,
`path.sty`,
`verbatim.sty`)
or other external macro
files (e.g., `btxmac.tex`, `eplain.tex`, `opmac.tex`,
`epsf.tex`).
%With the aid of a macro file `texi2p.tex`, \TeX2page
%can also process Texinfo documents~\cite{texinfo}.
While \TeX2page recognizes many commonly used commands,
there are plenty of commands in both the format proper
and the vast arena of macro files and packages that
\TeX2page does not know. If in math mode (assuming
math is translated as text and not image
(p.~\ref{mathflag})), \TeX2page
simply types the command’s name without the leading
escape character. This is sometimes a good choice, as
in the following text (where `\sin` and `\cos` are not
explicitly recognized by \TeX2page):
\let\TZPmathtext=1
\begintt
$$\sin^2 x + \cos^2 x = 1$$
\endtt
%
This becomes
$$\sin^2 x + \cos^2 x = 1$$
%
\let\TZPmathtext=0
which is clear enough.
If in non-math mode, \TeX2page simply ignores commands
it doesn’t understand. This is also usually a good
thing, as commands like `\leavevmode`, `\/`, and
`\-` are best translated into HTML as nothing at all.
\TeX2page ignores calls to include external \LaTeX\
packages: These are files with extension `.sty` and
are loaded with `\usepackage` or `\input`. If the
commands offered by these packages are not already
recognized by \TeX2page, they will be ignored too, and
often this is not a problem. E.g., you can use a
package for generating double columns — while this is
a great
paper-saver for your printed copy, it is generally not
important for the HTML version and so is no loss if
ignored by \TeX2page.
\index{Unicode}
Modern \TeX s, e.g., \XeTeX~\cite{xetex}, allow the use of
Unicode~\cite{unicode,haralambous:fonts,korpela:unicode,unicode4} fonts,
thereby permitting a vast cornucopia of characters
\ifx\shipout\UnDeFiNeD such as
\char"950 , \char"101, \char"222e\ and \char"2388\
\fi
to be entered verbatim (i.e.,
without the aid of \TeX\ commands) in the source document. \TeX2page
follows modern practice in typesetting Unicode characters as themselves
(provided of course they haven’t been deliberately `\catcode`’d to
mean something special).
\index{char@`\char`}
In particular, \TeX2page, like \TeX,
recognizes the `\char` command, followed by a \TeX\ number $n$, as a
directive to output the character $n$ in the current font — but
\TeX2page assumes a Unicode font is meant.
You may need to use conditionals
to ensure that the same glyphs are typeset in both the HTML and the
DVI, if your \TeX\ does not use a Unicode font.
\beginsection Defining \TeX-only and HTML-only text regions
\xrdef{htmlonly}
\TeX2page will attempt gamely to process any \TeX\
definitions that you use in your document or in
external macro files without the extension `.sty`,
but it may be a good idea to have them explicitly
ignored, if these
macros that are print-specific, or if
having \TeX2page try to parse them will cause error. A way
to have \TeX2page ignore such fragments in your document
is to use
\TeX\ conditionals, and indeed to exploit the
fact that \TeX2page does not know certain \TeX\ commands
such as `\shipout`:\f{%
\index{ifdefined@`\ifdefined`}
Here, `\UnDeFiNeD` is chosen because it is
a control sequence that is (presumably) undefined. If perchance
you defined it, replace it with something else, e.g.,
`\forHTMLonly`, `\ForTheWeb`. If using a modern PDF-producing
\TeX, you can use `\ifdefined`, and thus avoid having to come up
with arbitrary undefined control sequences. Note that with
`\ifdefined\shipout` it’s the else-branch that’s HTML-only.}
\index{ifx@`\ifx`}
\index{shipout@`\shipout`}
\index{else@`\else`}
\index{fi@`\fi`}
\begintt
\ifx\shipout\UnDeFiNeD
... |meta[for HTML only] ...
\else
... |meta[for DVI only] ...
\fi
\endtt
For example, let’s say you want to have your document load the macro file
`manmac.tex`, but in a way that \TeX2page will ignore
it. Use:
\index{input@`\input`}
\begintt
\ifx\shipout\UnDeFiNeD
\else
\input manmac
\fi
\endtt
However, there will also be many commands that
you do not want ignored in the HTML. In such
cases, while you may not be able to use the print-specific
definition, you should nevertheless furnish a definition that \TeX2page
can handle. For instance, although it may be acceptable
to ignore the print-specific macros of `manmac`, the
`\bull` macro defined in `manmac` should be
translated by \TeX2page. The following is a possible
definition for \TeX2page:
\index{def@`\def`}
\begintt
\def\bull{{\bf *}}
\endtt
Of course, we want this definition to be seen only
by \TeX2page, as we don’t want to override the
original, more sophisticated `\vrule`-based definition as seen
by \TeX.
We therefore make our
definition HTML-only
using a conditional:
\begintt
\ifx\shipout\UnDeFiNeD % HTML only
\def\bull{{\bf *}}
\fi
\endtt
\index{rawhtml@`\rawhtml`}
\index{endrawhtml@`\endrawhtml`}
Note that the HTML-only text continues to use \TeX\ syntax.
To specify some of this text as {\em raw} HTML, enclose it
in `\rawhtml` `...` `\endrawhtml`. With
`\rawhtml`, we can
spruce up the
HTML-only definition of `\bull`:
\begintt
\ifx\shipout\UnDeFiNeD % HTML only
\def\bull{{\bf
\rawhtml<span style="color: hsl(0,100%,30%)">♠</span>\endrawhtml
}}
\fi
\endtt
\index{texi2p.tex@`texi2p.tex`}
\index{Texinfo}
One can put HTML-only definitions in separate files
that are loaded just like regular \TeX\ macro files.
Indeed, one such external file, `texi2p.tex`, is used
by \TeX2page to process Texinfo
documents. Texinfo~\cite{texinfo} is another \TeX\
format, and files using this format `\input texinfo`
as the first thing they do. \TeX2page takes that as a
cue to
load `texi2p.tex`, which provides \TeX2page-suitable
definitions for the Texinfo commands. `texi2p.tex`
is included in the \TeX2page distribution.
\beginsection Paper and screen
One could use HTML-only and DVI-only regions to cordon off
any text at all, not just macro definitions. E.g.,
\begintt
The paper book is
\ifx\shipout\UnDeFiNeD % HTML only
an antiquated
\else % DVI only
a time-tested
\fi
technology.
\endtt
Use of these directives may seem to miss the point of
\TeX2page. `\ifx\shipout\UnDeFiNeD` violates the
principle of avoiding writing {\em two} texts, one
for HTML, the other for DVI. `\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, especially when the
text will profit from exploiting the presentational differences between
HTML and DVI.
\beginsection The {.t2p} file
\xrdef{t2p-file}
\index{t2p file@`.t2p` file}
%
Before processing a \TeX\ document, \TeX2page will
automatically load a file
with the same basename as the \TeX\ main file but with
extension `.t2p`, {\em if} this file exists. This
is a good place to put HTML-specific definitions for
the document without making changes in the document
itself.
`.t2p` files are especially valuable when HTMLizing
legacy or third-party documents without compromising
their authenticity, integrity, and timestamp.
Note that the definitions in the `.t2p` file
are processed {\em before} the main file. But it often
makes sense to activate these definitions sometime
later. E.g., activating the `.t2p` definitions {\em
after} the preamble in a \LaTeX\ document allows you to
redefine the preamble macros in a manner that is
appropriate for HTML. Here is a technique for
accomplishing this:
\index{let@`\let`}
\index{document@`\document`}
%
\begintt
\let\PRIMdocument\document
\def\document{
... |meta[HTML-specific definitions] ...
\PRIMdocument}
\endtt
%
This code, which goes in the `.t2p` file,
redefines the `\document` command to include a
hook that loads some {\em HTML-specific definitions}.
Since the `\document` command is called right after
the preamble, the definitions introduced by the hook
will shadow the preamble macros, as intended.
Sample `.t2p` files may be found in the \TeX2page
distribution.
\beginchapter 3 \TeX2page commands
%\label{texcmds}
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`.
\xrdef{miniltx}
\index{miniltx.tex@`miniltx.tex`}
%
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:
\index{expandafter@`\expandafter`}
\index{csname@`\csname`}
\index{endcsname@`\endcsname`}
\begintt
\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
\resetatcatcode
\endtt
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 `\input`ting `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.,
\begintt
\input miniltx
\input color.sty
\let\color\@ldc@l@r
\input graphicx.sty
\let\color\@ldc@l@r
\expandafter\def\expandafter\+\expandafter{\+}
\input url.sty
\resetatcatcode
\endtt
The \LaTeX\ package `path.sty` can be
loaded into plain \TeX\ directly, without `miniltx`.
\beginsection tex2page.tex and tex2page.sty
\index{tex2page.tex@`tex2page.tex`}
\index{tex2page.sty@`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
\begintt
\input tex2page
\endtt
%
The file is also available
under the \LaTeX-friendlier name `tex2page.sty`, and can be
loaded into \LaTeX\ with:
\begintt
\usepackage{tex2page} % if document is in |LaTeX
\endtt
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.
\index{tex2page.tex@`tex2page.tex`!not using}
Note that \TeX2page itself does not {\em 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`.
\beginchapter 4 \TeX\ commands with a difference
Most \TeX\ commands, whether from the format or from
macro files, are translated into an obvious HTML
equivalent, and therefore need no further description
than what is available in the \TeX\ and \LaTeX\ manuals.
However, some commands are treated
specially. We now turn to these commands.
\beginsection Multiple pages
\xrdef{eject}
\index{page breaks, forcing good}
\index{eject@`\eject`}
\index{vfill@`\vfill`}
\index{chapter@`\chapter`}
%
Unlike \TeX, \TeX2page does not automatically split the document into
pages at regular vertical lengths.
\TeX2page will start a new HTML page only at `\chapter`
commands and at explicit page break commands such as
`\eject` or \LaTeX’s `\clearpage`. It is possible to disable
pagebreaks entirely with the `\TZPsinglepage` flag
(p.~\ref{singlepage}).
(It is advisable to place a `\vfill` before
`\eject` so the DVI document doesn’t cause the
pre-`\eject` text to increase its
interparagraph space unsightlily in order to fill
the physical page.)
Conditionals may be used to specify page breaks for
only the DVI output, or for only the HTML output.
\index{navigation bar}
By default, \TeX2page will generate a {\em navigation
bar} at the top and at the bottom of each HTML page, with
links to the {\em first}, {\em
previous}, and {\em next} page.
If the document has a table of contents or
an index, links to the pages containing these elements are
also included in the
navigation bar. The nav bar is customizable if you set the
`\TZPtexlayout` flag (p.~\ref{texlayout}).
\beginsection Table of contents
\index{table of contents}
\index{tableofcontents@`\tableofcontents`}
\index{readtocfile@`\readtocfile`}
\index{tocdepth@`\tocdepth`}
%
\TeX2page recognizes \LaTeX’s `\tableofcontents` and
Eplain’s `\readtocfile`, both of which list the table
of contents (ToC). Each section name in the ToC links to the
page on which the section occurs. In \LaTeX, the ToC
lists the numbered section names in the document, upto
the depth specified by the count `\tocdepth`.
\index{writenumberedtocline@`\writenumberedtocline`}
\index{addcontentsline@`\addcontentsline`}
%
In formats other than \LaTeX, the user would have to
define section commands that explicitly wrote to the
ToC. A helper macro for this is
`\writenumberedtocline`, whose three arguments are
the section’s depth, number, and heading, all of which
can be empty (`{}`). Your \TeX\ format may have its
own macro for writing lines into the ToC
(`\writenumberedtocline` is the Eplain name for this
macro). \TeX2page also understands \LaTeX’s
`\addcontentsline`. For other formats, if you intend
to use their explicit ToC addition macro, you will need
to furnish an HTML-only definition for it in terms of
`\writenumberedtocline`.
\beginsection Footnotes
\index{footnotes}
\index{footnote@`\footnote`}
\index{vfootnote@`\vfootnote`}
\index{numberedfootnote@`\numberedfootnote`}
Both unnumbered and numbered footnotes — plain \TeX’s
`\footnote` and `\vfootnote`,
LaTeX’s `\footnote`, Eplain’s
`\numberedfootnote` — are recognized.
They are translated as in DVI (modulo what constitutes
a page), but additionally, the footnote mark in the text body
is a link to the footnote mark in the footnote text,
and vice versa. Here is an example
footnote.\f{Footnotes are separated from the body of
the page by a horizontal rule.}
Since Plain \TeX\ does not provide an automatically
numbering footnote macro, users can define their own as
follows:
\begintt
\newcount\footnotenumber
\def\numberedfootnote{%
\global\advance\footnotenumber by 1
\footnote{$^{\the\footnotenumber}$}}
\endtt
%
This definition could be made \TeX-only, since
\TeX2page already recognizes `\numberedfootnote`.
However, the \TeX\ programming in this definition is
recognized by \TeX2page, so it does not matter if it
overrides \TeX2page’s internal definition.
Indeed, one could define a
more complicated macro such as the following
`\sfootnote`, which
produces symbolic rather than
numeric footnote marks, cycling through a set of
nine symbols:
\index{newcount@`\newcount`}
\index{def@`\def`}
\index{ifcase@`\ifcase`}
\index{or@`\or`}
\index{fi@`\fi`}
\index{global@`\global`}
\index{advance@`\advance`}
\index{ifnum@`\ifnum`}
\index{the@`\the`}
\begintt
\def\fnsymbol#1{%
% #1 is between 1 and 9 inclusive
\ifcase#1\or
*\or\dag\or\ddag\or\S\or\P\or
$\Vert$\or**\or\dag\dag\or\ddag\ddag
\fi}
\def\sfootnote{%
\global\advance\footnotenumber by 1
\ifnum\footnotenumber>9 \global\footnotenumber=1 \fi
\footnote{\fnsymbol{\the\footnotenumber}}}
\endtt
\TeX2page produces the expected output for
all the footnote macros, including the user-defined
ones.
\beginsection Bibliographies
\index{cite@`\cite`}
\index{BibTeX@\BibTeX}
\index{bibliographies}