# Bold page numbers with revtex

I would like to print page numbers bold (that's an example) wherever they appear. My naive MWE looks like this:

\documentclass{revtex4-1}
\renewcommand*{\thepage}{\textbf{X}}
%\usepackage{microtype}
%\renewcommand*{\thepage}{X}
\begin{document}
foo
\end{document}


This does work. However, as soon as I use a few other packages such as microtype (uncomment first commented line), this breaks. This can be fixed by uncommenting the second commented line, suggesting that it's not the messing with \thepage per se which breaks things. Still, I lose the effect that I want.

With the formatting, the aux file looks like this:

....
\newlabel{LastPage}{{}{\protect \unhbox \voidb@x \bgroup \def document{1}\let \futurelet \@let@token \let \protect \relax \protect \edef m{bx}\protect \xdef \OT1/cmr/bx/n/10 {\OT1/cmr/m/n/10 }\OT1/cmr/bx/n/10 \size@update \enc@update 1\egroup }{}{}{}}


So probably, this command in revtex4-1.cls messes things up:

\immediate\write\@auxout{\string\newlabel{LastPage}{{}{\thepage}{}{}{}}}%


How can I fix this line to make things right?

Update: This creates a proper .aux file, but of courses messes up the document's page numbers:

\documentclass{revtex4-1}
\renewcommand*{\thepage}{\string\textbf{X}}
\usepackage{microtype}
\begin{document}
foo
\end{document}


## 2 Answers

Adding formatting to \thepage should be the last resort.

\documentclass{revtex4-1}
\usepackage{microtype}
\usepackage{etoolbox}

\usepackage{kantlipsum} % mock text

\makeatletter
\AtBeginDocument{%
\patchcmd{\@oddhead}{\thepage}{\textbf{\thepage}}{}{}%
\patchcmd{\@evenhead}{\thepage}{\textbf{\thepage}}{}{}%
}
\let\latex@pageref\pageref
\renewcommand{\pageref}[1]{\textbf{\latex@pageref{#1}}}
\makeatother

\begin{document}

This text has \pageref{LastPage} pages.

\kant

\end{document}


The .aux file has

\newlabel{LastPage}{{}{2}{}{}{}}


as it should.

Something more is needed if you use hyperref, but it's not in your question.

If you really want to go on the \textbf{\arabic{page}} road, then do it properly:

\usepackage{etoolbox}
\robustify{\textbf} % make \textbf survive \edef

\renewcommand{\thepage}{\textbf{\arabic{page}}}

• The OP stated (in a comment, so maybe not easy to find) that he/she wants the page numbers to be bold everywhere, including in cross-references. – Mico Jul 7 '15 at 15:58
• @Mico It's quite easy, too. – egreg Jul 7 '15 at 16:07
• Thanks! But you do agree that if I do not touch the definition of \thepage, then I do need to care about any (future) potential use of \thepage, be it through \pageref (which you cover), other hyperref functionality (which you mention) or other other custom macro (I could think of some back-referencing script, or a package breaking tables across pages and referencing them from one another). And I do not see any downside to formatting \thepage by changing its definition, so I like my answer better. (Oh, I see one downside: \pagenumbering resets \thepage. But I can deal with that.) – bers Jul 7 '15 at 19:41
• @bers Then do it properly: \usepackage{etoolbox}, then \robustify{\textbf} and finally \renewcommand{\thepage}{\textbf{\arabic{page}}. – egreg Jul 7 '15 at 19:45
• Awesome, thanks! I count that as an acceptable answer despite it being a comment :) – bers Jul 7 '15 at 19:51

I found the answer in Writing text content as labels and refer to them with \nameref*:

\documentclass{revtex4-1}
\renewcommand*{\thepage}{\unexpanded{\textbf{X}}}
\usepackage{microtype}
\begin{document}
foo
\end{document}


This seems to actually work!