TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

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???\\
share|improve this question
You should avoid capturing the argument in \code. Rather try: \newcommand{\code}{\lstinline[style=Inline]} – Werner Mar 30 '14 at 14:14
Then I get ...AAAAABC\ABC instead of ...AAAAABCABC or ...AAAAABC-<new line>ABC. – user3389757 Mar 30 '14 at 14:17
up vote 8 down vote accepted

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:








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.