1

I am using the listings package and am doing a mapping of syntax names. Basically I want to do this:

\NewDocumentCommand\syntaxnamefor{m}{
  ... % this command if given `xhtml` returns `html`, if given `py` returns `python`
}
\NewDocumentCommand\setsyntax{m}{
  \lstset{language=\syntaxnamefor{#1}}
}

Now the problem is that in the \lstset call the argument does not get fully expanded. I get the following error:

! Package Listings Error: language \syntaxnamefor {xhtml} undefined

E.g. the listings package gets the string \syntaxnamefor {xhtml} as its argument instead of getting its expansion html as its argument. I've tried around with \edev and \expandafter but that's some really complicated stuff...

1
  • 1
    Regardless of how you can force (or have to force) expansion in \lstset, note that a command defined with \NewDocumentCommand is never expadanble. You want \NewExpandableDocumentCommand.
    – moewe
    Jun 7 at 6:53
1

Commands defined with \NewDocumentCommand are not expandable, use \newcommand or \NewExpandableDocumentCommand.

2
  • Or use simply \def.
    – wipet
    Jun 8 at 20:13
  • @wipet I searched all my latex manuals and could find no such command, what does it do? Jun 8 at 22:22

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.