23

I'm trying to redefine the \emph command to make text bolded in addition to being italic, but when I use

\newcommand{\bfemph}[1]{\textbf{\emph{#1}}}

\renewcommand{\emph}[1]{\bfemph{#1}}

I get an error message. The first command defining \bfemph works on its own, but the latter does not.

I would really appreciate some help with this.

Andrew Swann
  • 95,762
ಠ_ಠ
  • 520

3 Answers3

32

Rather than redefining \emph in terms of a copy of itself, it's better redefining it from scratch, using the standard definition as model; the standard definition is surprisingly simple:

% latex.ltx, line 3744:
\DeclareTextFontCommand{\emph}{\em}

because it's \em that does the hard work. So we can simply do

\documentclass[11pt]{article}

\let\emph\relax % there's no \RedeclareTextFontCommand
\DeclareTextFontCommand{\emph}{\bfseries\em}

\begin{document}

Here is \emph{emphasized text with something \emph{emphasized} inside}

\end{document}

enter image description here

However, double emphasis is really too much: italic is sufficiently prominent. The advantage of redefining \emph in this way is that you can simply comment out those two lines and return to the default.

Why doesn't your idea work? Because with those definitions, when TeX finds

\emph{text}

it changes it into

\bfemph{text}

and this becomes

\textbf{\emph{text}}

that in turn becomes

{<expansion of \textbf>\emph{text}}

Sorry, infinite loop: \emph will restart the machinery.

egreg
  • 1,121,712
8

With latest Latex you can just do

\DeclareEmphSequence{\bfseries\itshape}

For nested \emph you can provide additional declarations to \DeclareEmphSequence separated by comma.

Twonky
  • 286
6

You can't define a command by itself, which you are basically doing. The simplest solution would to just use the textit command:

\documentclass[11pt]{article}

\newcommand{\bfemph}[1]{\textbf{\textit{#1}}}
\renewcommand{\emph}[1]{\bfemph{#1}}

\begin{document}
Text \bfemph{Text2} \emph{Text3}
\end{document} 

Of course you don't need the bfemph command:

\documentclass[11pt]{article}

\renewcommand{\emph}[1]{\textbf{\textit{#1}}}

\begin{document}
Text \emph{Text3}
\end{document}

This solution doesn't have the standard behaviour of emph to toggle between modes if you use it recursively.

Juri Robl
  • 4,763
  • 2
    That sort of works by luck , but \let\emphold\emph doesn't save the real definition of \emph it just saves the top level (which is \def\emph{\protect\emph_} (where _ is a space) you happened to use \renewcommand rather than \declarerobustcommand to redefine \emph so the internal definition was not over- written. but if you put that in a moving argument like \section it will write to the toc as \textbf{\emph {xxxx}} – David Carlisle Feb 11 '15 at 16:31
  • 1
    A crap.. I didn't know that. – Juri Robl Feb 11 '15 at 16:32
  • 1
    I will just remove the \let definition then. Although I always liked that solution :( – Juri Robl Feb 11 '15 at 16:33
  • 3
    @JuriRobl You should use \LetLtxMacro\oldemph\emph (requires \usepackage{letltxmacro}) instead of \let. See When to use \LetLtxMacro? – egreg Feb 11 '15 at 16:39