
答え1
答え2
およびの演算子+
および-
は、egregの+=
-=
答え+
これは、TeX では/-
との間にスペースが設定されず=
、式全体の+=
/ が-=
前後のスペースに関する関係記号になるためです。
この回答は自動的な解決法を試みます。+
および-
記号は、数式モードでのみアクティブになります。次に、アクティブな文字は、等号が続くかどうかを確認できます。 正の場合、+
および-
演算子の関係バージョンが使用され、そうでない場合は元のバイナリ バージョンが採用されます。
以下との互換性を得るには、少しの追加作業が必要ですamsmath
:
\documentclass{article}
\usepackage{amsmath}
% save original binary + and - as \binplus and \binminus
\mathchardef\binplus=\the\mathcode`+
\mathchardef\binminus=\the\mathcode`-
% define relational + and -
\mathchardef\relplus=\numexpr\the\binplus + "1000\relax
\mathchardef\relminus=\numexpr\the\binminus + "1000\relax
% define active + and -, which check for a following =
\makeatletter
\catcode`+=\active
\catcode`-=\active
\def+{\@ifnextchar=\relplus\binplus}
\def-{\@ifnextchar=\relminus\binminus}
\@makeother\+
\@makeother\-
\makeatother
% enable active + and - for math mode
\AtBeginDocument{%
\mathcode`+="8000\relax
\mathcode`-="8000\relax
}
% patch \newmcodes@ of package `amsopn.sty'
\usepackage{etoolbox}
\makeatletter
\@ifpackageloaded{amsopn}{%
\patchcmd\newmcodes@{%
\mathchardef\std@minus\mathcode`\-\relax
}{%
\let\std@minus\binminus
}{}{\errmessage{\noexpand\newmcodes@ could not be patched}}%
}{}
\makeatother
\begin{document}
\[
a += b + c \qquad x -= y - z \qquad \operatorname{foo-bar}
\]
\end{document}