| 1 |
% This file is part of the CTAN package named plain-widow. |
| 2 |
% |
| 3 |
% pxwreport.tex: change \plainoutput to \PXoutput |
| 4 |
% that writes a report about problematic lines |
| 5 |
% widow lines, club lines, and hyphenate last words |
| 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 |
%%% control sequences for club lines |
| 24 |
\newtoks\PXclublines % stores their page numbers |
| 25 |
\newif\ifPXfoundclubline % true: >= 1 entry |
| 26 |
\def\PXpagehasclubline{\edef\next{% no \global |
| 27 |
\ifPXfoundclubline \the\PXclublines, |
| 28 |
\the\pageno\else\the\pageno\fi}% |
| 29 |
\global\PXfoundclublinetrue |
| 30 |
\global\PXclublines=\expandafter{\next}} |
| 31 |
%%% and for widow and displaywidow lines |
| 32 |
\newtoks\PXwidowlines \newif\ifPXfoundwidowline |
| 33 |
\def\PXpagehaswidowline#1{% #1: 0, 1, or 2 |
| 34 |
% 0: widow, 1: displaywidow, 2: postdisplay |
| 35 |
\edef\next{% \global not required |
| 36 |
\ifPXfoundwidowline \the\PXwidowlines, |
| 37 |
% displaywidow and postdisplay in parentheses |
| 38 |
\ifnum#1=0 \the\pageno \else (\the\pageno)\fi |
| 39 |
\else\ifnum#1=0 \the\pageno\else(\the\pageno)% |
| 40 |
\fi\fi \ifnum#1=2 ?\fi}% `?' marks postdisplay |
| 41 |
\global\PXfoundwidowlinetrue |
| 42 |
\global\PXwidowlines=\expandafter{\next}} |
| 43 |
%%% and for broken lines |
| 44 |
\newtoks\PXbrokenlines\newif\ifPXfoundbrokenline |
| 45 |
\def\PXpagehasbrokenline{\edef\next{% |
| 46 |
\ifPXfoundbrokenline \the\PXbrokenlines, |
| 47 |
\the\pageno\else\the\pageno\fi}% |
| 48 |
\global\PXfoundbrokenlinetrue |
| 49 |
\global\PXbrokenlines=\expandafter{\next}} |
| 50 |
\newhelp\PXnoreload{The reload redeclares a few |
| 51 |
registers; already stored information is lost.} |
| 52 |
\def\PXreport{% report problematic line breaks |
| 53 |
\ifnum\PXprint=1 \par % exercise page builder |
| 54 |
\write16{Widow lines on the following pages: |
| 55 |
\ifPXfoundwidowline \the\PXwidowlines |
| 56 |
\else none found\fi.} |
| 57 |
\write16{Club lines on the following pages: |
| 58 |
\ifPXfoundclubline \the\PXclublines |
| 59 |
\else none found\fi.} |
| 60 |
\write16{Hyphen at page break on the following |
| 61 |
pages: \ifPXfoundbrokenline |
| 62 |
\the\PXbrokenlines\else none found\fi.} |
| 63 |
\fi} |
| 64 |
\expandafter\ifx\csname PXprint\endcsname\relax |
| 65 |
\def\PXprint{1 }\expandafter\let\csname PXbye% |
| 66 |
\expandafter\endcsname\csname bye\endcsname |
| 67 |
\else\errhelp=\PXnoreload \errmessage{Don't |
| 68 |
input this file more than once}\fi |
| 69 |
\outer\def\bye{\PXreport\csname PXbye\endcsname} |
| 70 |
% if \interlinepenalty<>0 add its value to \defs |
| 71 |
\def\PXpenB{101 }\brokenpenalty=101 % change: +1 |
| 72 |
\def\PXpenC{150 }\clubpenalty=150 % 0 |
| 73 |
\def\PXpenD{51 }\displaywidowpenalty=51 % +1 |
| 74 |
\def\PXpenW{151 }\widowpenalty=151 % +1 |
| 75 |
%%% combinations (sums) of two or more penalties |
| 76 |
% ... with \widowpenalty |
| 77 |
\def\PXpenBW{252 } |
| 78 |
\def\PXpenCW{301 } |
| 79 |
\def\PXpenBCW{402 } |
| 80 |
% ... with \clubpenalty, no \widowpenalty |
| 81 |
\def\PXpenCD{201 } |
| 82 |
\def\PXpenBC{251 } |
| 83 |
\def\PXpenBCD{302 } |
| 84 |
% ... with \displaywidowpenalty, no \clubpenalty |
| 85 |
\def\PXpenBD{152 } |
| 86 |
% check pages for ``postdisplay widow line'' |
| 87 |
\postdisplaypenalty=2 % change = +2 |
| 88 |
%%% IMPORTANT: all values must be unique |
| 89 |
\newif\ifPXpagewithclub % true: page has a club |
| 90 |
\newif\ifPXpagewithwidow % or a widow or a |
| 91 |
\newif\ifPXpagewithdisplaywidow % display widow |
| 92 |
\newif\ifPXpagewithhyphen % or ends with hyphen |
| 93 |
\newif\ifPXpagewithpostdisplaytext % check page |
| 94 |
\def\PXoutput{% report problematic lines |
| 95 |
\ifnum\outputpenalty=\PXpenW |
| 96 |
\PXpagewithwidowtrue |
| 97 |
\else\ifnum\outputpenalty=\PXpenBW |
| 98 |
\PXpagewithhyphentrue |
| 99 |
\PXpagewithwidowtrue |
| 100 |
\else\ifnum\outputpenalty=\PXpenCW |
| 101 |
\PXpagewithclubtrue |
| 102 |
\PXpagewithwidowtrue |
| 103 |
\else\ifnum\outputpenalty=\PXpenBCW |
| 104 |
\PXpagewithhyphentrue |
| 105 |
\PXpagewithclubtrue |
| 106 |
\PXpagewithwidowtrue |
| 107 |
\else\ifnum\outputpenalty=\PXpenC |
| 108 |
\PXpagewithclubtrue |
| 109 |
\else\ifnum\outputpenalty=\PXpenBC |
| 110 |
\PXpagewithhyphentrue |
| 111 |
\PXpagewithclubtrue |
| 112 |
\else\ifnum\outputpenalty=\PXpenCD |
| 113 |
\PXpagewithclubtrue |
| 114 |
\PXpagewithdisplaywidowtrue |
| 115 |
\else\ifnum\outputpenalty=\PXpenBCD |
| 116 |
\PXpagewithhyphentrue |
| 117 |
\PXpagewithclubtrue |
| 118 |
\PXpagewithdisplaywidowtrue |
| 119 |
\else\ifnum\outputpenalty=\PXpenB |
| 120 |
\PXpagewithhyphentrue |
| 121 |
\else\ifnum\outputpenalty=\PXpenBD |
| 122 |
\PXpagewithhyphentrue |
| 123 |
\PXpagewithdisplaywidowtrue |
| 124 |
\else\ifnum\outputpenalty=\PXpenD |
| 125 |
\PXpagewithdisplaywidowtrue |
| 126 |
\else\ifnum\outputpenalty=\postdisplaypenalty |
| 127 |
\PXpagewithpostdisplaytexttrue |
| 128 |
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi |
| 129 |
\PXpreplain \plainoutput \PXpostplain |
| 130 |
\PXpostoutput} |
| 131 |
\output={\PXoutput}\let\PXpostoutput=\relax |
| 132 |
\def\PXpreplain{% todos before \plainoutput |
| 133 |
\ifPXpagewithclub \PXpagehasclubline \fi |
| 134 |
\ifPXpagewithhyphen \PXpagehasbrokenline \fi} |
| 135 |
\def\PXpostplain{% todos after \plainoutput |
| 136 |
\ifPXpagewithwidow \PXpagehaswidowline0\fi |
| 137 |
\ifPXpagewithdisplaywidow |
| 138 |
\PXpagehaswidowline1\fi |
| 139 |
\ifPXpagewithpostdisplaytext |
| 140 |
\PXpagehaswidowline2\fi} |
| 141 |
\def\startwithPlain{\holdinginserts=0 |
| 142 |
\displaywidowpenalty=50 \widowpenalty=150 |
| 143 |
\brokenpenalty=100 \postdisplaypenalty=0 |
| 144 |
\def\footlinedist{24pt }\def\PXprint{0 }% |
| 145 |
\output={\plainoutput}\wlog{use plainoutput}} |