[Tex/LaTex] Redefine command when inside a specific other command possible

conditionalsmacrosnesting

How, in general, can I (re)define commands based on in which other command they are nested?

A more specific example: I have a custom latex command (say, \code{}) that makes text appear bold. However, when used inside another custom command (such as in \question{Will you use \code{command 1} or \code{command 2}?}), I want the \code{} text to be NOT bold. So I want to redefine \code{} when inside another command.

BTW: When using CSS to format HTML pages, it would go something like this:

.code {font-weight: bold;}
.question .code {font-weight: normal;}

Best Answer

Yes, you can.

\newcommand\question[1]{{% extra brace
  \renewcommand\code[1]{\textit{##1}}% double #
  whatever you want for #1}}
Related Question