I write a lot of documents (agreements) based on memoir with the article option. Normal pagestyleis plain (page number centered in the footer). Sometimes a document is only one page long, and a page number is unnecessary.
It is not much work to put a \thispagestyle{empty} after \maketitle (because \maketitle has hardcoded a \thispagestyle{plain} somewhere). But sometimes I forget this, and sometimes I add a word or two, and the document suddenly is two pages long. And it is of course much more fun to have LaTeX to do this automatically.
By borrowing some code from Ulrike Fisher’s answer to this question; http://tex.stackexchange.com/a/4258/9632 ; I was able to defining this macro:
\documentclass{article}
\usepackage{lipsum,ifthen}
\usepackage[lastpage]{zref}
\makeatletter
\zref@newprop*{numpage}{\the\value{page}}
\zref@addprop{main}{numpage}
\newcommand{\oneormoreside}%
{\ifthenelse{\zref@extractdefault{LastPage}{numpage}{1}>1}%
{\thispagestyle{plain}}%
{\thispagestyle{empty}}%
}
\makeatother
\title{Test}
\author{Test Testson}
\begin{document}
\maketitle
\oneormoreside
\lipsum[1-60] %More than one page
%\lipsum[1] % One page
\end{document}
Is there better and simpler solutions? For example one that does not involve additional packages?
To include the macro \oneormorepagesin the text is a kludge. I can redefine \maketitle, but I am reluctant to that. Is there a better solution for integrating the test in the preamble? My goal is to include such test in a separate, private style- or class-file?
EDIT: And here is the result I ended up with. I patch the \maketile on the fly using \patchcmd from etoolbox, a package I load for other purposes in the ‘real’ document:
\documentclass{article}
\usepackage{lipsum,etoolbox}
%% No page number if the document ai a onepager
\makeatletter
\AtEndDocument{%
\ifnum\value{page} > 1%
\immediate\write\@auxout{\string\xdef\string\@multipage\string{\string}}%
\fi%
}
\newcommand{\oneormoreside}{\ifdefined\@multipage\else\thispagestyle{empty}\fi}
\patchcmd{\maketitle}{\thispagestyle{title}}{\oneormoreside}{}{}
%% Change `title` to `plain` if you are using a standard class, not `memoir`
%% or make a conditional or put a new `patchcmd` in the `false` part
\makeatother
\title{Test}
\author{Test Testson}
\begin{document}
\maketitle
\oneormoreside
\lipsum[1-60] %More than one page
%\lipsum[1] % One page
\end{document}
Thanks a lot for all help!
\maketitleline, then you can change its definition to have\oneormoresideinstead of\thispagestyle{plain}. If they haven't it necessarily, say also\AtBeginDocument{\oneormoreside}. – egreg May 21 '12 at 21:24\maketitle, there is a risk that other packages will break, isn’t it? I will try to avoid this. – Sveinung May 21 '12 at 21:43ifthentoo package by using\ifnuminstead of\ifthen– Andreas Wallner May 22 '12 at 8:33\ifthenelsewith\ifnumbut then the macro failed. If you change your comment as a answer, I can upvote it. – Sveinung May 30 '12 at 15:48