summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex')
-rw-r--r--Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex37
1 files changed, 29 insertions, 8 deletions
diff --git a/Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex b/Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex
index e26e628b0bb..237b9f39c38 100644
--- a/Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex
+++ b/Build/source/texk/web2c/cwebdir/texinputs/pdfwebtocfront.tex
@@ -1,28 +1,42 @@
-% pdfwebtofront.tex
+% pdfwebtocfront.tex
% Code from knuth.drv in https://github.com/oberdiek/latex-tds
-% 2020/06/20 v2.0 by Andreas Scherer.
+% 2024/05/25 v3.1 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.
+% Works with pdftex/xetex/luatex and plain tex/dvipdf in connection
+% with either 'pwebmac.tex' for Pascal/WEB programs or 'cwebmac.tex'
+% for C/CWEB programs.
%
\ifx\detokenize\undefined\endinput\fi
+\ifx\twodigits\undefined\endinput\fi
\def\contentsfile{\jobname.toc} % file that gets table of contents info
\newif\iftexmf\texmffalse % special toc treatment for TeX, Metafont, etc.
\newread\testread
\openin\testread=\contentsfile\relax
\ifeof\testread % First run
\else % Second run
+ % Fix page numbers in the PDF bootmarks with 'Page Labels'
+ \def\tocpages{1} % Most programs have one-page Table-of-Contents
+ \def\tocstart{2} % so we start with (fake) page 2 for the rest
+ \def\pagemode{/PageMode /UseOutlines}
+ \def\pagelabels{/PageLabels << /Nums [
+ \ifnum\contentspagenumber=0 0 << /P(Contents) >> \tocpages << /S/D/St 1 >>
+ \else 0 << /S/D/St \contentspagenumber >> \fi ] >> }
+ \def\startpdf{\ifpdflua\pdfcatalog{\pagemode\space\pagelabels}
+ \else {\special{pdf: docview << \pagemode\space\pagelabels >>}}\fi}
% Redefine '\con' to be invoked before the first '\N' (starred section).
\let\ORGcon\con
\def\con{%
% reduce size of PDF pages for more screen space
\pdfpagewidth=\pagewidth \advance\pdfpagewidth by 1in
\pdfpageheight=\fullpageheight \advance\pdfpageheight by 1in
+ \iftexmf \advance\pdfpageheight by 0.5in
+ \gtitle={Table of Contents} % overwrite default 'WEB output'
+ \mark{\noexpand\nullsec{\the\gtitle}} \fi
\ifpdflua \pdfhorigin=0.5in \pdfvorigin=0.5in
\else \global\pageshift=-0.5in
\global\hoffset=-0.5in \global\voffset=-0.5in \fi
@@ -34,27 +48,34 @@
}%
% Special variant for 'mf.web' and 'tex.web' (et al.).
% They all define a peculiar version of '\N' in their preamble.
- % And they put their tables-of-contents on a sparse 'page 2' and
- % start the main body on page '3'.
+ % And they put their tables-of-contents on sparse 'Contents' page(s)
+ % and start the main body on page '3'.
\edef\x{\jobname}%
\edef\y{\detokenize{tex}}%
\ifx\x\y \texmftrue\else
\edef\y{\detokenize{mf}}%
\ifx\x\y \texmftrue\else
\edef\y{\detokenize{pdftex}}%
- \ifx\x\y \texmftrue\else
+ \ifx\x\y \texmftrue \def\tocpages{2}\else
\edef\y{\detokenize{xetex}}%
\ifx\x\y \texmftrue\fi\fi\fi\fi
\iftexmf
+ % These main programs start on page '3' (after any number of ToC pages)
+ \def\pagelabels{/PageLabels << /Nums [
+ 0 << /P(Contents) >> \tocpages << /S/D/St 3 >> ] >> }
\expandafter\let\csname ORGN\expandafter\endcsname
\csname N\endcsname
\expandafter\outer\expandafter\def\csname N\endcsname{%
- \titletrue \con \pageno=2
+ \titletrue \con \pageno=\tocstart
\expandafter\let\csname N\expandafter\endcsname
\csname ORGN\endcsname
\csname N\endcsname
}%
\else % Much more general approach for WEB and CWEB programs.
+ \edef\y{\detokenize{mp}}%
+ % This main program starts on page '3' (after any number of ToC pages)
+ \ifx\x\y \def\pagelabels{/PageLabels << /Nums [
+ 0 << /P(Contents) >> \tocpages << /S/D/St 3 >> ] >> } \fi
% In fact, '\con' will be invoked _inside_ the first '\N' right _after_
% '\MN', but _before_ '\eject'. And '\topofcontents' gets in the twist
% as well.