例子

例子

我想编写一些宏,如果前面有指定的宏,其行为会发生变化。具体来说,我有一些控制符号(数学运算符,如 、 等)的宏,\det它们\trace在另一个字段中有对应部分,它们的名称以“super-”为前缀,所以我考虑在超级数学中为超级符号编写 、 等\super\det\super\trace

这也许也是一个糟糕的想法,但现在我只是想知道它是否可行的

例子

我正在写一些关于超级数学的笔记,它就像普通数学一样……但是极好的(即 Z2 级)。我们几乎在所有事物前都加上“超级”前缀。

我想要这样的东西:

\documentclass{article}
% ... amsmath packages omitted, but probably needed

% vanilla mathematical operators
\DeclareMathOperator\tr{tr}
\DeclareMathOperator\det{det}
\def\commutator#1#2{[#1, #2]}

% any operator with "\super" preceding it is defined
% to behave according to the declarations within this body
\prefixRedefs{\super}{
  \DeclareMathOperator\tr{str} % super trace
  \DeclareMathOperator\det{Ber} % super det are called Berezinians
  \def\commutator#1#2{[#1, #2\}}
}

\begin{document}
In Linear algebra, we have $\det(A)$, but super linear
algebra has $\super\det(A)$. Supermatrices may be given
a super commutator $\super\commutator{A}{B}$ and we get
a super Lie algebra; just as normal matrices may be given
the commutator $\commutator{A}{B}$ to produce a Lie algebra.
\end{document}

我理想情况下想获得\super\det生产Ber\super\trace生产str等等,按照前缀环境所指定的方式。

答案1

你可以这样做:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\makesuper}[2]{%
  % #1 = \DeclareMathOperator or \newcommand or \DeclareRobustCommand
  % #2 = macro name
  \expandafter#1\csname super\string#2\endcsname
}
\DeclareRobustCommand{\super}[1]{%
  \ifcsname super\string#1\endcsname
    \csname super\string#1\expandafter\endcsname
  \else
    \expandafter\ERROR
  \fi
}

\DeclareMathOperator{\tr}{tr}
\newcommand{\commutator}[2]{[#1,#2]}

\makesuper\DeclareMathOperator{\det}{Ber}
\makesuper\DeclareMathOperator{\tr}{str}
\makesuper\newcommand{\commutator}[2]{[#1,#2\}}

\begin{document}

$\det A-\tr A+\commutator{X}{Y}$

$\super\det A-\super\tr A+\super\commutator{X}{Y}$

\super\ddt

\end{document}

最后一个将产生

! Undefined control sequence.
<recently read> \ERROR

l.30 \super\ddt

在此处输入图片描述

不要使用\def,即使实际上允许\makesuper

相关内容