LaTeX forum ⇒ GeneralChange 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

Postby lulabelle » Sun Jan 04, 2009 1:13 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

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

Postby sommerfee » Sun Jan 04, 2009 1:29 pm

Use \DeclareRobustCommand\bubu instead of \def\bubu.

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

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

Axel

Link:
BBcode:
HTML:
Hide post links
Show post links

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Postby phi » Sun Jan 04, 2009 3:48 pm

a bit shorter:
  1. \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.

Link:
BBcode:
HTML:
Hide post links
Show post links

lulabelle
Posts: 3
Joined: Sun Jan 04, 2009 1:03 pm

Postby lulabelle » Sun Jan 04, 2009 7:56 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.

Link:
BBcode:
HTML:
Hide post links
Show post links

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Postby phi » Sun Jan 04, 2009 8:25 pm

Could you please provide an MWE? I tested this code (using Times) and it worked everywhere:
  1. \documentclass{article}
  2.  
  3. \usepackage{lmodern}
  4. \usepackage[T1]{fontenc}
  5. \usepackage{xspace}
  6.  
  7. \protected\def\bubu{{\fontfamily{ptm}\selectfont bubu}\xspace}
  8.  
  9.  
  10. \begin{document}
  11.  
  12. \tableofcontents
  13. \listoffigures
  14.  
  15. \section{Normal text, normal text, \bubu in other font, normal font again}
  16.  
  17. \begin{figure}
  18. \caption{Normal text, normal text, \bubu in other font, normal font again}
  19. \end{figure}
  20.  
  21. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

lulabelle
Posts: 3
Joined: Sun Jan 04, 2009 1:03 pm

Postby lulabelle » Sun Jan 04, 2009 9:35 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 ...

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “General”

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests