3

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!

  • 2
    \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
3

You could do

\expandafter\selectlanguage\expandafter{\documentLanguage}

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

I'd prefer a different approach, but this requires knowing the details of your implementation.

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.