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.

I have a little lstlisting to show a snippet of code but since the code has % in it for modulo calculation the listing breaks down. How can I escape it?

I have tried the backslash, verbatim and \text commands

\begin{lstlisting}
int RSAEncrypt(char m)
{
    return (int)pow(charToNumber(m), e) % n;
}
\end{lstlisting}
share|improve this question
2  
You shouldn't need to escape a % inside lstlisting... It works perfectly for me... –  Seamus Mar 6 '11 at 13:04
1  
Could it be that you are using the lstlisting inside another macro or pseudo-environment like tabularx? Otherwise it should work fine as Seamus said. Please add a complete minimal example that illustrates your problem. –  Martin Scharrer Mar 6 '11 at 13:15
add comment

1 Answer

up vote 5 down vote accepted

I found it, in the lstset definition I had

escapeinside={\%}{)}

I remove it and it works now. Thanks :)

share|improve this answer
1  
You can also accept your own answer! –  Hendrik Vogt Mar 9 '11 at 13:25
    
@Hendrik Got it! Thanks :) –  Ólafur Waage Mar 9 '11 at 14:28
2  
The above comment helped. I wasted almost an hour looking for it. :-) Thanks –  user6063 Jun 9 '11 at 21:56
add comment

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.