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.

Colas
  • 6,772
  • 4
  • 46
  • 96

1 Answers1

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.)

Mico
  • 506,678