\everyath에 토큰 목록 추가

\everyath에 토큰 목록 추가

나는 |축어적 구분 기호로 설정하여 Donald Knuth를 모방했습니다. 수학 모드에서 일반적인 의미를 부여하기 위해 다음과 같이 설정했습니다.

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

하지만 나는 그러고 싶다추가\everymath이전 콘텐츠(있는 경우)를 지우는 대신 이 작업을 수행합니다 . 난 노력 했어

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

하지만 작동하지 않습니다. 어떤 아이디어?

추신: 이 질문은 일반 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}

\relax( TeXbook에서 그 이유를 찾을 수 있습니다 ).


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필요함).

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

\everymath다음으로 설정ab

관련 정보