Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Assume I would like to change the font for a section of text, e.g. use Bookman for both headings and paragraphs (similarly to the explanations in this community wiki guide).

If I change the \familydefault, as in section (1), only headings are affected. If on the other hand I select Bookman as the \fontfamily, it affects only paragraph text but not headings (2). Combining both commands gives the desired result (3), as does adding a \normalfont command to \familydefault* (4).

What causes this behaviour? Does \fontfamily set some "currentfont" variable which is not accessed when headings are formatted? And why does changing \familydefault immediately affect headings, but not text?

 

*This was pointed out in a comment by @mpg.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}

%print a _short section of lipsum text
\newcommand{\shlipsum}{%
    \section{A quick brown fox}
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.\\%
}

%reset font to typewriter CM
\newcommand{\resetfont}{\renewcommand{\familydefault}{cmtt}\normalfont}

\begin{document}

\resetfont
\renewcommand{\familydefault}{pbk}  %sets heading only
\shlipsum

\resetfont
\fontfamily{pbk}\selectfont         %sets paragraph text only
\shlipsum

\resetfont
\renewcommand{\familydefault}{pbk}
\fontfamily{pbk}\selectfont
\shlipsum

\resetfont
\renewcommand{\familydefault}{pbk}
\normalfont
\shlipsum

\end{document}
share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

\fontfamily{pbk}\selectfont selects that family from that point for the rest of the current group.

\renewcommand{\familydefault}{pbk} Just redefines that macro and does nothing unless something does \fontfamily{\familydefault}\selectfont. That combination isn't normally done explicitly but is part of \resetfont or \normalfont which heading commands usually use so that they get consistent fonts even if the text at that point in the document is locally using a different font style.

share|improve this answer
    
Thank you, now it makes sense. How could I access the variable set by \fontfamily, i.e. what is its identifier? –  dgs Jun 8 '12 at 15:44
1  
the definition of fontfamily is \DeclareRobustCommand\fontfamily[1]{\edef\f@family{#1}} so \f@family but you wouldn't normally need to look at that directly –  David Carlisle Jun 8 '12 at 16:13
    
Probably not, but it could come in handy for "figuring out what's going on" purposes. Thanks again. –  dgs Jun 8 '12 at 16:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.