# ledpar: How to force a pagebreak in {pages}-environment/stanzas?

How can I force a pagebreak in ledpar’s {pages}-environment between to \stanzas or even between two lines of a single \stanza? The reason for my question is that ledpar sometimes breaks the page between a verse an it’s continuation in the next line, e.g.

This is a verse is to long to fit in
ledpar inserts a pagebreak here —
(indent) a single line

That’s not good to read an I want to force a pagebreak before “This is …”

In a comment at “ledmac/-par: No versesyncing but pagesyncing” diabonas suggests to stop the left-/rightpage/\Pages-construc manually to force a pagebreak but I hope there’s a more elegant way …?

This is a minimal example for testing. I’ve tried three versions; related code is marked with [n].

\documentclass{scrartcl}
\usepackage{geometry}% very small pages to see an effect
\geometry{paperheight=4cm,paperwidth=6cm,vmargin=1cm}
\usepackage{ledmac,ledpar}

\begin{document}
\begin{pages}
\begin{Leftside}
\beginnumbering
\setstanzaindents{2,0,0,0}
\stanza 1 & 2 & 3 \&
\stanza 4 & 5 & 6 \&
%   \stanza\pagebreak\&% [1] doesn't work
%   \pagebreak% [2,3] doesn't work too
\stanza 7 & 8 & 9 \&
\endnumbering
\end{Leftside}
\begin{Rightside}
\beginnumbering
\setstanzaindents{2,0,0,0}
\stanza one & two & three \&
\stanza four & five & six \&
%   \stanza\pagebreak\&% [1] doesn't work
%   \pagebreak% [3] doesn't work too
\stanza seven & eight & nine \&
\endnumbering
\end{Rightside}
\Pages
\end{pages}
\end{document}

-

This solution is certainly no "more elegant way" in terms of beautiful coding - it's the exact opposite indeed! - but it seems to work:

## Code:

\usepackage{etoolbox}
\makeatletter
\newcommand*{\pageisfull}{\def\checkpageL{\l@dpagefulltrue\l@dsamepagefalse}}
\newcommand*{\fakelineL}{{\ledRcolfalse\new@line\startlock\skipnumbering\endlock\null}}
\newcommand*{\fakelineR}{{\ledRcoltrue\new@lineR\startlock\skipnumbering\endlock\null}}
\patchcmd{\Pages}{\hb@xt@ \hsize{\ledstrutL\unhbox\l@dleftbox}}{\ifdim\dp\l@dleftbox=12mm\pageisfull\fakelineL\else\hb@xt@ \hsize{\ledstrutL\unhbox\l@dleftbox}\fi}{}{}
\patchcmd{\Pages}{\hb@xt@ \hsize{\ledstrutR\unhbox\l@drightbox}}{\ifdim\dp\l@drightbox=12mm\fakelineR\else\hb@xt@ \hsize{\ledstrutR\unhbox\l@drightbox}\fi}{}{}
\makeatother
\newcommand*{\ledparpagebreak}{\stanza\strut\vrule depth12mm\&}


## Explanation:

The central output routine \Pages is modified in order to check wether the box to be inserted has a depth of 12mm. This is rather unrealistic for normal boxes, so it will serve as a marker for a page break at this point. If such a special box is found, it isn't output - instead, the newly defined macros \fakelineL/\fakelineR and \pageisfull are executed:

The \fakeline. commands behave if there really was a line to be inserted, but they execute the necessary macros to skip the number for this line. This may sound weird, but it proves to be necessary to (hopefully) get correct line numbers.

The macro \pageisfull hacks \checkboxL which controls if a page break is needed so that it forces a new page. (This redefinition is local because it is inside a group in \Pages, so we don't have to reset the change as this is done automatically at the end of the group.)

Now we just have to define a macro \ledparpagebreak which inserts such a box of depth 12mm to be able to control the page breaking: It starts a new stanza (otherwise, the output routine can't handle it correctly) with a \vrule set to the desired depth.

## Usage:

Just add the code to your LaTeX document after you have loaded ledpar. You can then use \ledparpagebreak between two stanzas to insert a page break at this point. Make sure to use the command in both columns (after corresponding stanzas, otherwise you may observe weird behaviour...).

You can use this hack parallel to the patch suggested in the answer to your related question as both should be compatible.

## WARNING:

As I said, this is no clean approach at all, I can't guarantee correct behaviour, especially regarding consistent line numbering, in all cases (it worked properly with my test texts, though).

It may be a better idea to take advantage of the so-called "action-code list" ledmac introduces: It seems to me that it is specially made in order to do special tasks at certain lines, like starting a new page. However, I do not understand the internals of ledmac/ledpar well enough to use it.

-
Thank you very much (especial for explaining your code in detail)! I’ll try it when finally typesetting the document and report about—hopefully—success or not … –  Tobi Apr 24 '11 at 23:59
ps. Did you only read the manual to get this idea/solution or are there any further informations the I’ve overlooked? –  Tobi Apr 24 '11 at 23:59
Hy, the translation is finished now and I tried your soulution but it causes some strange errors (e. g. print all verse nums in footnotes as 0) that I don’t comprehend. The other solution I found is to put an invisible rule in the line before the break to make it long enough to fill the page (I set the rule via \newcommand{\ledstrut}[1]{\rule[-#1]{0pt}{#1}}). That works for me and don’t causes problems—at least as far as I can see … Thank you again for your help! –  Tobi Jun 25 '11 at 9:18
@diabonas : I just tried your solution without stanza in my document and it seems to work. However, the linecounter seems to miss a line: ... - 73 - 74 - pagebreak - 76 - 77 - .... Pther than that, I really like your solution! –  ClintEastwood Feb 27 at 17:12