35

I'm using the listings package in a LaTeX document. It works great, but it doesn't allow me to put LaTeX commands inside of the listing. I would like to use a counter to enumerate some of the interesting parts in the source code.

Is there a way to enable LaTeX commands in source listings?

0

1 Answer 1

34

OK, found the answer. You can use escapechar=<char> to set a character that will escape you to the latex mode. See The Listings Package, 4.3.13 Escaping to LaTeX.

2
  • 1
    Is there a default? I couldn't find it quickly. From what I understand there is no default. Oct 23, 2013 at 9:13
  • 1
    Here is an example: if you set escapechar=\%, you could use it inside the listings as follows: \begin{lstlisting} t %\leftarrow% 0 \end{lstlisting}.
    – thiagowfx
    Jul 9, 2017 at 23:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .