summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-07-29 21:00:35 +0000
committerKarl Berry <karl@freefriends.org>2022-07-29 21:00:35 +0000
commit855f5fb65b35423aa18e0e69a1e36aca098e93e3 (patch)
treef31a276d0465d13a1b9cc1e48e090688e7f68659 /Master/texmf-dist/tex/latex
parentf87ea7533e16b8b8a7f8b0348e15b34e0dcba81e (diff)
pbalance (28jul22)
git-svn-id: svn://tug.org/texlive/trunk@64002 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r--Master/texmf-dist/tex/latex/pbalance/pbalance.sty338
1 files changed, 267 insertions, 71 deletions
diff --git a/Master/texmf-dist/tex/latex/pbalance/pbalance.sty b/Master/texmf-dist/tex/latex/pbalance/pbalance.sty
index 6cab784cb9d..10719cbcaa4 100644
--- a/Master/texmf-dist/tex/latex/pbalance/pbalance.sty
+++ b/Master/texmf-dist/tex/latex/pbalance/pbalance.sty
@@ -18,7 +18,7 @@
%% The Current Maintainer of this work is Nelson Lago <lago@ime.usp.br>.
%%
\NeedsTeXFormat{LaTeX2e}[2015/01/01]
-\ProvidesPackage{pbalance}[2022/06/22 v1.3.0 Poor man's balance]
+\ProvidesPackage{pbalance}[2022/07/28 v1.4.0 Poor man's balance]
\RequirePackage{etoolbox}
\RequirePackage{expl3}
@@ -87,6 +87,8 @@
}
\newcommand\shrinkLastPage[1]{\dimgdef\@PBslack{#1}}
+\newcommand\balancePageNum[1]{\gdef\@PBthepage{#1}}
+\newcommand\nopbalance{\toggletrue{@PBdraft}}
\newcommand\@PBStartBalancing{
\ifdefvoid{\@PBslack}
@@ -167,7 +169,7 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@outputdblcol)}
}
\let\@PBbalanceSecondColumn\relax
@@ -221,14 +223,14 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@makecol)}
}
\pretocmd{\@addmarginpar}{\global\toggletrue{@PBtmpHasMarginpars}}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@addmarginpar)}
}
@@ -268,19 +270,19 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@addtocurcol)}
}
\apptocmd{\@addtocurcol}{\@PBcollectFloatHeights}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@addtocurcol)}
}
\newtoggle{@PBtmpHasFloatcol}
-\newtoggle{@PBtmpIsFloatPage}
+\newtoggle{@PBtmpFloatcolBoth}
\newcommand\@PBcollectColumnUsedHeight{
\setbox\@tempboxa=\vbox{\unvcopy\@outputbox\unskip\unskip}
@@ -291,24 +293,26 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@makecol)}
}
-\newtoggle{@PBpatchStillActive} % Let's make sure our patched code actually runs
+ % Let's make sure our patched code actually runs. We only switch this
+ % to true after we verify that the patches in @makecol and @outputdblcol
+ % are actually executed when the page is built (therefore, after the
+ % preamble has ended).
+\newtoggle{@PBpatchStillActive}
\newcommand\@PBcollectColumnInfo{
- \global\toggletrue{@PBpatchStillActive}
-
\iftoggle{@PBpatchFailed}
{}
{
\ifdefvoid{\@PBtmpColumnUsedHeight}
+ {} % the patch to @makecol is not active, so we do nothing here
{
- \global\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch disabled by another
- package, won't balance}
+ % the patch to @makecol is active and so is ours, we're good to go!
+ \global\toggletrue{@PBpatchStillActive}
+ \@PBreallyCollectColumnInfo
}
- {\@PBreallyCollectColumnInfo}
}
}
@@ -335,7 +339,7 @@
\@PBiffloatcol
{
\iftoggle{@PBtmpHasFloatcol}
- {\global\toggletrue{@PBtmpIsFloatPage}}
+ {\global\toggletrue{@PBtmpFloatcolBoth}}
{\global\toggletrue{@PBtmpHasFloatcol}}
}
{}
@@ -350,7 +354,7 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@outputdblcol)}
}
\ifboolexpr{togl {@PBdraft} or togl {@PBnoBalancePackage}}
@@ -361,14 +365,14 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@BAdblcol)}
}
% Revert \balance before next page if it exists (it might be a float page)
\patchcmd{\@BAdblcol}{\endgroup}{\endgroup\nobalance}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (@BAdblcol)}
}
}
}
@@ -381,14 +385,14 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (stfloats/@addtocurcol)}
}
\apptocmd{\@addtocurcol}{\@PBcollectFloatHeights}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (stfloats/@addtocurcol)}
}
}
@@ -398,81 +402,265 @@
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (stfloats/fn@makecol)}
}
\pretocmd{\org@makecol}{\@PBcollectPageInfo}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (stfloats/org@makecol)}
}
\apptocmd{\fn@makecol}{\@PBcollectColumnUsedHeight}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (stfloats/fn@makecol)}
}
\apptocmd{\org@makecol}{\@PBcollectColumnUsedHeight}
{}
{
\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch failed, won't balance}
+ \PackageWarningNoLine{pbalance}{Patch failed (stfloats/org@makecol)}
+ }
+ }
+
+
+
+\ifdefvoid{\mem@makecol}
+ {}
+ {
+ \pretocmd{\mem@makecol}{\@PBcollectPageInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (memoir/mem@makecol)}
+ }
+ \apptocmd{\mem@makecol}{\@PBcollectColumnUsedHeight}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (memoir/mem@makecol)}
+ }
+ \pretocmd{\mem@makecolbf}{\@PBcollectPageInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (memoir/mem@makecolbf)}
+ }
+ \apptocmd{\mem@makecolbf}{\@PBcollectColumnUsedHeight}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (memoir/mem@makecolbf)}
+ }
+ }
+
+
+\AtEndOfPackageFile{footmisc}
+ {
+ \pretocmd{\@makecol}{\@PBcollectPageInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (footmisc/@makecol)}
+ }
+ \apptocmd{\@makecol}{\@PBcollectColumnUsedHeight}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (footmisc/@makecol)}
+ }
+ }
+
+
+
+\AtEndOfPackageFile{ftnright}
+ {
+ \pretocmd{\@makecol}{\@PBcollectPageInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (ftnright/@makecol)}
+ }
+ \apptocmd{\@makecol}{\@PBcollectColumnUsedHeight}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (ftnright/@makecol)}
+ }
+
+ \pretocmd{\@outputdblcol}{\@PBbalanceSecondColumn}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (ftnright/@outputdblcol)}
+ }
+
+ \pretocmd{\@outputdblcol}{\@PBcollectColumnInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (ftnright/@outputdblcol)}
+ }
+ }
+
+
+
+
+
+\AtEndOfPackageFile{flafter}
+ {
+
+ \pretocmd{\@addtocurcol}{\dimgdef{\@PBtmpHeightBefore}{\@textfloatsheight}}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (flafter/@addtocurcol)}
+ }
+
+ \apptocmd{\@addtocurcol}{\@PBcollectFloatHeights}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (flafter/@addtocurcol)}
+ }
+ }
+
+
+
+\AtEndOfPackageFile{fnpos}
+ {
+ \pretocmd{\@makecol}{\@PBcollectPageInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (fnpos/@makecol)}
+ }
+ \apptocmd{\@makecol}{\@PBcollectColumnUsedHeight}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (fnpos/@makecol)}
+ }
+ }
+
+
+
+\AtEndOfPackageFile{cuted}
+ {
+ \pretocmd{\@outputdblcol}{\@PBbalanceSecondColumn}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (cuted/@outputdblcol)}
+ }
+
+ \pretocmd{\@outputdblcol}{\@PBcollectColumnInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (cuted/@outputdblcol)}
+ }
+ }
+
+\AtEndOfPackageFile{midfloat}
+ {
+ \pretocmd{\@outputdblcol}{\@PBbalanceSecondColumn}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (midfloat/@outputdblcol)}
+ }
+
+ \pretocmd{\@outputdblcol}{\@PBcollectColumnInfo}
+ {}
+ {
+ \toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch failed (midfloat/@outputdblcol)}
}
}
+\ExplSyntaxOn
\AtBeginShipout{
\iftoggle{@PBpatchFailed}
{}
{
- \iftoggle{@PBpatchStillActive}
- {\@PBfinalizePageData}
- {
- \global\toggletrue{@PBpatchFailed}
- \PackageWarningNoLine{pbalance}{Patch disabled by another
- package, won't balance}
- }
+ % It only makes sense to consider pages that actually have two columns.
+ \if@twocolumn
+ \iftoggle{@PBpatchStillActive}
+ {\@PBfinalizePageData}
+ {
+ \global\toggletrue{@PBpatchFailed}
+ \PackageWarningNoLine{pbalance}{Patch~disabled~by~another~package}
+ }
+ \fi
+
+ % Reset before processing next page
+ \global\togglefalse{@PBtmpHasFloats}
+ \global\togglefalse{@PBtmpHasFloatcol}
+ \global\togglefalse{@PBtmpHasFootnotes}
+ \global\togglefalse{@PBtmpHasMarginpars}
+ \global\togglefalse{@PBtmpFloatcolBoth}
+
+ \seq_gclear_new:N \@PBtmpLeftFloatHeights
+ \seq_gclear_new:N \@PBtmpLeftFloatSpacesBelow
+
+ \gundef{\@PBtmpHeight}
+ \gundef{\@PBtmpLeftHeight}
+ \gundef{\@PBtmpLeftFloatsHeight}
+ \gundef{\@PBtmpUsedLeft}
+ \gundef{\@PBtmpRightHeight}
+ \gundef{\@PBtmpRightFloatsHeight}
+ \gundef{\@PBtmpUsedRight}
}
}
+\ExplSyntaxOff
-\ExplSyntaxOn
\newcommand\@PBfinalizePageData{
- % It only makes sense to consider pages that actually have two
- % columns. LaTeX3 does not do short-circuit evaluation, so we
- % cannot add this test to the ifboolexpr below.
- \if@twocolumn
- \ifboolexpr
- {
- % A float page is not the last text page, ignore
- togl {@PBtmpIsFloatPage}
- or
- % A page with a float column on the left and an empty
- % column on the right is not the last text page, ignore
- (
- togl {@PBtmpHasFloatcol}
- and
- test {\ifdimcomp{\@PBtmpUsedRight}{=}{\topskip}}
- )
- }
- {}
- {
- % This page is a candidate to be the last two-column text page
- \xdef\@PBlastPage{\the\value{abspage}}
- \@PBcopyPageData{tmp}{candidate}
- }
- \fi
-
- % Reset before processing next page
- \global\togglefalse{@PBtmpHasFloats}
- \global\togglefalse{@PBtmpHasFloatcol}
- \global\togglefalse{@PBtmpHasFootnotes}
- \global\togglefalse{@PBtmpHasMarginpars}
- \global\togglefalse{@PBtmpIsFloatPage}
-
- \seq_gclear_new:N \@PBtmpLeftFloatHeights
- \seq_gclear_new:N \@PBtmpLeftFloatSpacesBelow
+ % LaTeX3 does not do short-circuit evaluation,
+ % so we cannot use a single ifboolexpr here
+ \ifdefvoid{\@PBtmpUsedRight}
+ % This is probably a float page or the user disabled
+ % the package somehow and recompiled. Either way,
+ % this is not the last text page, ignore
+ {}
+ {
+ \ifboolexpr
+ {
+ % If both cols are float cols, this is not the last text page, ignore
+ togl {@PBtmpFloatcolBoth}
+ or
+ % A page with a float column on the left and an empty
+ % column on the right is not the last text page, ignore
+ (
+ togl {@PBtmpHasFloatcol}
+ and
+ test {\ifdimcomp{\@PBtmpUsedRight}{=}{\topskip}}
+ )
+ }
+ {}
+ {
+ \ifdefvoid{\@PBthepage}
+ {
+ % The user did not choose a page, so this page is
+ % a candidate to be the last two-column text page
+ \xdef\@PBlastPage{\the\value{abspage}}
+ \@PBcopyPageData{tmp}{candidate}
+ }
+ {
+ \ifnumcomp{\@PBthepage}{=}{\the\value{abspage}}
+ {
+ % This is the page the user indicated
+ % as the last two-column text page
+ \xdef\@PBlastPage{\the\value{abspage}}
+ \@PBcopyPageData{tmp}{candidate}
+ }
+ {}
+ }
+ }
+ }
}
-\ExplSyntaxOff
\AfterLastShipout{
@@ -495,7 +683,11 @@
{\PackageWarningNoLine{pbalance}{Could not balance, doing nothing}}
{
\iftoggle{@PBpatchFailed}
- {\PackageWarningNoLine{pbalance}{Patching failed, doing nothing}}
+ {
+ \PackageWarningNoLine{pbalance}{Patching failed, cannot balance;
+ try \MessageBreak loading
+ pbalance earlier or later}
+ }
{\PackageInfo{pbalance}{Draft mode, doing nothing}}
}
}
@@ -535,8 +727,12 @@
% The document has changed, so we need to measure
% stuff again; clear aux file and start over.
{\@PBnotifyRerun}
- % Nothing changed, just write the same info down
- {\@PBsaveUnbalancedInfo\@PBsaveBalancedInfo}
+ {
+ % Nothing changed, just write the same info down
+ \@PBsaveUnbalancedInfo
+ \@PBsaveBalancedInfo
+ \PackageInfo{pbalance}{Done balancing page \@PBlastPage}
+ }
}
% Second pass, which means something did change: we have just
% balanced the columns for the first time.