summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex
blob: 8e72c76a07420882a97d1b96c44c29ebcb0230f6 (plain)
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
% pdfwebtofront.tex
% Code from knuth.drv in https://github.com/oberdiek/latex-tds
% 2020/05/21 v1.0 by Andreas Scherer.
%
% This file is part of project https://github.com/ascherer/cwebbin
% and may be distributed under the MIT License or the LaTeX Project
% Public License.
%
% Move table-of-contents page to the front in PDF output.
% Works with pdftex and xetex in connection with either 'webmac.tex'
% for Pascal/WEB programs or 'cwebmac.tex' for C/CWEB programs.
%
\ifx\detokenize\undefined\endinput\fi
\newread\testread
\openin\testread=\contentsfile\relax
\ifeof\testread % First run
\else % Second run
  \let\ORGcon\con \let\ORGtoc\topofcontents
  \ifx\undefined\grouptitle \mark{1} % WEB: let's start with section '1'.
  \else\def\topofcontents{\ORGtoc\gtitle={\the\grouptitle}}\fi % CWEB
  % Redefine '\con' to be invoked before the first '\N' (starred section).
  \def\con{%
    \def\:{\par\hangindent 2em} % Fix for 'bibtex.web'.
    \begingroup
      \let\end\relax
      \ORGcon\eject
    \endgroup
    \let\con\end
  }%
  % Redefine '\N’ to invoke redefined '\con' before switching back
  % to original '\N'.
  \expandafter\let\csname ORGN\expandafter\endcsname
                  \csname N\endcsname
  \expandafter\outer\expandafter\def\csname N\endcsname{%
    \con
    \expandafter\let\csname N\expandafter\endcsname
                    \csname ORGN\endcsname
    \csname N\endcsname
  }%
  % Special variant of the above for 'mf.web' and 'tex.web'.  They put
  % their tables-of-contents on a sparce 'page 2' and start on page '3'.
  \begingroup
    \def\num{0}%
    \edef\x{\jobname}%
    \edef\y{\detokenize{tex}}%
    \ifx\x\y \def\num{1}\else
    \edef\y{\detokenize{mf}}%
    \ifx\x\y \def\num{1}\else
    \edef\y{\detokenize{pdftex}}%
    \ifx\x\y \def\num{1}\else
    \edef\y{\detokenize{xetex}}%
    \ifx\x\y \def\num{1}\fi\fi\fi\fi
  \expandafter\endgroup\ifnum\num=1 %
    \def\contentspagenumber{2}%
    \let\ORGpageno\pageno
    \def\pageno{%
      \let\pageno\ORGpageno
      \expandafter\let\csname ORGN\expandafter\endcsname
                      \csname N\endcsname
      \expandafter\outer\expandafter\def\csname N\endcsname{%
        \con
        \expandafter\let\csname N\expandafter\endcsname
                        \csname ORGN\endcsname
        \csname N\endcsname
      }%
      \pageno
    }%
  \fi
\fi