Making Latex typeset given text on two facing pages
Asked Answered
S

2

6

How do I encourage/make Latex typeset some portion of text so that it will all appear on a consecutive even-page, odd-page pair of pages?

With trial and error, \nopagebreak can be coaxed into doing this, but is there a strategy that Just Works? Something like a samepage environment would be ideal, but one that:

  1. Will force a pagebreak on odd pages if that is needed to get all the text on facing pages;
  2. Allows up to one page break anywhere in the environment body, and fails noisily if that can't be ensured.
Southerly answered 7/2, 2010 at 17:17 Comment(0)
E
6

You could put together an environment such as

\newenvironment{twopage}{%
  \begingroup\setbox0\vbox\bgroup
}{%
  \egroup
  \ifdim\ht0>\textheight
    \setbox1\vsplit0 to \textheight
    \cleardoublepage\unvbox1\clearpage
    \ifdim\ht0>\textheight
      \PackageWarning{twopage}{Overflow in twopage environment}%
    \fi
    \unvbox0\clearpage
  \else
    \clearpage\unvbox0\clearpage
  \fi\endgroup
}

If you want a noisier failure, change \PackageWarning into \PackageError, The \unvboxes should allow for notes/floats to work properly - if you don't need that, you might consider changing them all to \boxes instead (although I'm a bit rusty on the behavior of \vsplit with respect to box depths and skips, so that might produce funny behavior, but it would guarantee that you only took two pages by flowing anything extra off the bottom of the second page).

Entourage answered 13/3, 2010 at 0:28 Comment(2)
Accepted: This seems to be perfect. Am I right that the point of the \unvbox is to stop spurious space, because otherwise \vsplit would make sure box 1 was exactly \textheight high?Southerly
The \unvbox has two main effects, both of which have to do weith making it behave as if there were no enclosing environment. The first is that any whatsits/\vadjusts (used by \mark, \footnote, \marginpar, etc) don't work properly inside boxes, since they want to be "top-level" in the shipped-out page (the boxes aren't recursed). The other has to do with space - I don't recall off-hand \vsplit's behavior, but I believe there is a difference between foo\par\vbox{bar\par baz}\par qux and foo\par bar\par baz\par qux, and it seemed to me that we wanted the latter.Entourage
S
3

There is a distinction between \clearpage and \cleardoublepage. By using \cleardoublepage just before the stuff you want on the left hand side and \clearpage before the stuff you want on the right hand side you can force the layout you're looking for.

Of course, the twoside option is must.

Seen answered 7/2, 2010 at 17:24 Comment(1)
Technically, yes, this answers the question I've asked, but I'm actually after something analogous to samepage: I don't want any breaks unless they are needed to keep the text on the facing pages. Your suggestion will ensure the text is on facing pages, but it's pretty eager to make page breaks.Southerly

© 2022 - 2024 — McMap. All rights reserved.