## LaTeX forum ⇒ General ⇒ Change font in caption/headings text

LaTeX specific issues not fitting into one of the other forums of this category.
lulabelle
Posts: 3
Joined: Sun Jan 04, 2009 1:03 pm

### Change font in caption/headings text

Hi,

I have a document where I use a specific definition to put a specific word always in
another font: i.e.:

\usepackage[T1]{fontenc}
\def\bubu{{\renewcommand{\rmdefault}{pfu}\textrm{bubu}}}

I then use \bubu in the body text to get the word bubu in the preferred font.
This works fine, but it doesn't work in headings and captions. I didn't found
any hints on the web how to resolve this problem without changing the font of the whole
caption/heading. To be clear, I want to have something like this:

\begin{figure}
\caption{Normal text, normal text, \bubu in other font, normal font again}
\end{figure}

Many thanks in advance for any hints regarding the problem.

sommerfee
Posts: 495
Joined: Mon Apr 09, 2007 4:20 pm
Contact:

As an alternative, you could use \protect\bubu instead of \bubu where no fragile commands are allowed, i.e. inside captions and headings.

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=protect
http://www.ics.uci.edu/~pan/documents/l ... agile.html

Axel

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm
a bit shorter:
\protected\def\bubu{{\fontfamily{pfu}\selectfont bubu}\xspace}

The \xspace from the xspace package allows you to write A \bubu B instead of A \bubu\ B.

lulabelle
Posts: 3
Joined: Sun Jan 04, 2009 1:03 pm
Many thanks it works fine! But if I use the new command in a section or subsection title
the text is printed in the default font. In the table of contents however the font of
the subsection titles are printed in the correct font, but in the real document the default
font is used. The font of the section title however are also printed in the default font in
the toc.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm
Could you please provide an MWE? I tested this code (using Times) and it worked everywhere:
\documentclass{article} \usepackage{lmodern}\usepackage[T1]{fontenc}\usepackage{xspace} \protected\def\bubu{{\fontfamily{ptm}\selectfont bubu}\xspace}  \begin{document} \tableofcontents\listoffigures \section{Normal text, normal text, \bubu in other font, normal font again} \begin{figure}\caption{Normal text, normal text, \bubu in other font, normal font again}\end{figure} \end{document}

lulabelle
Posts: 3
Joined: Sun Jan 04, 2009 1:03 pm
Oh, I found my error. Your test file totally works fine.
I had a faulty bold version of my used font. Sorry for the inconvenience
and many thanks for the fast help ...