I'm trying to use xkeyval to create a custom option (\codeblock) for my lstinputlisting (specifically for the linerange part). This is my MWE:








I get the error:

! Improper alphabetic constant.
<to be read again>
l.4 \code[block=inout]

This comes from using:


So I tried:


... but then the resulting listing is completely empty.

I don't think there's anything wrong with my xkeyval syntax but I'm not sure how to get this working?

  • You're showing fragments only and it should by linerange=\maxtestblock most likely. You have \newcommand{\code}... twice as well... and autogobble is no key for listings environments
    – user31729
    Jul 12, 2017 at 14:06
  • Sorry but how on Earth did you know about "maxtestblock"? I deliberately removed all instances of that and changed them all to "codeblock"
    – Ben A
    Jul 12, 2017 at 14:57
  • re. autogobble=true: tug.ctan.org/macros/latex/contrib/lstaddons/lstautogobble.pdf
    – Ben A
    Jul 12, 2017 at 15:01
  • The lstaddons stuff was not in your post above
    – user31729
    Jul 12, 2017 at 15:04
  • 1
    An example of usage with (an approximation of) the expected output would make the question answerable.
    – egreg
    Jul 12, 2017 at 18:03

1 Answer 1


I got around this with:


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.