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.

3
  • Do you even need the bfemph command?
    – Juri Robl
    Feb 11, 2015 at 16:20
  • I was just trying to figure out how to redefine \emph so I was playing around with defining a new command that did what I wanted.
    – ಠ_ಠ
    Feb 11, 2015 at 16:23
  • 1
    Ok, I'll change my solution to remove bfemph
    – Juri Robl
    Feb 11, 2015 at 16:24

3 Answers 3

8

With latest Latex you can just do

\DeclareEmphSequence{\bfseries\itshape}

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

1
  • 2
    Yes, this is the correct way to do it nowadays.
    – egreg
    Nov 17, 2023 at 10:34
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.

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.

4
  • 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}} Feb 11, 2015 at 16:31
  • 1
    A crap.. I didn't know that.
    – Juri Robl
    Feb 11, 2015 at 16:32
  • 1
    I will just remove the \let definition then. Although I always liked that solution :(
    – Juri Robl
    Feb 11, 2015 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, 2015 at 16:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .