Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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},
   commentstyle=\itshape\color{green},
   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,
   commentstyle=\itshape\color{purple!40!black},
   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.

share|improve this question

migrated from stackoverflow.com May 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 at 12:22

1 Answer 1

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.

share|improve this answer
    
Welcome to TeX.SX! You may have a look on our starter guide. –  texenthusiast May 8 '13 at 7:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.