TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to define a command that slightly differs depending on the currently selected language in my document. My code:



\newcommand{\whatever}{whatever} % if this is commented out the code works as desired




Why do I get an error thrown at \newcommand{\whatever}{whatever} and how do I avoid that?


In an earlier version I oversimplified my MWE using only two languages, in that case no error is thrown

share|improve this question
Which error? I have no problems. – Marco Daniel Jan 30 '12 at 13:30
I get an error saying Error: Missing \begin{document} – D.Roepo Jan 30 '12 at 13:32
Is that your first error. Please provide also the File List produced in the log-File by \listfiles. – Marco Daniel Jan 30 '12 at 13:40
No, you don't; but you surely get lots of spurious spaces. – egreg Jan 30 '12 at 13:40
You're missing a closing brace in the modified example. That's why I proposed a different approach: counting braces is difficult. – egreg Jan 30 '12 at 17:46
up vote 8 down vote accepted

The definition seems to be "almost" correct, in that it gives almost the expected result, apart from spurious spaces:


However this is error prone if one wanted to augment the supported languages; with xparse it's easier:


\NewDocumentCommand{\mynewcommand}{m m m}
   \cs_new:Npn #1
      \prg_case_str:onn { \languagename }
        {``No~def~of~\texttt{\token_to_str:N #1}~for~\languagename''}

If other languages were desired it would be sufficient to add an argument to \mynewcommand and the suitable line along the same scheme.

An alternative way might be to define different commands:

      {``No def of \texttt{\string#1} for \languagename''}

Unknown languages will result in "No def of \command for language"

With \newlanguagecommand{\uno} one defines the command so that its expansion is \\uno<languagename>; for example, when the language is French, writing \uno will use \\unofrench which is defined by \addtolanguagecommand{\uno}{french}{une} to expand to "une".

This should give no problems also in moving arguments as long as the replacement text doesn't contain fragile commands (text is OK).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.