\documentclass[a4paper]{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]\filbreak
\textbf{This should fit on page 1}~\lipsum[5]\filbreak\lipsum[6-10]\filbreak
\textbf{This should not fit on page 2}~\lipsum[11-12]\filbreak\lipsum[13-19]
\end{document}
The problem arises with the last \filbreak in this example. It flushes \lipsum[13-19] to the next page. I want to replace the last \filbreak it with a command \stopfilbreak, so that since \lipsum[11-12] actualy didn't fit on page 2, then it would put \lipsum[11-12] on page 3 with \lipsum[13-19] following it (on page 3). Now it sets \lipsum[13-19] on page 4.
I want a command \stopfilbreak such that LaTeX interprets "fit the content between \filbreak and \stopfilbreak on the same page if possible, else break the page here and put it on a new page". The content to come after \stopfilbreak should not be affected.
That is: i want a command that restores the normal flow after use of \filbreak
Be aware that it might be so that what would go between \filbreak and \stopfilbreak could be larger than a pagewidth, so minipage would not work.
Below is some background info that I think might be helpful to answer my question:
Background info
Purpose of \filbreak
The TeXbook says that \filbreak means roughly
“Break the page here and fill the bottom with blank space, unless there is room for more copy that is itself followed by \filbreak.”
That is, if we consider content that is "enclosed" by \filbreaks, it inserts this content if there is room on the page, but goes to the next page if there is no room.
\filbreak in practice
\filbreak is defined by \par\vfil\penalty-200\vfilneg. As I understand it, this finishes up the current paragraph, then fills the page with stretchable whitespace and then, at the bottom of the page/top of new page it says that "breaking" here is cheap. If the program then decides to break here, then the \vfilneg doesn't do anything because there is no \vfil to "neg", but if it doesn't then \vfilneg puts the "cursor" back.
I'm not using \filbreak as it was purposed. Everything in my VC-example works as expected, which indicates that I might be asking the wrong question?
\filbreakis mistaken or at least imprecise. It does not really check or insert anything; it merely inserts a particular sequence of glue and penalties, which are used by the page builder whenever it decides to look for appropriate places to break the page. Rather than go by the informal description in The TeXbook, see the definition you've included. Anyway, it's not clear what you want exactly: where do you want the page breaks to happen / what would you like the general behaviour to be? – ShreevatsaR Apr 29 '18 at 10:12\filbreakis wrong. I get that it doesn't "check" anything, I just had problems wording this, which results in that my description of how\filbreakworks is imprecise. Maybe it's just confusing to have the Background info in there?I suspect you missed the "TL;DR"-section in the top (maybe because you read all the rest)? I thought it was quite clear there what I wanted to achieve. If I'm wrong, and you did read it, let me know what is unclear so I can clarify!
– Andreas Storvik Strauman Apr 29 '18 at 10:21\outputpenaltycannot be used in that way to discriminate the two cases. – GuM Apr 29 '18 at 17:26\endfilbreak(or replace/define it with nothing), then I get 3 pages, with 1–4 on the first page, 5–9 on the second page, and 10 on the third page. So your example does not actually illustrate any problem, because it seems that an empty definition of\endfilbreakmatches the thing you want (“\lipsum[6-10]should always come right after\lipsum[5]”). Do you have a more illuminating example perhaps? – ShreevatsaR Apr 30 '18 at 00:17The comment about GuM not understanding the question was from his previous answer. His answer now works as expected! :)
– Andreas Storvik Strauman Apr 30 '18 at 06:41\lipsum[13-19]preceding it (on page 3)” you mean “following” instead of “preceding” (the opposite). Otherwise it seems magical…. (2) You want to replace the last\filbreakwith a\stopfilbreak, but it is still the case that if I replace the last\filbreakwith nothing, then everything seems to satisfy your requirements. So empty definition of\stopfilbreakstill works? – ShreevatsaR Apr 30 '18 at 07:48\lipsum[11-12]would fit or not. – Andreas Storvik Strauman Apr 30 '18 at 07:53\lipsum[11-12]) within some macros, with the intended meaning being: “fit this stuff on the same page if possible, else break the page here and put it on a new page”. And of course, what comes later should not be affected. Is that correct? (You propose\filbreak ...\stopfilbreakas the intended form of these macros, but if I understand your true goal correctly, then you just care about these semantics/behaviour, and the macros don't necessarily have to take this exact form.) – ShreevatsaR Apr 30 '18 at 08:03\filbreakused, but to my use, having them as macros are necessary. I hope it's okay with you if I insert your formulation into my question? – Andreas Storvik Strauman Apr 30 '18 at 08:08