TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to answer to Include a cover page then title page in book class I've found that \newpage only creates a new page if there is some contents, i.e.,

\documentclass{article}
\begin{document}
\newpage
\end{document}

doesn't produce any result (no pdf file) while

\documentclass{article}
\begin{document}
\null\newpage
\end{document}

does it (empty page with 1 on footer). Instead of \null, \mbox{} also works. Could you explain why?

My understanding is that an empty page is not empty because LaTeX automatically introduces headers and footers. I was using \pagestyle{empty} or \thispagestyle{empty} could understand it, but first code doesn't fit this case.

share|improve this question
1  
Very informal idea: Well, to create a new page \newpage you need at least one page, otherwise you can not go to the next one. So, a page must contain at least an empty char. – Sigur Jan 26 at 18:08
up vote 16 down vote accepted

Headers and footers are added after TeX has decided it wants to do a page break, so the fact that they are empty or not is completely irrelevant.

A page must have something non discardable in it (a box, a rule, a whatsit), because discardable items (glue, penalties, kerns) are discarded at a page break.

So doing \newpage\newpage does not produce a blank page because, when issued in vertical mode, it essentially does

\vfil
\penalty-10000

Note that the start of a document is implicitly considered as a page break, so initial discardable items are indeed discarded. That's the same reason why you get no vertical space when you do

\begin{document}
\vspace{10cm}
Hello world
\end{document}

and “Hello world” will appear at the top.

The macro \null does \hbox{}, so it provides a box. A better method for adding something invisible is doing

\vspace*{0pt}

There's a very good reason for this: after the final \clearpage (that implicitly calls \newpage) issued by \end{document}, TeX is still doing its work and it's ready to make a new page, because pending floats might remain. If its behavior was changed to allow \newpage making a page without non discardable items, you'd always get a blank page at the end.


This is the full definition of \newpage:

% latex.ltx, line 6503 (2015/10/01 patch level 2)
\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}

This opens the problem of where \if@noskipsec is true; well, it is at startup, but it is set to false at \begin{document} and back to true when a run-in section title is being typeset. The command \@nodocument is responsible of issuing an error message if some text is typeset before \begin{document}, but is later set to be equivalent to \relax. So the purpose of the first conditional is to put things into order when something like \paragraph{Title}\newpage is found.

The conditional \if@inlabel is true when LaTeX is processing an \item, so that part is for recovering from input such as \item\newpage. Finally \if@nobreak is true when LaTeX has typeset a “block” sectional title (\section, for instance) and, again, this is for recovering from something like \section{Title}\newpage.

So the initial part is just code that tries to avoid later problems in presence of disputable code. If none of those (hopefully) rare situations occurs, then just \par\vfil\penalty-10000 is issued. Note that \par is normally implicit in \vfil, but just in case the user has redefined \vfil, it is issued nonetheless.

I don't recommend \leavevmode\newpage that still appears to work; the command does start a paragraph, contributing \parskip glue and \baselineskip glue too. To the contrary, \null or \vspace*{0pt} just contribute a box/rule of zero height and depth (the latter also a 10000 penalty and zero glue), with no \parskip and \baselineskip glue.

Not a big deal, actually, since we're analyzing the problem of making an apparently empty page: a blank box, an invisible rule or a blank paragraph don't make such a big difference, but the less we contribute the better. Starting a paragraph also frees the contents of \everypar, which can have some side effect in some situations.

share|improve this answer
1  
+1. Could you explain why \vspace*{0pt} is better? – Sigur Jan 26 at 18:36
2  
@Sigur Because it's documented in the manual and \null isn't. – egreg Jan 26 at 18:36
    
I'd have issued \leavevmode\newpage. – A.Ellett Jan 26 at 19:16
    
@A.Ellett \leavevmode isn't a documented latex command either and the behaviour of \leavevmode\newpage is much more complicated to analyse (and less desirable) than either null or vspace* (I'll leave that to egreg:-) – David Carlisle Jan 26 at 20:23
1  
@DavidCarlisle So that opens a question for me: what does "documented LaTeX command" mean? Since, after all, I can find \leavevmode in source2e but I can't find \vspace*{0pt} in source2e. Where should I be looking for such documentation? – A.Ellett Jan 26 at 20:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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