# How can I "force" macro expansion before calling another macro?

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...

• 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. Jun 7 at 6:53

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

• Or use simply \def. 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