15

I think I understand the difference between newpage and pagebreak.

My question mostly comes out os curiosity. I came across this way to get a new page: \vfill\eject. What is the difference between this and just \newpage (or \pagebreak). Does it have an advantage?

3
  • \vfill and \eject are tex primitives. they are used to define the latex commands \newpage and \pagebreak, but the latter contain additional checks. Oct 23, 2014 at 20:42
  • @barbarabeeton are you sure \eject is primitive:-) Oct 23, 2014 at 20:55
  • @DavidCarlisle -- ya got me. \eject is defined in plain.tex as {\par\penalty-10000 } (texbook version). it is "pre-latex", however. Oct 23, 2014 at 21:02

1 Answer 1

15

There is a big difference between \newpage and \vfill\eject.

  • Definition of \newpage in LaTeX

    % latex.ltx, line 6342:
    \def \newpage {%
      \if@noskipsec
        \ifx \@nodocument\relax
          \leavevmode
          \global \@noskipsecfalse
        \fi
      \fi
      \if@inlabel
        \leavevmode
        \global \@inlabelfalse
      \fi
      \if@nobreak \@nobreakfalse \everypar{}\fi
      \par
      \vfil
      \penalty -\@M}
    
  • Definition of \eject in Plain TeX

    % plain.tex, line 558:
    \def\break{\penalty-\@M}
    
    % plain.tex, line 564:
    \def\eject{\par\break}
    

LaTeX tries first to catch problems with \everypar; if \newpage is given in sectional titles or immediately after or else in lists, some countermeasures are taken.

After this the working is almost identical, but you can notice that \newpage issues \vfil, because of how it deals with \flushbottom and \raggedbottom. Both constructions end with \penalty-10000 that forces a page break.

4
  • 2
    Thanks for this detailed answer. Would you be able to express this in more layman's terms?
    – Thomas
    Oct 25, 2014 at 12:12
  • @Thomas What's before \par in the definition of \newpage is somewhat technical; LaTeX, in some circumstances, sets some parameters in a way that's not appropriate for normal text and in those cases simply issue the penalty for forcing the page break would give wrong results.
    – egreg
    Oct 25, 2014 at 15:45
  • Does the term \eject has any roots in typography?
    – Viesturs
    Nov 12, 2021 at 5:21
  • @Viesturs I don't think so. The idea is that the completed page box is pushed out of TeX's memory.
    – egreg
    Nov 12, 2021 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.