# How to use different font and shape characters properly in headers?

I'm using Kpfonts for the text of my documents, but I'd like to use the Computer Modern italic ampersand in my headings. To this end, I've defined a command \amp to insert the proper character. The first attempt is

\newcommand\amp{{\fontfamily{cmr}\fontshape{it}\selectfont\&}}


But that doesn't work because there's no bold italic CM, so I have to use the bx series instead:

\newcommand\amp{{\usefont{T1}{cmr}{bx}{it}\&}}


Which works. But now I have bold ampersands in the page headers (this is a thesis, so I've got chapter and section titles on top of non-title pages). After some fiddling, I get this:

\makeatletter
\newcommand\amp{{\if\f@series b\usefont{T1}{cmr}{bx}{it}\else\usefont{T1}{cmr}{m}{it}\fi\&}}
\makeatother


This gives me the right weight in the right place in titles and page heads, but now the table of contents gets the wrong font, because \amp is expanded when the stuff is added to the .toc file, and at that time the font series is m and not b.

Is there some way I can get this to do the right thing in all three places? I suppose I have to somehow delay expansion of the macro in the appropriate way, but I've no idea how...

Using \protect\amp does the trick.

\documentclass{article}

\usepackage{kpfonts}

\makeatletter
\newcommand\amp{{\if\f@series b\usefont{T1}{cmr}{bx}{it}\else\usefont{T1}{cmr}{m}{it}\fi\&}}
\makeatother

\begin{document}

\tableofcontents

\section{Barnes \protect\amp\ Noble}

Some text.

\end{document}

• D'oh. When something untoward happens in titles and such \protect is of course the way. Thanks! – arnsholt Apr 9 '11 at 14:35