我想为线性函数的范围定义一个新的运算符。因为我是德国人,所以我想以一种根据所用语言而变化的方式来定义它。
\documentclass{scrartcl}
\usepackage[english]{babel}
\usepackage{amsmath}
\DeclareMathOperator{\range}{ran}
\DeclareMathOperator{\kernel}{ker}
% The following should be used if german or ngerman are defined for babel
% \DeclareMathOperator{\range}{Bild}
% \DeclareMathOperator{\kernel}{Kern}
\begin{document}
\begin{align}
T &: V \rightarrow W \\
\dim(V) &= \dim(\range(T)) + \dim(\kernel(T))
\end{align}
\end{document}
有没有简单的方法可以实现这一点?
答案1
在我看来,定义应该是这样的,即使语言发生变化,操作员也不会在整个文档中发生改变。
因此,如果主要语言是德语,\ker
则在英语中也应解析为“Kern”。但是,也很容易提供“变量”类型。
\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}
可选参数用于与先前选择中未包含的语言一起使用的字符串。
english
如果和ngerman
被交换,则输出如下。
答案2
\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}
答案3
我会坚持旧的\operatorname
并将它与babel
的结合起来\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}