I have a command which formats a piece of text a certain way. Simple example:
\begincommand{\myformat}[1]{\texttt{#1}}
I want to be able to place this command inside other text formatting commmands and have those "outer" commands have no effect on the text enclosed in my command.
If I write
\textbf{Some \myformat{example} text.}
\emph{Some \myformat{example} text.}
I want this to be displayed the same as if I had written
\textbf{Some }\myformat{example}\textbf{ text.}
\emph{Some }\myformat{example}\emph{ text.}
Is it possible to "protect" the formatting on a piece of text in situations like this? So that all text formatting applied within \myformat is applied, but all further formatting is ignored?

\DeclareTextFontCommand{\myformat}{\normalfont\ttfamily}(this is actually better, since it handles automatic insertion of the italic correction). – GuM Feb 15 '17 at 23:20can be used only in preamble. – GuM Feb 15 '17 at 23:30\DeclareTextFontCommandI’d mention: if theamsmathpackage is loaded, the\myformatcommand will automagically switch to the correct size when used, for example, in a susbcript (inside math). In other words, in that case the argument is wrapped in a\hboxthat, in turn, is wrapped in a\mathchoice. – GuM Feb 16 '17 at 00:55