The problem is that in the inline listing "ABC-ABC" the hyphen disappears. It works if I remove the literate=... parameter but I need it because I want to wrap around long inline code by specifying manual hyphenation markers with "-". How can I solve this problem?

Another weird thing is that inline listing only works with \newcommand as the second part in the example shows. Is this a bug?




Bug in listings???\\
  • 3
    You should avoid capturing the argument in \code. Rather try: \newcommand{\code}{\lstinline[style=Inline]}
    – Werner
    Mar 30, 2014 at 14:14
  • Then I get ...AAAAABC\ABC instead of ...AAAAABCABC or ...AAAAABC-<new line>ABC. Mar 30, 2014 at 14:17

1 Answer 1


There are two issues:

  • \- is the same as - in literate, if you want to have a backslash in front of the hyphen, then the backslash needs to be escaped by a backslash. The hyphen does not need to be escaped by a backslash: \\- catches the backslash and the hyphen.

    From the documentation:

    4.1 How to read the reference
    5. If you want to enter one of the special characters {}#%\, this character must
      be escaped with a backslash. This means that you must write \} for the
      single character ‘right brace’—but of course not for   the closing paramater

  • Package listings reads the code with changed catcodes. If the code for \lstinline is already read as argument, the argument is tokenized and catcode changes do not have an effect, see Werner's comment:








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.