# Use toks or commands in selectlanguage from babel

I'm currently working on creating a generic invoice in LaTeX. Later I don't want to change the document, but a little section which only contains variables. It works fine for now, but now I want to introduce a variable which switches the language between english and ngerman. Because \selectlanguage of the babel package just works in the document section, I have to define a variable for that.

I tried it with

\def\documentLanguage{english}


and

\newcommand{\documentLanguage}{english}


And then in the document section with

\begin{document}
\selectlanguage{\documentLanguage}


Neither of these worked, because of the error "You haven't defined documentLanguage yet". I think the \ somehow gets removed and the parser just reads "documentLanguage" as string.

Is there a way to fix this behavior?

Thanks!

• \expandafter\selectlanguage\expandafter{\documentLanguage} should work, but probably there are better methods, if you're implementing a class. – egreg Dec 15 '16 at 13:40
• @egreg Thanks, it works! Exactly what I was looking for. – michidk Dec 15 '16 at 13:49

\expandafter\selectlanguage\expandafter{\documentLanguage}

(for historical reasons, \selectlanguage stringifies its argument, so a control sequence there is not expanded).