
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 \everymath
lugar 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`|=12
no 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 \relax
en 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 \beginsection
se 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:
Respuesta2
A. Ellet dio la respuesta en los comentarios (editar: solo \expandafter
se necesita uno):
\everymath{a}
\everymath\expandafter{\the\everymath b}
se establece \everymath
enab