Chapter27. PageBreaking
Some penalties are implicitlyinsertedby T
E
X, forinstance e the \interlinepenalty
which is s put in n between every pair of lines of a paragraph. Other penalties can be
explicitly insertedby the useror a usermacro. A penalty value p≥ ≥ 10000 0 inhibits
breaking; apenaltyp≤−10000 (inexternalverticalmode)forces apage break, , and
immediatelyactivates theoutputroutine.
Costcalculationproceeds asfollows:
1.
Whenapenaltyissolowthatitforcesapagebreakandimmediateinvocation
oftheoutputroutine, butthepageisnotoverfull, thatis
b<∞
and p≤−10000
thecostis equaltothepenalty:c=p.
2.
Whenpenaltiesdonotforceanything,andthepageisnotoverfull, thatis
b<∞
and |p|<10000
thecostis c=b+p.
3.
Forpages thatareverybad, thatis
b=10000 and |p|<10000
thecostis c=10000.
4.
Anoverfullpage, thatis
b=∞
and p<10000
gives infinite cost: c = ∞. . In this case e T
E
X decides that the optimal break
point must have occurred earlier, , and it t invokes the output routine. . Values
of\insertpenalties(seeChapter29)that exceed10000alsogive infinite
cost.
The fact that a penalty p≤ −10000 activates s the e output routine is used extensively
intheL
A
T
E
Xoutputroutine:theexcess|p|−10000isacodeindicatingthereasonfor
callingtheoutputroutine;seealsothesecondexampleinthenextchapter.
27.5 \vsplit
Thepage-breakingoperationis available totheuserthroughthe\vsplitoperation.
\setbox1 = \vsplit2 to \dimen3
assignsto box 1thetoppart ofsize\dimen3ofbox 2.Thismaterial
is actually removed from box 2. Compare this with splitting off a
chunk of size \vsize from thecurrent page.
Theextracted result of
\vsplit8-bit numbertodimen
isabox withthefollowing properties.
Height equal to the specified dimen; T
E
X will go through the original box
register (which must contain a vertical box) to find the best breakpoint. This
may result in an underfull box.
Depth at most \splitmaxdepth; this is analogousto the \maxdepthfor the
pagebox,rather than the\boxmaxdepththat holds for any box.
Afirstandlast mark inthe\splitfirstmarkand \splitbotmarkregisters.
230
VictorEijkhout–T
E
XbyTopic
Cut pages from pdf online - remove PDF pages in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Provides Users with Mature Document Manipulating Function for Deleting PDF Pages
add and delete pages in pdf; delete pages pdf files
Cut pages from pdf online - VB.NET PDF Page Delete Library: remove PDF pages in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Visual Basic Sample Codes to Delete PDF Document Page in .NET
delete a page from a pdf online; delete page from pdf
27.6. Examples of page breaking
Theremainder of the \vsplit operation isa box where
all discardables have been removed fromthetop;
glueof size\splittopskip has been inserted on top; if the box being split
was box 255, it already had \topskipglue on top;
its depth has been forced to beat most \splitmaxdepth.
Thebottomoftheoriginalboxisalwaysavalidbreakpointforthe\vsplitoperation.
If this breakpoint is taken, theremainder box register is void. The extracted box can
beempty; it isonly void iftheoriginal box was void, or not a vertical box.
Typically, the \vsplit operation is used to split off part of \box255. By setting
\splitmaxdepth equal to \boxmaxdepth the result is something that could have
been made by T
E
X’s page builder. After pruning the top of \box255, the mark re-
gisters \firstmark and \botmarkcontain the first and last marks on the remainder
of box 255. Seethenext chapter for more information on marks.
27.6 Examplesofpagebreaking
27.6.1 Fillingupapage
Supposeacertain vertical box is too largeto fit on theremainder of thepage. Then
\vfil\vbox{ ... }
isthewrongway tofill up thepageandpush thebox tothenext.T
E
Xcanonly break
at the start of the glue, and the \vfil is discarded after the break: the result is an
underfull, or at least horribly stretched,page.On theother hand,
\vfil\penalty0 % or any other value
\vbox{ ... }
is thecorrect way: T
E
Xwill breakat thepenalty, and thepagewill befilled.
27.6.2 Determiningthebreakpoint
In thefollowingexamples the\vsplitoperation isused, whichhasthesamemecha-
nism aspagebreaking.
Let themacros and parameter settings
\offinterlineskip \showboxdepth=1
\def\High{\hbox{\vrule height5pt}}
\def\HighAndDeep{\hbox{\vrule height2.5pt depth2.5pt}}
begiven.
First let us consider an example where a vertical list is simply stretched in order to
reach abreak point.
\splitmaxdepth=4pt
\setbox1=\vbox{\High \vfil \HighAndDeep}
\setbox2=\vsplit1 to 9pt
VictorEijkhout–T
E
XbyTopic
231
VB.NET PDF Page Extract Library: copy, paste, cut PDF pages in vb.
Ability to copy PDF pages and paste into another PDF file. Security PDF component download. Online source codes for quick evaluation in VB.NET class.
delete pdf pages ipad; delete a page from a pdf in preview
C# PDF Page Extract Library: copy, paste, cut PDF pages in C#.net
NET application. Online C# source code for extracting, copying and pasting PDF pages in C#.NET console class. Support .NET WinForms
delete blank pages from pdf file; add or remove pages from pdf
Chapter27. PageBreaking
gives
> \box2=
\vbox(9.0+2.5)x0.4, glue set 1.5fil
.\hbox(5.0+0.0)x0.4 []
.\glue 0.0 plus 1.0fil
.\glue(\lineskip) 0.0
.\hbox(2.5+2.5)x0.4 []
Thetwo boxestogether haveaheight of 7.5pt, so thegluehasto stretch 1.5pt.
Next,wedecreasethe allowed depth of theresulting list.
\splitmaxdepth=2pt
\setbox1=\vbox{\High \vfil \HighAndDeep}
\setbox2=\vsplit1 to 9pt
gives
> \box2=
\vbox(9.0+2.0)x0.4, glue set 1.0fil
.\hbox(5.0+0.0)x0.4 []
.\glue 0.0 plus 1.0fil
.\glue(\lineskip) 0.0
.\hbox(2.5+2.5)x0.4 []
The reference point is moved down half a point, and the stretch is correspondingly
diminished, but thismotion cannot lead to alarger dimension than was specified.
Asan exampleofthis,consider thesequence
\splitmaxdepth=3pt
\setbox1=\vbox{\High \kern1.5pt \HighAndDeep}
\setbox2=\vsplit1 to 9pt
Thisgivesaboxexactly 9pointshighand 2.5pointsdeep.Setting\splitmaxdepth=2pt
does not increasethe height by half apoint; instead, an underfull box resultsbecause
an earlier break istaken.
Sometimes the timing of actions is important. T
E
Xfirst locates a breakpoint that will
lead to the requested height, then checks whether accommodating the \maxdepth or
\splitmaxdepthwill not violate that height.
Consider an exampleof thistiming: in
\splitmaxdepth=4pt
\setbox1=\vbox{\High \vfil \HighAndDeep}
\setbox2=\vsplit1 to 7pt
theresult isnot aboxof 7 points high and 3 points deep.Instead,
> \box2=
\vbox(7.0+0.0)x0.4
.\hbox(5.0+0.0)x0.4 []
which is an underfull box.
232
VictorEijkhout–T
E
XbyTopic
VB.NET PDF copy, paste image library: copy, paste, cut PDF images
Copy, paste and cut PDF image while preview without adobe Free Visual Studio .NET PDF library, easy to be Online source codes for quick evaluation in VB.NET
delete page in pdf file; reader extract pages from pdf
C# PDF copy, paste image Library: copy, paste, cut PDF images in
C#.NET PDF SDK - Copy, Paste, Cut PDF Image in C#.NET. C#.NET Demo Code: Cut Image in PDF Page in C#.NET. PDF image cutting is similar to image deleting.
delete pages from pdf without acrobat; delete blank page in pdf
27.6. Examples of page breaking
27.6.3 Thepagebuilderafteraparagraph
After aparagraph,thepagebuildermovesmaterialto thecurrentpage, butit doesnot
decide whether abreakpoint has been found yet.
\output{\interrupt \plainoutput}% show when you’re active
\def\nl{\hfil\break}\vsize=22pt % make pages of two lines
a\nl b\nl c\par \showlists
% make a 3-line paragraph
will report
### current page:
[...]
total height 34.0
goal height 22.0
prevdepth 0.0, prevgraf 3 lines
Even though more than enough material has been gathered, \output
isonly invoked when thenext paragraph starts: typing adgives
! Undefined control sequence.
<output> {\interrupt
\plainoutput }
<to be read again>
d
when \outputisinserted after\everypar.
VictorEijkhout–T
E
XbyTopic
233
VB.NET PDF Page Insert Library: insert pages into PDF file in vb.
add and insert one or multiple pages to existing adobe PDF document in VB.NET. Ability to create a blank PDF page with related by using following online VB.NET
delete page on pdf document; delete pdf pages reader
C# PDF Page Insert Library: insert pages into PDF file in C#.net
adding and inserting one or multiple pages to existing Offer PDF page break inserting function. Free components and online source codes for .NET framework 2.0+.
add and delete pages from pdf; delete pages in pdf online
Chapter 28
OutputRoutines
The final stages of page processing are performed by the output routine. The page
builder cuts off a certain portion of the main vertical list and hands it to the output
routinein \box255. This chapter treats thecommands and parameters that pertain to
theoutput routine, and it explainshowoutput routinescan receiveinformationthrough
marks.
\output Token list with instructionsfor shipping out pages.
\shipout Ship aboxto the dvifile.
\mark Specify a mark text.
\topmark Thelast mark on theprevious page.
\botmark Thelast mark on thecurrent page.
\firstmark Thefirst mark onthecurrent page.
\splitbotmark Thelast mark on asplit-off page.
\splitfirstmark Thefirst mark on a split-offpage.
\deadcycles Counter that keeps track of how many times the output routine has
been called without a\shipouttaking place.
\maxdeadcycles The maximum number of times that the output routine is allowed
to becalled without a\shipoutoccurring.
\outputpenalty Value of the penalty at the current page break, or 10000 if the
break wasnot at apenalty.
28.1 The\outputtokenlist
Common parlance has it that ‘the output routine is called’ when T
E
X has found a
placetobreak themainvertical list. Actually, \outputisnotamacrobut atokenlist
that isinserted into T
E
X’s command stream.
Insertion of the \output token list happens inside a group that is implicitly opened.
Also, T
E
X enters internal vertical mode. Because of the group, non-local assignments
(to the page number, for instance) have to be prefixed with \global. The vertical
modeimplies that during the workingsof the output routine spaces are mostly harm-
less.
234
C# HTML5 PDF Viewer SDK to view PDF document online in C#.NET
Image: Copy, Paste, Cut Image in Page. Link: Edit Redact Text Content. Redact Images. Redact Pages. Annotation & Text. Add Text Box. Drawing Markups. PDF Print. Work
delete page from pdf preview; delete pdf pages in reader
VB.NET PDF- View PDF Online with VB.NET HTML5 PDF Viewer
from PDF Page. Image: Copy, Paste, Cut Image in Redact Text Content. Redact Images. Redact Pages. Annotation & Add Text. Add Text Box. Drawing Markups. PDF Print.
copy pages from pdf into new pdf; copy pages from pdf to new pdf
28.2. Output and \box255
The \outputtoken list belongs to the classof the token parameters. These behave
the same as \toksnnn token lists; see Chapter 14. Assigning an output routine can
thereforetakethe following forms:
\outputequalsgeneraltext or \outputequalsfillertokenvariable
28.2 Outputand\box255
T
E
X’s pagebuilder breaks thecurrent page at theoptimal point, andstores everything
above that in \box255; then, the \output tokens are inserted into the input stream.
Any remaining material on the main vertical list is pushed back to therecent contri-
butions. Ifthepageis brokenat apenalty,that valueisrecorded in \outputpenalty,
and a penalty of size 10000 is placed on top of the recent contributions; otherwise,
\outputpenalty is set to 10000. When the output routine is finished, \box255 is
supposed to beempty. If it is not,T
E
Xgivesan errormessage.
Usually, the output routine will take the pagebox, append a headline and/or footline,
maybemerge in some insertionssuch as footnotes, and ship thepage to the dvifile:
\output={\setbox255=\vbox
{\someheadline
\vbox to \vsize{\unvbox255 \unvbox\footins}
\somefootline}
\shipout\box255}
Whenbox 255 reachestheoutputroutine,itsheighthasbeen setto\vsize.However,
thematerial in itcan haveconsiderably smaller height. Thus, theaboveoutputroutine
may lead to underfull boxes.Thiscan beremedied with a \vfil.
The output routineis under no obligation to do anything useful with \box255; it can
empty it, or unbox it to let T
E
Xhaveanother go at finding apagebreak. Thenumber
of timesthattheoutputrouting postponesthe\shipoutisrecordedin \deadcycles:
thisparameterissetto0 by \shipout,andincreasedby1 just beforeevery\output.
When the number of dead cycles reaches\maxdeadcycles, T
E
X gives an error mes-
sage, and performs thedefault output routine
\shipout\box255
insteadoftheroutineit was about to start. TheLAT
E
Xformat hasamuch higher value
for \maxdeadcycles than plain T
E
X, because the output routine in LAT
E
X is often
called forintermediatehandling offloatsand marginal notes.
The \shipout command can send any box to the dvi file; this need not be box
255, or even a box containing the current page. It does not have to be called inside
theoutput routine, either.
If theoutput routineproduces any material,for instanceby calling
\unvbox255
VictorEijkhout–T
E
XbyTopic
235
VB.NET PDF: Basic SDK Concept of XDoc.PDF
example, you may easily create, load, combine, and split PDF file(s), and add, create, insert, delete, re-order, copy, paste, cut, rotate, and save PDF page(s
cut pages from pdf preview; delete a page from a pdf
Chapter28. Output Routines
thisis put on top of therecent contributions.
After the output routine finishes, the page builder is activated. In particular, because
the current page has been emptied, the \vsize is read again. Changes made to this
parameterinsidetheoutput routine(using \global)will thereforetakeeffect.
28.3 Marks
Information can be passed to the output routine through the mechanism of ‘marks’.
Theusercan specify atoken list with
\mark{mark text}
which is put in a mark item on the current vertical list. The mark text is subject to
expansion asin \edef.
If the mark is given in horizontal mode it migrates to the surrounding vertical lists
like an insertion item (see page 76); however, if this is not the external vertical list,
theoutput routine will not find themark.
Marks are the main mechanism through which the output routine can obtain infor-
mation about the contents of the currently broken-off page, in particular its top and
bottom.T
E
Xsets three variables:
\botmark thelast mark occurring on the current page;
\firstmark thefirst markoccurring on thecurrent page;
\topmark thelast mark of the previous page, that is, the value of \botmark on the
previouspage.
Ifnomarkshaveoccurred yet,all threeareempty;ifnomarksoccurredonthecurrent
page, all threemark variables areequal to the\botmark of the previouspage.
Forboxesgeneratedbya\vsplitcommand (seepreviouschapter),the\splitbotmark
and \splitfirstmarkcontainthemarksofthesplit-offpart;\firstmarkand\botmark
reflect thestate of what remains in theregister.
Markscan beused to get asection heading into theheadlineorfoot-
line of the page.
\def\section#1{ ... \mark{#1} ... }
\def\rightheadline{\hbox to \hsize
{\headlinefont \botmark\hfil\pagenumber}}
\def\leftheadline{\hbox to \hsize
{\headlinefont \pagenumber\hfil\firstmark}}
This places the title of the first section that starts on a left page in
the left headline, and the title of the last section that starts on the
right page in theright headline. Placing theheadlines on thepageis
thejob of theoutput routine; seebelow.
It is important that no page breaks can occur in between the mark
and thebox that placesthetitle:
236
VictorEijkhout–T
E
XbyTopic
28.4. Assorted remarks
\def\section#1{ ...
\penalty\beforesectionpenalty
\mark{#1}
\hbox{ ... #1 ...}
\nobreak
\vskip\aftersectionskip
\noindent}
Letusconsideranotherexamplewith headlines: oftenapagelooks better ifthehead-
lineis omitted on pageswhereachapterstarts. Thiscan be implemented as follows:
\def\endofchapter
\chapter#1{ ... \def\chtitle{#1}\mark{1}\mark{0} ... }
\def\theheadline{\expandafter\ifx\firstmark1
\else \chapheadline \fi}
Only on the pagewhereachapter startswill themark be 1, and on all other pagesa
headlineisplaced.
28.4 Assortedremarks
28.4.1 Hazardsinnon-trivialoutputroutines
If thefinal call to theoutput routine doesnot perform a\shipout, T
E
Xwill call the
output routine endlessly, since a run will only stop if both the vertical list is empty,
and \deadcyclesiszero.Theoutputroutinecanset \deadcyclesto zero to prevent
this.
28.4.2 Pagenumbering
The page number is not an intrinsic property of the output routine; in plain T
E
X it
is the value of \count0. The output routine is responsible for increasing the page
numberwhen ashipout of apageoccurs.
Apart from \count0, counter registers 1–9 are also used for page identification: at
shipout T
E
Xwrites the values of these ten counters to thedvi file (see Chapter 33).
Terminaland log fileoutput display only thenon-zero counters,and thezero counters
for which a non-zero counter with a higher number exists, that is, if \count0 =
1 and \count3 = 5 are the only non-zero counters, the displayed list of counters
is [1.0.0.5].
28.4.3 HeadlinesandfootlinesinplainT
E
X
Plain T
E
X has token lists \headline and \footline; these are used in the macros
\makeheadlineand \makefootline.Thepage is shippedout as(moreor less)
\vbox{\makeheadline\pagebody\makefootline}
Both headlineand footlineare inserted inside a\line. For non-standard headers and
footers it is easier to redefine the macros \makeheadline and \makefootline than
to tinkerwith thetoken lists.
VictorEijkhout–T
E
XbyTopic
237
Chapter28. Output Routines
28.4.4 Example:nowidowlines
Suppose that one does not want to allow widow lines, but pages have in general no
stretch or shrink, for instance because they only contain plain text. A solution would
beto increasethepagelengthbyonelineifapageturnsouttobebrokenat awidow
line.
T
E
X’s output routine can perform this sort of trick: if the \widowpenalty is set to
some recognizable value, the output routine can see by the \outputpenalty if a
widow line occurred. In that case, the output routine can temporarily increase the
\vsize,and let thepagebuilder haveanother go at finding abreak point.
Hereis theskeleton ofsuch anoutput routine.Noheadersorfootersareprovidedfor.
\newif\ifLargePage \widowpenalty=147
\newdimen\oldvsize \oldvsize=\vsize
\output={
\ifLargePage \shipout\box255
\global\LargePagefalse
\global\vsize=\oldvsize
\else \ifnum \outputpenalty=\widowpenalty
\global\LargePagetrue
\global\advance\vsize\baselineskip
\unvbox255 \penalty\outputpenalty
\else \shipout\box255
\fi
\fi}
The test \ifLargePage is set to true by the output routine if the \outputpenalty
equalsthe\widowpenalty.Thepagebox isthen\unvboxed,sothatthepagebuilder
will tacklethe samematerial oncemore.
28.4.5 Example:noindentationtopofpage
Someoutput routines can beclassified asabuseoftheoutput routinemechanism. The
output routinein thissection isa good example of this.
It is imaginable that onewishes paragraphs not to indent if they start at thetop of a
page. (Thereare plenty of objections to this layout, but occasionally it is used.) This
problemcan besolved using theoutput routineto investigatewhether thepageis still
emptyand,if so,to givea signal that aparagraph should not indent.
Notethat we cannot usethefact here that thepagebuilder comes into play after the
insertionof\everypar:evenifwecould forcetheoutput routinetobeactivatedhere,
thereis no way for it to removetheindentation box.
Thesolution given herelets the\everyparterminatetheparagraph immediately with
\par\penalty-\specialpenalty
which activatestheoutput routine. Seeing whether thepagebox is empty (after remo-
ving theempty lineand any \parskipglue), theoutput routinethen can set aswitch
signalling whether theretry of the paragraph should indent.
238
VictorEijkhout–T
E
XbyTopic
28.4. Assorted remarks
Therearesome minor matters inthefollowing routines, thesenseof whichis left for
thereader to ponder.
\mathchardef\specialpenalty=10001
\newif\ifPreventSwitch
\newbox\testbox
\topskip=10pt
\everypar{\begingroup \par
\penalty-\specialpenalty
\everypar{\endgroup}\parskip0pt
\ifPreventSwitch \noindent \else \indent \fi
\global\PreventSwitchfalse
}
\output{
\ifnum\outputpenalty=-\specialpenalty
\setbox\testbox\vbox{\unvbox255
{\setbox0=\lastbox}\unskip}
\ifdim\ht\testbox=0pt \global\PreventSwitchtrue
\else \topskip=0pt \unvbox\testbox \fi
\else \shipout\box255 \global\advance\pageno1 \fi}
28.4.6 Moreexamplesofoutputroutines
Alargenumber ofexamples of output routinescan befound in [38]and [39].
VictorEijkhout–T
E
XbyTopic
239
Documents you may be interested
Documents you may be interested