cwebbin icon indicating copy to clipboard operation
cwebbin copied to clipboard

Shift page numbers to place mini-indexes on a spread.

Open ascherer opened this issue 1 year ago • 2 comments

By default, CTWILL output starts on “page 1” and the mini-index for each pair of pages appears on the even-numbered page. Although the \contentspagenumber is set to “0”, pdfctwimac.tex does not produce a useful table-of-contents (yet).

In DEK's software books (Stanford GraphBase and MMIXware), the mini-indexes appear on the right-hand, i.e., odd-numbered page of each spread. (Don't ask about twimac.tex for WEB sources processed with TWILL.)

In order to achieve this page shift, we must modify pdfctwimac.tex to “add 1” to the \folio number in the page headers

 % diff pdfctwimac.tex /usr/local/texlive/2024basic/texmf-dist/tex/plain/cweb/cwebbin/pdfctwimac.tex
419,421d418
< \newcount\PageNo
< \def\Folio{\PageNo=\pageno \advance\PageNo by 1
<   \ifnum\pageno<\z@ \romannumeral-\PageNo \else\number\PageNo \fi}
424c421
<   \hfil\eightrm\Folio}}
---
>   \hfil\eightrm\folio}}
426c423
<   \eightrm\Folio\hfil\ninerm\title:\enspace \eightsl\rrhead\/}}
---
>   \eightrm\folio\hfil\ninerm\title:\enspace \eightsl\rrhead\/}}

and the preamble in mmix-noinx.ch to change the page reference in the PDF catalog

% git diff
diff --git a/mmix-noinx.ch b/mmix-noinx.ch
index caaa449..6f73862 100644
--- a/mmix-noinx.ch
+++ b/mmix-noinx.ch
@@ -2,8 +2,9 @@
 {\eightpoint \let\ninett=\eighttt \editorsnote \vskip7mm}
 @y
 \def\startpdf{\def\pagemode{/PageMode /UseOutlines}
-  \ifpdflua\pdfcatalog{\pagemode}
-  \else\special{pdf: docview << \pagemode >>}\fi}
+  \def\pagelabels{/PageLabels << /Nums [ 0 << /S/D/St 2 >> ] >> }
+  \ifpdflua\pdfcatalog{\pagemode\space\pagelabels}
+  \else\special{pdf: docview << \pagemode\space\pagelabels >>}\fi}
 {\eightpoint \let\ninett=\eighttt \editorsnote \vskip7mm}
 @z

Internally, apart from the table-of-contents, CWEB documents never reference pages, only sections.

ascherer avatar Jan 20 '25 13:01 ascherer

Alternatively, pdfctwimac.tex could finally get a “real” \con macro, and we could start in the preamble with

\def\contentspagenumber{1}
\pageno=\contentspagenumber
\advance\pageno by 1

With this approach, the \startdf macro from pdfctwimac.tex a/o pdfwebtocfront.tex should work out-of-the-box.

ascherer avatar Jan 20 '25 15:01 ascherer

Note that in both The Stanford GraphBase and MMIXware books, all chapters generated from publically available CWEB sources start on even-numbered, i.e., left-hand pages.

Moreover, the chapters in the MMIXware book have footers that contain page ranges for each chapter. I guess DEK used some change files that hard-coded the first and last page of each chapter.

ascherer avatar Jan 20 '25 20:01 ascherer