Debian Codegraph @

texmf-dist/tex/plain/plain-widow/pxwsingle.tex

raw
1 % This file is part of the CTAN package named plain-widow.
2 %
3 % pxwsingle.tex: change \plainoutput to \PXsinglepage
4 % that writes a report about problematic lines
5 % and prevents widow lines in a text by changing \vsize
6 % Version 1.0, 13.05.2025
7 %
8 % Copyright (C) 2025 Udo Wermuth (author)
9 %
10 % This program is free software: you can redistribute it and/or modify
11 % it under the terms of the GNU General Public License as published by
12 % the Free Software Foundation, either version 3 of the License, or
13 % (at your option) any later version.
14 %
15 % This program is distributed in the hope that it will be useful,
16 % but WITHOUT ANY WARRANTY; without even the implied warranty of
17 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 % GNU General Public License for more details.
19 %
20 % You should have received a copy of the GNU General Public License
21 % along with this program. If not, see <http://www.gnu.org/licenses/>.
22 %
23 \input pxwreport.tex
24 \holdinginserts=1 % change its default value
25 \newbox\PrevPageBotMark % box to store \botmark
26 \def\SaveCurrentBotMark{% fill \PrevPageBotMark
27 \global\setbox\PrevPageBotMark % must be global
28 =\vbox{Restore\mark{\botmark}\vfil}}
29 \SaveCurrentBotMark % initialize the box
30 \def\RestoreBotMark{-"C0DA }% unique < -10000
31 \def\footlinedist{30pt }%plain TeX's value: 24pt
32 \def\makefootline{\baselineskip=\footlinedist
33 \lineskiplimit=0pt\line{\the\footline}}
34 \begingroup \dimen255=\footlinedist
35 \gdef\PXnormaldist{\gdef\footlinedist{30 pt}}
36 \advance\dimen255 by +1\baselineskip
37 \xdef\PXplusdist{\noexpand\gdef\noexpand
38 \footlinedist{\the\dimen255 }}
39 \advance\dimen255 by -2\baselineskip
40 \xdef\PXminusdist{\noexpand\gdef\noexpand
41 \footlinedist{\the\dimen255 }}\endgroup
42 \def\PXincVsize{% increase \vsize by one line
43 \global\advance\vsize by +1\baselineskip
44 \PXminusdist\wlog{SINGLE: \vsize + 1 line}}
45 \def\PXdecVsize{% decrease \vsize by one line
46 \global\advance\vsize by -1\baselineskip
47 \PXplusdist\wlog{SINGLE: \vsize - 1 line}}
48 \def\PXresetVsize{% reset \vsize to former value
49 \ifdim\vsize=\PXsaveVsize \else \PXnormaldist
50 \global\vsize=\PXsaveVsize \fi}
51 \def\PXstorevsize{\edef\PXsaveVsize{\the\vsize}}
52 \PXstorevsize % call this if \vsize is changed
53 \newif\ifPXshowoutputroutine % true: show method
54 \def\PXlog#1{% #1: string; flag-protected \wlog
55 \ifPXshowoutputroutine\wlog{#1}\fi}
56 \def\PXsinglepage{% prevent club and widow lines
57 \ifnum\outputpenalty=\RestoreBotMark
58 \setbox0=\vbox{\unvbox255 }% ignore contents
59 \else\ifnum\outputpenalty=\PXpenW
60 \PXincVsize \unvbox255 % keep \penalty10000
61 \else\ifnum\outputpenalty=\PXpenBW
62 \PXincVsize \unvbox255
63 \else\ifnum\outputpenalty=\PXpenCW
64 \PXincVsize \unvbox255
65 \else\ifnum\outputpenalty=\PXpenBCW
66 \PXincVsize \unvbox255
67 \else\ifnum\outputpenalty=\PXpenC
68 \PXdecVsize \unvbox255
69 \else\ifnum\outputpenalty=\PXpenCD
70 \PXdecVsize \unvbox255
71 \else\ifnum\outputpenalty=\PXpenBC
72 \PXdecVsize \unvbox255
73 \else\ifnum\outputpenalty=\PXpenBCD
74 \PXdecVsize \unvbox255
75 \else\ifnum\holdinginserts=1 % switch its value
76 \global\holdinginserts=0
77 \unvbox\PrevPageBotMark % restore \botmark to
78 \penalty\RestoreBotMark % get a valid \topmark
79 \unvbox255 % next, reprocess material
80 \ifnum\outputpenalty<10000 % including penalty
81 \penalty\outputpenalty \fi% keep \TeX's 10000
82 \else \SaveCurrentBotMark % for next \topmark
83 \PXlog{OUTPUT: single }\PXoutput \PXresetVsize
84 \global\holdinginserts=1 \PXpostsingle
85 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
86 \output={\PXsinglepage}
87 \let\PXpostsingle=\relax
88 \def\startwithReport{\holdinginserts=0
89 \output={\PXoutput}}
90 \def\fromSingletoReport{%
91 \def\PXpostsingle{\global\holdinginserts=0
92 \global\output={\PXoutput}}}
93 \def\fromReporttoSingle{%
94 \SaveCurrentBotMark \global\holdinginserts=1
95 \global\let\PXpostoutput=\relax
96 \global\let\PXpostsingle=\relax
97 \global\output={\PXsinglepage}}