Getting bold typed text
I have been using listings to format my code, and have occasionally been using the following solution to make some typed text bold:
\DeclareFontShape{OT1}{cmtt}{bx}{n}{<5><6><7><8><9><10><10.95><12><14.4><17.28><20.74><24.88>cmttb10}{}
(I have no idea how this works, but is suggested here and here).
However, I usually use this with black text, but have just noticed that this does not preserve the colour the listings package gives when highlighting.
It doesn't work within a coloured listings
MWE
\documentclass[10pt]{extarticle}
\usepackage{color}
\usepackage{listings}
\lstset{stringstyle=\color[rgb]{.627,.126,.941}, basicstyle={\fontfamily{cmtt}\selectfont\footnotesize},showstringspaces=false}
\DeclareFontShape{OT1}{cmtt}{bx}{n}{<5><6><7><8><9><10><10.95><12><14.4><17.28><20.74><24.88>cmttb10}{}
\begin{document}
\ttfamily Something in \textbf{bold}. {\color{red} Something else in \textbf{bold}.}
\begin{lstlisting}[escapechar=@]
Something @\textbf{important}@ right here.
\end{lstlisting}
\begin{lstlisting}[language=C, escapechar=@]
int main()
{
int = 1;
char * s = "@something@ @\textbf{important}@ right @\color[rgb]{.627,.126,.941} \bfseries here@"
"and a normal string for comparison";
}
\end{lstlisting}
\end{document}
Is it possible to have @\textbf{...}@ inherit the colour listings wants to give it?


@...@be some escape that allowed for some extra formatting, so while in my example I may use bold, I an/could instead choose@\textit{something}@, or even@$something$@. In what I am expecting to use it for though I am mostly expecting to use either bold, italics, underline, strikethrough, etc. (nothing too exotic, bit to support a few features, mostly bold though). – oliversm May 16 '19 at 14:44listings' capabilities are really limited here. For bold and italics text my solutions works fine. For underline or strikethrough you can use the approach presented in this answer. I'm not sure how a solution for math mode could look like, aslistingsexecutes theEndGrouphook when it escapes the listing, so all information about the\@instringtoggle ist lost. – siracusa May 16 '19 at 23:09