I want to declare a macro \myemph which typesets its argument in italics. When \emph is used in \myemph, it should use boldface. But when \emph is used outside of \myemph, it should still use italics:
\emph{italic, \emph{upright}} % as usual
\myemph{italic, \emph{bold and italic}} % new command
(For the moment, I do not care about nested \emph in \myemph.)
I have attempted to declare the macro below. This seems to work fine. However, I'm getting weird errors when I use this in section or chapter titles:
\documentclass{article}
\makeatletter
\NewCommandCopy\org@emph\emph
\DeclareTextFontCommand{\bfemph}{\bfseries}
\newcommand{\myemph}[1]{\textit{\RenewCommandCopy\emph\bfemph#1\RenewCommandCopy\emph\org@emph}}
\makeatother
\begin{document}
\myemph{italic, \emph{bold and italic}} % works
\section{\myemph{Section}} % error
\end{document}
(I'm not sure if there's any benefit to defining \bfemph over just using \textbf.)
The error I get is: Argument of \@sect has an extra }. How can I define \myemph so that it also works in this environment?

\DeclareRobustCommand(I wrote something about that earlier today here). Your\myemphmacro is not expandable, but writing to the .toc file forces it to expand and it breaks. Making it robust solves the problem – Phelype Oleinik Oct 22 '21 at 14:18