Declaremathoperator with language dependence
In my opinion the definition should be so that the operator doesn't change across a document even through language changes.
So if the main language is German, \ker
should resolve to “Kern” also in English. However, it's easy to provide also a “variable” kind.
\documentclass{scrartcl}
\usepackage[english,ngerman]{babel}
\usepackage{amsmath}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand\DeclareBabelMathOperator{mmO{???}}
{
\DeclareMathOperator{#1}
{
\str_case:xnF { \use:c { bbl@main@language } } { #2 } { #3 }
}
}
\NewDocumentCommand\DeclareVariableBabelMathOperator{mmO{???}}
{
\DeclareMathOperator{#1}
{
\str_case:xnF { \languagename }{ #2 } { #3 }
}
}
\cs_generate_variant:Nn \str_case:nnF { x }
\ExplSyntaxOff
\DeclareBabelMathOperator{\range}{
{english}{ran}
{ngerman}{Bild}
}
\DeclareBabelMathOperator{\kernel}{
{english}{ker}
{ngerman}{Kern}
}[ker]
\DeclareVariableBabelMathOperator{\vrange}{
{english}{ran}
{ngerman}{Bild}
}
\DeclareVariableBabelMathOperator{\vkernel}{
{english}{ker}
{ngerman}{Kern}
}[ker]
\begin{document}
\section{Fixed names}
\[
\dim(V) = \dim(\range(T)) + \dim(\kernel(T))
\]
\begin{otherlanguage*}{english}
\[
\dim(V) = \dim(\range(T)) + \dim(\kernel(T))
\]
\end{otherlanguage*}
\section{Variable names}
\[
\dim(V) = \dim(\vrange(T)) + \dim(\vkernel(T))
\]
\begin{otherlanguage*}{english}
\[
\dim(V) = \dim(\vrange(T)) + \dim(\vkernel(T))
\]
\end{otherlanguage*}
\end{document}
The optional argument is for the string to be used with a language not included in the previous choices.
Here is the output if english
and ngerman
are swapped throughout.
\documentclass{scrartcl}
\usepackage[german,english]{babel}
\usepackage{amsmath}
\DeclareMathOperator{\range}{\rangename}
\DeclareMathOperator{\kernel}{\kernelname}
\addto\extrasenglish{%
\def\rangename{range}%
\def\kernelname{ker}%
}
\addto\extrasgerman{%
\def\rangename{Bild}%
\def\kernelname{Kern}%
}
\begin{document}
\selectlanguage{english}
english
\begin{align}
T &: V \rightarrow W \\
\dim(V) &= \dim(\range(T)) + \dim(\kernel(T))
\end{align}
\selectlanguage{german}
Und jetzt etwas auf Deutsch
\begin{align}
T &: V \rightarrow W \\
\dim(V) &= \dim(\range(T)) + \dim(\kernel(T))
\end{align}
\end{document}
I would stick to good old \operatorname
and combine it with babel
's \extrasLANGUAGE
:
\documentclass{scrartcl}
\usepackage[german,english]{babel}
\usepackage{amsmath}
\addto\extrasenglish{%
\def\range{\operatorname{ran}}%
\def\kernel{\operatorname{ker}}%
}
\addto\extrasgerman{%
\def\range{\operatorname{Bild}}%
\def\kernel{\operatorname{Kern}}%
}
\begin{document}
English
\begin{align}
T &: V \rightarrow W \\
\dim(V) &= \dim(\range(T)) + \dim(\kernel(T))
\end{align}
\selectlanguage{german}
Und jetzt etwas auf Deutsch
\begin{align}
T &: V \rightarrow W \\
\dim(V) &= \dim(\range(T)) + \dim(\kernel(T))
\end{align}
\end{document}