Agregar una lista de tokens a \everymath

Agregar una lista de tokens a \everymath

He imitado a Donald Knuth estableciéndolo |como delimitador palabra por palabra. Para darle su significado normal en modo matemático, he configurado

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

Sin embargo me gustaríaadjuntaresto en \everymathlugar de borrar su contenido anterior (si lo hubiera). He intentado

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

pero no funciona. ¿Alguna idea?

PD: esta pregunta es para TeX simple.

Respuesta1

El método no funcionará: si tienes, digamos,

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

la configuración de \catcode`|=12no tendría efecto porque |ya habría sido tokenizada.

La forma más segura es decir

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

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

Si desea utilizar Plain TeX sin extensiones e-TeX, el comando resultante sería bastante frágil, así que utilícelo con cuidado:

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

(Encontrarás el motivo \relaxen el TeXbook).


Probemos con un documento 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

Usted obtiene

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

porque |ya ha sido tokenizado cuando \beginsectionse absorbió el argumento de.

Con

\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

no obtiene ningún error y el resultado es el esperado:

ingrese la descripción de la imagen aquí

Respuesta2

A. Ellet dio la respuesta en los comentarios (editar: solo \expandafterse necesita uno):

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

se establece \everymathenab

información relacionada