\everymathにトークンリストを追加する

\everymathにトークンリストを追加する

私はドナルド・クヌースを真似て、|逐語的な区切り文字として設定しました。数式モードで通常の意味を持たせるために、私は設定しました。

\everymath{\catcode`\|=12}
\everydisplay{\catcode`\|=12}

しかし私は追加\everymath以前の内容(もしあれば)を消去するのではなく、これを変更してください。私は試してみました

\everymath{a}
\everymath{\the\everymath b}

しかし、動作しません。何かアイデアはありますか?

PS: この質問はプレーン TeX に関するものです。

答え1

この方法は機能しません。例えば、

\section{Proof that $|x|\ge 0$}

の設定は、すでにトークン化されている\catcode`|=12ため有効になりません。|

最も安全な方法は

\catcode`|=\active
\protected\def|{\ifmmode\expandafter\vert\else\expandafter\activebar\fi}

\def\activebar{...<whatever you want>...}

e-TeX 拡張機能なしで Plain TeX を使用する場合、結果のコマンドは非常に脆弱になるため、注意して使用してください。

\def|{\relax\ifmmode\expandafter\vert\else\expandafter\activebar\fi}

(その理由は\relaxTeXbookに記載されています)。


Plain TeX ドキュメントを試してみましょう:

\input manmac
\everymath\expandafter{\the\everymath\catcode`|=12 }
\everydisplay\expandafter{\the\everydisplay\catcode`|=12 }

\beginsection $|x|$ is never negative.

|the $p$-norm| is
$$
\Vert x\Vert=\root p\of{|x_1|^p+\cdots+|x_n|^p}
$$
\bye

あなたは得る

! Argument of \\ has an extra }.
<inserted text> 
                \par 
<to be read again> 
                   }

|の引数が\beginsection吸収されたときに、すでにトークン化されているためです。

\input manmac

\let\manmacbar| % after manmac | is active
\protected\def|{%
  \ifmmode
    \expandafter\vert
  \else
    \expandafter\manmacbar
  \fi
}

\beginsection $|x|$ is never negative.

|the $p$-norm| is
$$
\Vert x\Vert=\root p\of{|x_1|^p+\cdots+|x_n|^p}
$$
\bye

エラーは発生せず、出力は期待どおりになります。

ここに画像の説明を入力してください

答え2

A. Ellet がコメントで答えました (編集:\expandafter必要なのは 1 つだけです):

\everymath{a}
\everymath\expandafter{\the\everymath b}

\everymathに設定するab

関連情報