I'm trying to use xkeyval
to create a custom option (\codeblock
) for my lstinputlisting
(specifically for the linerange
part). This is my MWE:
\makeatletter
\newcommand{\code}{}
\define@key{code}{block}{\renewcommand\codeblock{#1}}
\setkeys{code}{block=}
{}
\savekeys{code}{block}
\newcommand\code[1][]{
\setkeys{code}{#1}
\lstinputlisting[linerange=\codeblock,rangeprefix=//---,includerangemarker=false]{./listingwithoutcomments}
}
\makeatother
I get the error:
! Improper alphabetic constant.
<to be read again>
\code
l.4 \code[block=inout]
This comes from using:
\linerange=\block
So I tried:
\linerange=\\block
... 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?
linerange=\maxtestblock
most likely. You have\newcommand{\code}...
twice as well... andautogobble
is no key forlistings
environmentslstaddons
stuff was not in your post above