[Tex/LaTex] How to undo bold and italic text in braces

bolditalic

Is there a command to nullify, override or cancel any font style in the text in braces?

Something like:

\nullifystyle{sample text: \textit{this should be not italic} and \textbf{this should be not bold}}

\normalfont, \textnormal,\textup and \upshapedo the very opposite.
See: How to set not italic or not bold?

Use case: I need it to recall pieces of text from other part of the document, but to override the font style. A MWE would be:

\documentclass{article}

\begin{document}

\newcommand{\nullifystyle}{???} %is there already a command for this? or how to define it?

\newcommand{\textsample} {some normal text, \textit{some italic} and \textbf{some bold}}

Here I would like to write \textsample. \par

Here  \nullifystyle{\textsample} \ should be typed  totally with normal font style.


\end{document}

Best Answer

Locally redefine \selectfont not to honor changes in shape and series:

\documentclass{article}

\makeatletter
\newcommand{\nullifystyle}[1]{%
  \begingroup
  \edef\sv@f@shape{\f@shape}%
  \edef\sv@f@series{\f@series}%
  \let\sv@selectfont\selectfont
  \def\selectfont{%
    \fontshape{\sv@f@shape}%
    \fontseries{\sv@f@series}%
    \sv@selectfont
  }%
  #1%
  \endgroup
}
\makeatother

\begin{document}

\nullifystyle{sample \emph{text}: \textit{this should be not italic}
  and \textbf{this should be not bold}\textsuperscript{test}}

\end{document}

enter image description here

It works the same if you use a macro like in your example

\newcommand{\sampletext}{sample \emph{text}: \textit{this should be not italic}
  and \textbf{this should be not bold}\textsuperscript{test}}

\nullifystyle{\sampletext}
Related Question