### Who is online

In total there are 15 users online :: 0 registered, 0 hidden and 15 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 15 guests

## Change font in caption/headings text

Add tags LaTeX specific issues not fitting into one of the other forums of this category.

### 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.
lulabelle

Posts: 3
Joined: Sun Jan 4th, 2009

### Re: Change font in caption/headings text

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

sommerfee

Posts: 493
Joined: Mon Apr 9th, 2007

### Re: Change font in caption/headings text

a bit shorter:
Code: Select all  •  Open in writeLaTeX
\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.
phi

Posts: 578
Joined: Tue Oct 21st, 2008

### Re: Change font in caption/headings text

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

Posts: 3
Joined: Sun Jan 4th, 2009

### Re: Change font in caption/headings text

Could you please provide an MWE? I tested this code (using Times) and it worked everywhere:
Code: Select all  •  Open in writeLaTeX
\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}
phi

Posts: 578
Joined: Tue Oct 21st, 2008

### Re: Change font in caption/headings text

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

Posts: 3
Joined: Sun Jan 4th, 2009