48

Question says it all. What is the best way to redefine the \emph command to be bold font and upright?

lockstep
  • 250,273
yannisl
  • 117,160

2 Answers2

45

Since \emph uses \em, I would redefine \em.

Here's such a redefinition which preserves the ability to toggle between bold and normal, if nested:

\makeatletter
\DeclareRobustCommand{\em}{%
  \@nomath\em \if b\expandafter\@car\f@series\@nil
  \normalfont \else \bfseries \fi}
\makeatother

Test of nesting behavior of \emph:

Question: \emph{What is the way to redefine the \emph{\textbackslash emph} command?}

alt text

Stefan Kottwitz
  • 231,401
  • 2
    @Stefan: +1 for reminding me of \em's toggling ability. – lockstep Dec 08 '10 at 19:41
  • 3
    I'm not sure if it makes any sense to use normal font to emphasise something inside bold text... – Jukka Suomela Dec 08 '10 at 19:48
  • @Jukka: I just imitated the toggling. Of course \normalfont may be replaced by \itshape or the like if accumulation of font attributes would be preferred. Toggling allows unworried nesting, accumulation does not. – Stefan Kottwitz Dec 08 '10 at 19:56
  • @Stefan Thanks. Not part of the original question but how can one save the old \em? \let\oldem\em does not seem to have an effect. – yannisl Dec 08 '10 at 20:27
  • @Yiannis: yes, and neither does \xdef. Perhaps copy& paste ... or define \em to be variable: using \noemphasizing and \emphasizing and a test macro instead of \upshape and \itshape. This way one just has to change the simple macros instead of redefining \em again. – Stefan Kottwitz Dec 08 '10 at 20:51
  • @Stefan Both are great answers! – yannisl Dec 08 '10 at 21:03
  • @Yiannis: If you do \show\em, you will get \protect \em . in the log file and notice the two spaces after \em (they do not show here for some reason): this is because it is a protected macro and so the original definition is saved in the \csname em \endcsname macro. So you should do \expandafter\let\expandafter\oldem\csname em \endcsname. Just beware that \oldem is not a protected macro anymore. – Philippe Goutet Dec 09 '10 at 00:21
  • 2
    Note that the toggling is somewhat modified by fixltx2e so that in an italic context, \em produces \eminnershape (by default this is \upshape to give the original behaviour, but it can be redefined to, eg, \scshape to give small caps). – Lev Bishop Dec 09 '10 at 05:51
  • 1
    @Philippe: just a thought: it is also possible to do \begingroup\def\protect{\global\let\oldem}\em\endgroup. – Bruno Le Floch Jul 29 '11 at 01:04
  • And what If we wanted to use \slshape instead of \bfseries (in this example). I want to emphasize in slanted. How would the redefinition be? – Manuel Nov 30 '12 at 23:27
  • 1
    @Manuel \makeatletter\DeclareRobustCommand\em{\@nomath\em \ifdim \fontdimen\@ne\font >\z@\upshape \else \slshape \fi}\makeatother – Stefan Kottwitz Nov 30 '12 at 23:37
19

According to p. 194 of the LaTeX2e sources, \emph is defined as

\DeclareTextFontCommand{\emph}{\em}

So I suggest to redefine it as follows:

\DeclareTextFontCommand{\emph}{\bfseries}
lockstep
  • 250,273