diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/plain/contrib/misc/autotoc.tex |
Initial commit
Diffstat (limited to 'macros/plain/contrib/misc/autotoc.tex')
-rw-r--r-- | macros/plain/contrib/misc/autotoc.tex | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/macros/plain/contrib/misc/autotoc.tex b/macros/plain/contrib/misc/autotoc.tex new file mode 100644 index 0000000000..3b2f8ce6e8 --- /dev/null +++ b/macros/plain/contrib/misc/autotoc.tex @@ -0,0 +1,53 @@ +% +% Automatically generate a Table Of Contents (TOC) while the +% document is being processed by PLAIN TeX +% +% Use \tocref{ texta }{ textb } to insert TOC entries. `texta' +% will be typeset in the TOC and at the current location, +% for example `\centerline{\tocref{Chapter 1}{}}' inserts +% `Chapter 1' at the current location in your document +% centered, and enters it in the TOC (not centered). +% `textb' is a prefix text/TeX commands to precede `texta' +% in the TOC only (it will not appear in the current loc- +% ation of your document -- {{`textb'`texta'}.....\folio}). +% Use \tocline to add info only intended for the TOC (no page number or +% dotfill is used for tocline entries). +% Use \tocgen to force the last TOC page to be printed (last command +% before \end?) +% To specialize, look at the below comments in the right +% +% Uses variable names +% tocnew, tocopage, tocbox, tocsize, tocstrut, tocref, +% tocbanner, tocsuffix, tocline, tocstart, tocont, tocgen +% +\newcount\tocnew\tocnew=1\newcount\tocopage +\newbox\tocbox\newdimen\tocsize +\def\tocstrut{{\vrule height8.5pt depth3.5pt width0pt}} % TOC baselineskip -1pt +\def\tocref#1#2{\tocbanner#1 % Where `texta' is duplicated + \global\setbox\tocbox=\vbox{ + \box\tocbox\vbox{ + \line{\tocstrut{#2#1}~\dotfill~\folio} % Where the TOC line is made + }}\tocsuffix} +\def\tocline#1{\tocbanner + \global\setbox\tocbox=\vbox{ + \box\tocbox\vbox{ + \line{\tocstrut{#1}} + }}\tocsuffix} +\def\tocbanner{\ifnum\tocnew=1\tocstart\fi + \ifnum\tocnew=3\tocont\fi} +\def\tocsuffix{\ifdim\tocsize<\ht\tocbox\tocgen + \global\tocnew=3\fi} +% Do not change tocsize = 1.0 (TeX may go into an infinite loop) +\def\tocstart{\global\tocsize=.95\vsize % TOC page >95% full, print it + \global\setbox\tocbox=\vbox{ + \centerline{\tocstrut\bf Table Of Contents} % TOC page 1 banner line 1 + \line{\tocstrut\hfil} % TOC page 1 banner line 2 blank line + }\global\tocnew=2} +\def\tocont{\global\setbox\tocbox=\vbox{ + \centerline{\tocstrut Table Of Contents (Continued)} % TOC page <> 1 banner + }\global\tocnew=2} +\def\tocgen{\ifnum\tocnew=1 + \message{No TOC entries found.}\else + \tocopage=\pageno\pageno=0\message{(TOC} + \shipout\box\tocbox\message{)} + \pageno=\tocopage\global\tocnew=1\fi} |