4

I would like to disable the command \newpage.

I did the following but it does not work.

\documentclass{article}

\renewcommand{\newpage}{}

\begin{document}

\begin{itemize}
\item A
\item B
\newpage
\item C
\end{itemize}

\end{document}

Thank you for your help.

9
  • 3
    well.... it works, \newpage is disabled so in particular the \newpage that is in\end{document} doesn't happen and no page is shipped out. beware what you ask for. Dec 15, 2020 at 21:21
  • you probably just want to do the redefinition in some group eg inside the itemize in this example. Dec 15, 2020 at 21:21
  • 1
    Why? isn't it simpler and safer not use it?
    – Zarko
    Dec 15, 2020 at 21:21
  • @Zarko: thank you!!!
    – Colas
    Dec 15, 2020 at 21:22
  • 2
    @Colas note \newpage is used in \clearpage and as such is vital for the float mechanism, if you disable it and use figures or tables they are likely to get lost or the document not terminate Dec 15, 2020 at 21:51

1 Answer 1

7

I suggest you include the following code in the preamble:

\usepackage{etoolbox}
\AtBeginDocument{%
    \let\orignewpage\newpage 
    \renewcommand\newpage{}
    \patchcmd{\clearpage}{\newpage}{\orignewpage}{}{}}

That way, the code chunk

\begin{itemize}
\item A
\item B
\newpage
\item C
\end{itemize}

is assured not to generate a page break between items B and C.

Observe that it's very necessary to patch \clearpage, since \clearpage contains a \newpage directive internally and because \clearpage is used by quite a few LaTeX macros, including the \enddocument macro that's run when \end{document} is encountered. For more on the subject of \newpage vs. \clearpage, see the posting Is it wrong to use \clearpage instead of \newpage? (shameless self-citation alert!)

(If other LaTeX macros contain a \newpage directive internally, those macros would need to be patched as well. One such macro, which is defined by the LaTeX kernel, is \cleardoublepage. Fortunately (?) for you, \cleardoublepage doesn't get used by the article document class unless the options \twoside and \openright are both set.)

1
  • 5
    +1 for rescuing the float mechanism :-) Dec 15, 2020 at 21:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .