diff options
author | Karl Berry <karl@freefriends.org> | 2022-06-22 20:52:52 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-06-22 20:52:52 +0000 |
commit | e30bffce416c228b04a7418a047408d3c0ae08d5 (patch) | |
tree | 9d427681546fdd04ecd51f2a95c5f4a5f2229fc8 /Master/texmf-dist/tex/latex/pbalance | |
parent | 8371bb42081e6a6b466faf47b7d97ec9d5f68af9 (diff) |
pbalance (22jun22)
git-svn-id: svn://tug.org/texlive/trunk@63692 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/pbalance')
-rw-r--r-- | Master/texmf-dist/tex/latex/pbalance/pbalance.sty | 237 |
1 files changed, 198 insertions, 39 deletions
diff --git a/Master/texmf-dist/tex/latex/pbalance/pbalance.sty b/Master/texmf-dist/tex/latex/pbalance/pbalance.sty index 1b54a4f76c6..6cab784cb9d 100644 --- a/Master/texmf-dist/tex/latex/pbalance/pbalance.sty +++ b/Master/texmf-dist/tex/latex/pbalance/pbalance.sty @@ -5,7 +5,7 @@ %% The original source files were: %% %% pbalance.dtx (with options: `package') -%% Copyright 2020-2021 Nelson Lago <lago@ime.usp.br> +%% Copyright 2020-2022 Nelson Lago <lago@ime.usp.br> %% %% This work may be distributed and/or modified under the conditions of the %% LaTeX Project Public License, either version 1.3c of this license or (at @@ -18,29 +18,44 @@ %% The Current Maintainer of this work is Nelson Lago <lago@ime.usp.br>. %% \NeedsTeXFormat{LaTeX2e}[2015/01/01] -\ProvidesPackage{pbalance}[2021/05/24 v1.1.1 Poor man's balance] +\ProvidesPackage{pbalance}[2022/06/22 v1.3.0 Poor man's balance] \RequirePackage{etoolbox} \RequirePackage{expl3} \RequirePackage{atbegshi} % Manipulate the page output routine \RequirePackage{atveryend} % Write to the aux file after processing ends \RequirePackage{zref-abspage} % Figure out the current page +\RequirePackage{filehook} % Patch other packages that modify the output routine -\AtEndOfPackage{\RequirePackage{balance}} - -\gdef \@reinserts{% - \ifvbox\@kludgeins\insert\@kludgeins - {\unvbox\@kludgeins}\fi - \ifvoid\footins\else\insert\footins{\unvbox\footins}\fi -} +\newtoggle{@PBpatchFailed} \providetoggle{@PBstabilized} \providetoggle{@PBimpossible} +\newtoggle{@PBnoBalancePackage} +\DeclareOption{safe}{\toggletrue{@PBnoBalancePackage}} + \newtoggle{@PBdraft} \DeclareOption{draft}{\toggletrue{@PBdraft}} + \ProcessOptions\relax +\AtEndPreamble{\@ifpackageloaded{lineno}{\toggletrue{@PBnoBalancePackage}}{}} + +\@ifpackageloaded{lineno}{\toggletrue{@PBnoBalancePackage}}{} + +\AtEndOfPackage{ + \ifboolexpr{togl {@PBdraft} or togl {@PBnoBalancePackage}} + {} + {\RequirePackage{balance}} +} + +\gdef \@reinserts{% + \ifvbox\@kludgeins\insert\@kludgeins + {\unvbox\@kludgeins}\fi + \ifvoid\footins\else\insert\footins{\unvbox\footins}\fi +} + \AtBeginDocument{ @@ -76,7 +91,10 @@ \newcommand\@PBStartBalancing{ \ifdefvoid{\@PBslack} {\@PBautomaticBalance} - {\@PBshrinkPage} + { + \PackageInfo{pbalance}{Automatic mode disabled, doing manual adjustment} + \@PBshrinkPage + } } \newcommand\@PBautomaticBalance{ @@ -91,10 +109,10 @@ \@PBcalculateShrinkage \@PBshrinkPage } - {} + {\PackageInfo{pbalance}{Page "naturally" balanced, doing nothing}} } } - {} + {\PackageInfo{pbalance}{Float-only column at last page, doing nothing}} } \newcommand\@PBcalculateShrinkage{ @@ -111,8 +129,8 @@ % Figure out the amount of unused space on the last page (both % cols); we will reduce the first column height by half that amount - \dimgdef\@PBslack{2\dimexpr\@PBtmpH\relax - \@PBtmpUL - \@PBtmpUR} - \dimgdef\@PBslack{.5\dimexpr\@PBslack\relax} + \dimgdef\@PBslack{\@PBtmpH *2 - \@PBtmpUL - \@PBtmpUR} + \dimgdef\@PBslack{\@PBslack /2} % Actually, I lied. While half, as said above, sometimes yields % perfectly balanced columns, that is often not the case (the page @@ -145,7 +163,12 @@ } } -\pretocmd{\@outputdblcol}{\@PBbalanceSecondColumn}{}{} +\pretocmd{\@outputdblcol}{\@PBbalanceSecondColumn} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } \let\@PBbalanceSecondColumn\relax @@ -180,7 +203,6 @@ \newtoggle{@PBtmpHasMarginpars} \def\@PBcollectPageInfo{ - \ifboolexpr { test {\@PBifmidfloat} or test {\@PBiftopfloat} or @@ -195,9 +217,19 @@ {} } -\pretocmd{\@makecol}{\@PBcollectPageInfo}{}{} +\pretocmd{\@makecol}{\@PBcollectPageInfo} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } -\pretocmd{\@addmarginpar}{\global\toggletrue{@PBtmpHasMarginpars}}{}{} +\pretocmd{\@addmarginpar}{\global\toggletrue{@PBtmpHasMarginpars}} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } \ExplSyntaxOn @@ -232,15 +264,55 @@ } \ExplSyntaxOff -\pretocmd{\@addtocurcol}{\dimgdef{\@PBtmpHeightBefore}{\@textfloatsheight}}{}{} -\apptocmd{\@addtocurcol}{\@PBcollectFloatHeights}{}{} +\pretocmd{\@addtocurcol}{\dimgdef{\@PBtmpHeightBefore}{\@textfloatsheight}} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + +\apptocmd{\@addtocurcol}{\@PBcollectFloatHeights} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } \newtoggle{@PBtmpHasFloatcol} \newtoggle{@PBtmpIsFloatPage} +\newcommand\@PBcollectColumnUsedHeight{ + \setbox\@tempboxa=\vbox{\unvcopy\@outputbox\unskip\unskip} + \dimgdef\@PBtmpColumnUsedHeight{\ht\@tempboxa\relax} +} + +\apptocmd{\@makecol}{\@PBcollectColumnUsedHeight} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + +\newtoggle{@PBpatchStillActive} % Let's make sure our patched code actually runs + \newcommand\@PBcollectColumnInfo{ + \global\toggletrue{@PBpatchStillActive} + + \iftoggle{@PBpatchFailed} + {} + { + \ifdefvoid{\@PBtmpColumnUsedHeight} + { + \global\toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch disabled by another + package, won't balance} + } + {\@PBreallyCollectColumnInfo} + } +} +\newcommand\@PBreallyCollectColumnInfo{ \if@firstcolumn \@PBiffloatcol @@ -256,6 +328,7 @@ % Space used by \texttt{here} floats \dimgdef\@PBtmpLeftFloatsHeight{\@textfloatsheight} + \dimgdef\@PBtmpUsedLeft{\@PBtmpColumnUsedHeight} \else @@ -269,28 +342,101 @@ \dimgdef\@PBtmpRightHeight{\@colroom} \dimgdef\@PBtmpRightFloatsHeight{\@textfloatsheight} - - \setbox\@tempboxa=\copy\@leftcolumn - \setbox\@tempboxa=\vbox{\unvbox\@tempboxa\unskip\unskip} - \dimgdef\@PBtmpUsedLeft{\ht\@tempboxa\relax} - - \setbox\@tempboxa=\copy\@outputbox - \setbox\@tempboxa=\vbox{\unvbox\@tempboxa\unskip\unskip} - \dimgdef\@PBtmpUsedRight{\ht\@tempboxa\relax} + \dimgdef\@PBtmpUsedRight{\@PBtmpColumnUsedHeight} \fi } -\pretocmd{\@outputdblcol}{\@PBcollectColumnInfo}{}{} +\pretocmd{\@outputdblcol}{\@PBcollectColumnInfo} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } -\AtEndOfPackage{ - \pretocmd{\@BAdblcol}{\@PBcollectColumnInfo}{}{} - % Revert \balance before next page if it exists (it might be a float page) - \patchcmd{\@BAdblcol}{\endgroup}{\endgroup\nobalance}{}{} -} +\ifboolexpr{togl {@PBdraft} or togl {@PBnoBalancePackage}} + {} + { + \AtEndOfPackage{ + \pretocmd{\@BAdblcol}{\@PBcollectColumnInfo} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + % 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} + } + } + } + + +\AtEndOfPackageFile{stfloats} + { + + \pretocmd{\@addtocurcol}{\dimgdef{\@PBtmpHeightBefore}{\@textfloatsheight}} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + + \apptocmd{\@addtocurcol}{\@PBcollectFloatHeights} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + } + +\AtEndOfPackageFile*{stfloats} + { + \pretocmd{\fn@makecol}{\@PBcollectPageInfo} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + \pretocmd{\org@makecol}{\@PBcollectPageInfo} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + \apptocmd{\fn@makecol}{\@PBcollectColumnUsedHeight} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + \apptocmd{\org@makecol}{\@PBcollectColumnUsedHeight} + {} + { + \toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch failed, won't balance} + } + } -\ExplSyntaxOn \AtBeginShipout{ + \iftoggle{@PBpatchFailed} + {} + { + \iftoggle{@PBpatchStillActive} + {\@PBfinalizePageData} + { + \global\toggletrue{@PBpatchFailed} + \PackageWarningNoLine{pbalance}{Patch disabled by another + package, won't balance} + } + } +} + +\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. @@ -334,7 +480,7 @@ % document, there is no candidate page. \ifcsdef{@PBlastPage} {\@PBcopyPageData{candidate}{pg\@Roman{\@PBlastPage}}} - {} + {\PackageInfo{pbalance}{No two-column pages, doing nothing}} } @@ -343,8 +489,16 @@ % so the user can start over if they want to. \iftoggle{@PBdraft}{\togglefalse{@PBimpossible}}{} - \ifboolexpr{togl {@PBdraft} or togl {@PBimpossible}} - {} + \ifboolexpr{togl {@PBdraft} or togl {@PBimpossible} or togl {@PBpatchFailed}} + { + \iftoggle{@PBimpossible} + {\PackageWarningNoLine{pbalance}{Could not balance, doing nothing}} + { + \iftoggle{@PBpatchFailed} + {\PackageWarningNoLine{pbalance}{Patching failed, doing nothing}} + {\PackageInfo{pbalance}{Draft mode, doing nothing}} + } + } { \ifdefvoid{\@PBprevLastPage} {\@PBsaveUnbalancedInfo\@PBnotifyRerun} % First pass @@ -420,6 +574,8 @@ togl {@PBunbalpg\@Roman{\@PBprevLastPage}HasFootnotes} or togl {@PBunbalpg\@Roman{\@PBprevLastPage}HasMarginpars} + or + togl {@PBnoBalancePackage} } {#2} {#1} @@ -593,7 +749,10 @@ \PackageWarningNoLine{pbalance} {Last two-column page cols not balanced. Rerun LaTeX} } - {} + { + \PackageWarningNoLine{pbalance} + {No two-column pages, doing nothing} + } } } |