2

The following MWE works as expected:

\documentclass[french,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{translations}
\usepackage{babel}

\DeclareTranslationFallback{foo}{Foo}%
\DeclareTranslation{English}{foo}{Foo (English)}%
\DeclareTranslation{French}{foo}{Foo (French)}%

\def\foo{\GetTranslation{foo}}
% \declaretheorem[name=\GetTranslation{foo}]{baz}

\begin{document}
\GetTranslation{foo} = \foo

\selectlanguage{french}

\GetTranslation{foo} = \foo
\end{document}

except if the \declaretheorem[name=\GetTranslation{foo}]{baz} is commented out: in such a case, compilation fails with errors:

! Undefined control sequence.
<argument> ...@language@\@trnslt@current@language 

l.15 ...aretheorem[name=\GetTranslation{foo}]{baz}

? 
! Undefined control sequence.
<argument> \@trnslt@current@language 

l.15 ...aretheorem[name=\GetTranslation{foo}]{baz}

?

Hence my question: why \GetTranslation from translations package cannot be used for (thmtools) theorem's name?

  • 1
    Try name=\protect{GetTranslation}{foo}. The output is different from your MWE.. there's no baz – user31729 Oct 27 '15 at 14:43
  • 1
    It looks like it is looking for a "current language" which i guess isn't set up until \begin{document} – David Carlisle Oct 27 '15 at 14:45
  • 2
    @DenisBitouzé with \def the replacement text is never evaluated at until \foo is used, but \declaretheorem is doing more work and is clearly expanding some of its arguments at the point of definition, hence \protect to stop that. – David Carlisle Oct 27 '15 at 14:50
  • 2
    translations defines \def\@trnslt@current@language{\languagename} only at the end of the preamble. Probably \declaretheorem expands its name (which would defeat using \GetTranslation{...} as name in the first place…) – clemens Oct 27 '15 at 14:54
  • 1
    Indeed \thmt@thmname (set by name=...) is found inside \protected@edef so often I lost track… – clemens Oct 27 '15 at 22:04
4

You've to protect \GetTranslation from being executed at the point of definition in \declaretheorem -- the call to \GetTranslation is deferred to the point where the theorem itself is used, i.e. in the document body:

 \declaretheorem[name=\protect\GetTranslation{foo}]{baz}

Thanks to David Carlisle also for some explanations ;-)

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.