Upon trying to typeset the following TeX I get the error:

Too many }'s. ...handleClick } >Button component}


\lstinline{<Button onClick=\{this.handleClick\}>Button component</Button>}

What am I doing wrong?

1 Answer 1


Using curly braces for the source code argument of \lstinline is marked as experimental in the documentation of package listings. The normal form with a character to delimit the argument works without the need to escape braces inside the code:


\lstinline|<Button onClick={this.handleClick}>Button component</Button>|


The expression

\lstinline{<Button onClick=\{this.handleClick\}>Button component</Button>}

with or without the backslash does not work, because the source code argument is scanned in a special way as verbatim with changed category codes. The first } ends the argument: <Button onClick=\{this.handleClick\ the remaining part >Button component</Button>} is set outside of \lstinline and the closing curly brace without counterpart causes the error.

  • Thanks a lot for the detailed response. It works great.
    – Hedge
    Sep 2, 2015 at 1:23
  • 1
    Had the exact same Problem, thanks for your super simple solution! Jan 17, 2017 at 15:37
  • 2
    Syntax: \lstinline[⟨key=value list⟩]⟨character⟩⟨source code⟩⟨same character⟩ Feb 18, 2019 at 5:28
  • I'm trying to do a shell line that has sed and awk in a pipeline, so the | does not work. But the answer is great and thanks to Marc's comment I was able to use I (uppercase i) which did not appear elsewhere in the pipe. Unfortunately I still don't know how to deal with a $ sign: quoting it leaves the \, and not quoting it enters math mode... May 18, 2020 at 4:02
  • @markgalassi Maybe you have activated mathescape. Then, it can be disabled for a \lstinline by using the optional argument: \lstinline[mathescape=false]I<shell pipeline>I May 18, 2020 at 9:30

You must log in to answer this question.

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