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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to combine to use mathescape together with the Erlang syntax highlighting in the package lstlisting, as described in Section 4.14 of its manual:




This fails with:

! Extra }, or forgotten \endgroup.
<recently read> \egroup 

l.10 \lstinline{$n_1$.lookup(k)}

The code works fine for other languages, e.g. C. Does the style for Erlang miss something to allow this?

share|improve this question
\lstinline|$n_1$.lookup(k)| seems to work. – egreg Feb 13 '13 at 14:36
Yes, it works. You might want to put that up as an answer. – evnu Feb 13 '13 at 14:42
up vote 3 down vote accepted

The listings package allows the syntax


but marks it as “experimental”, see p. 26 of the manual, section 4.2. Section 5.1 talks about using \lstinline in the argument of another command; the end of section 5.1 tells, however, that this is not safe.

In particular, mathescape turns out not be compatible with the experimental syntax, so you should use something like


(use, as a delimiter, a character that doesn't appear in the string to be typeset, just like for the \verb command).

share|improve this answer

Your Answer


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.