Is it possible to tell LaTeX not to break a page except at a paragraph break (i.e. only break pages at the end of a paragraph)?
I've still had no luck in trying to get this to work by changing the page width inside a paragraph. According to a friend of mine, I've accidentally hit one of the fundamental limitations of TeX identified by Knuth, in that you can't change the text width between pages, only between paragraphs, because paragraphs are built asynchronously before pages are built. I haven't found any way to confirm this — I remember reading Knuth's limitations of TeX online, but now I can't find them.
I still think that there may be a way around this, if I can use code similar to multicol's rebalancing mechanism to force TeX to tear apart the end of the paragraph at the top of the page and lay it out again. This sounds quite hard to get working, and I think I'd rather concentrate on other things just now.
So, as a stop-gap measure, I'm trying to force TeX to only break pages at paragraph breaks.
My first thought was to inject a pagebreak hint in between each paragraph. Here's my minimal example:
Code: Select all
\documentclass{article}
\usepackage{lipsum}
\newcommand{\lip}[1]{\section{#1}\lipsum[0-20]\pagebreak}
\begin{document}
\lip{No pagebreak}
\def \par {\pagebreak[3] \endgraf}
\lip{pagebreak 3}
\def \par {\pagebreak[4] \endgraf}
\lip{pagebreak 4}
\def \par {\pagebreak \endgraf}
\lip{pagebreak}
\end{document}
The problem here is that \pagebreak[3] (and [1] and [2] for that matter) will cause LaTeX to break the last paragraph on the first page, while \pagebreak[4] will cause it to break the page between each and every paragraph.
I guess I could fiddle around with some sort of tolerance setting and get something that would work for this lipsum text, but I would like to know that it would work properly regardless of what text I throw at it (at least if it's not taken to extremes, eg a paragraph longer than a page).
Is there some other way I could achieve this? I want to have the last full paragraph always be at the end of the page so that there are no page breaks between paragraphs, and (ultimately) the next page could be set with a different \hsize?
My second idea was to put each paragraph in a samepage environment by modifying \par, but I haven't got that to work at all. With plain text, I just get the pagebreak in the middle of a paragraph (apparently inside the samepage environment?!):
Code: Select all
\documentclass{article}
\usepackage{lipsum}
\newenvironment{pagebreakatpara}{
\begin{samepage}
\gdef\par{
\end{samepage}
\endgraf
\begin{samepage}
}
}{
\end{samepage}
\gdef\par{\endgraf}
}
\begin{document}
\begin{pagebreakatpara}
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
\end{pagebreakatpara}%
\end{document}
And replacing the text with a lipsum, I get an error:
Code: Select all
\documentclass{article}
\usepackage{lipsum}
\newenvironment{pagebreakatpara}{
\begin{samepage}
\gdef\par{
\end{samepage}
\endgraf
\begin{samepage}
}
}{
\end{samepage}
\gdef\par{\endgraf}
}
\begin{document}
\begin{pagebreakatpara}
\lipsum
\end{pagebreakatpara}%
\end{document}
! Undefined control sequence.
\lips@dolipsum ...m \value {lips@count}<\lips@max
\relax \addtocounter {lips...
l.19 \end
{pagebreakatpara}%
! Missing number, treated as zero.
Any help as to what I am doing wrong, or alternative approaches I could take, would be most appreciated!
Thanks in advance,
—Robert J Lee