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?


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 '15 at 1:23
  • 1
    Had the exact same Problem, thanks for your super simple solution! – Christian Seiler Jan 17 '17 at 15:37
  • 2
    Syntax: \lstinline[⟨key=value list⟩]⟨character⟩⟨source code⟩⟨same character⟩ – l --marc l Feb 18 '19 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... – markgalassi May 18 '20 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 – Heiko Oberdiek May 18 '20 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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