Preventing page breaks (needspace)
![](https://secure.gravatar.com/avatar/b44fb78f61a9ba4f7ddfa7cb863d9897.jpg?s=120&d=mm&r=g)
While using \obeylines for some poetry there would sometimes be page breaks in the middle of stanzas, even if there was very stretchy space on either side. So I borrowed some code from needspace.sty, basically to tell TeX I'd be much happier w/ a ragged bottom than a break between lines: \def\needspace#1{% \begingroup \vskip#1\lineheight\penalty -100\vskip-#1\lineheight \vskip#1\lineheight\penalty 9999\vskip-#1\lineheight \endgroup} So if there is a stanza of four lines that *really* shouldn't be split across pages, it looks like this: \needspace{4} Line 1 Line 2 Line 3 Line 4 However, I suspect I'm not the first person to run into this. So my question is if there is a more ConTeXt-y way to do this? Or does ConTeXt already have something to do this?
![](https://secure.gravatar.com/avatar/c5ae4f9aa0d3a9bd5376e92b322c3e50.jpg?s=120&d=mm&r=g)
On Sat, 24 Jun 2006, Joshua Ellis wrote:
While using \obeylines for some poetry there would sometimes be page breaks in the middle of stanzas, even if there was very stretchy space on either side. So I borrowed some code from needspace.sty, basically to tell TeX I'd be much happier w/ a ragged bottom than a break between lines:
\def\needspace#1{% \begingroup \vskip#1\lineheight\penalty -100\vskip-#1\lineheight \vskip#1\lineheight\penalty 9999\vskip-#1\lineheight \endgroup}
So if there is a stanza of four lines that *really* shouldn't be split across pages, it looks like this:
\needspace{4} Line 1 Line 2 Line 3 Line 4
However, I suspect I'm not the first person to run into this. So my question is if there is a more ConTeXt-y way to do this? Or does ConTeXt already have something to do this?
\testpage[4] will check if there is space for 4 lines, and would otherwise cause a pagebreak. I do not know how testpage compares with needspace defined above. Aditya
participants (2)
-
Aditya Mahajan
-
Joshua Ellis