# Changing Style Inside LaTeX Listing

In short, I'm trying to combine some C code with its disassembly in LaTeX such that the x86 code is displayed after the relevant statement. In order to make this look nice, I would like to be able to switch between styles inside of a listing. I've searched online for quite a while and have come across multiple sources talking about escapeinside and escapechar (this post for example), but I can't seem to get either working. Right now, my code looks like:

\begin{lstlisting}[style=customcpp, escapechar=\@]
void sort(int *rgList, int nLen)
{@\lstset{escapechar=\@, style=customasm}@
push    ebp
mov     ebp, esp
sub     esp, 48h
push    ebx
push    esi
push    edi
...
\end{lstlisting}


where customcpp and customasm are styles that I have defined. Both work fine separately. It's when I try and combine them that I get issues. I have a feeling that I'm doing something stupid, but I can't seem to find it.

For what it's worth, here are my style definitions:

\lstdefinestyle{customcpp}{
belowcaptionskip=1\baselineskip,
breaklines=true,
frame=L,
xleftmargin=\parindent,
language=C++,
showstringspaces=false,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\color{blue},
stringstyle=\color{purple},
identifierstyle=\color{gray},
tabsize=4,
numbers=left,
numbersep=8pt,
stepnumber=1,
numberstyle=\tiny\color{gray},
}

\lstdefinestyle{customasm}{
belowcaptionskip=1\baselineskip,
frame=L,
xleftmargin=\parindent,
language=[x86masm]Assembler,
basicstyle=\footnotesize\ttfamily,
keywordstyle=\color{black},
identifierstyle=\color{black},
tabsize=4,
numbers=left,
numbersep=8pt,
stepnumber=1,
numberstyle=\tiny\color{gray}
}


I should also note that escaping works. What doesn't work is changing the style.

-

## migrated from stackoverflow.comMay 7 '13 at 12:35

This question came from our site for professional and enthusiast programmers.

I may be wrong (I'm still learning about listings), but I think the style is set early on by the lstlisting environment, and you cannot simply switch from one to another within the listing. I'm afraid that's just not possible. –  Jubobs Mar 10 '14 at 12:22

I found a workaround where I just used @\verb=...=@ since that was the same format as my assembly code and it worked OKAY and I apparently can't use \lstinline inside of a listing. Nevertheless, it's still really silly that I had to resort to this. If anyone has any better solution, I'd love to hear it.