
Imitei Donald Knuth definindo |
como um delimitador literal. Para dar seu significado normal no modo matemático, defini
\everymath{\catcode`\|=12}
\everydisplay{\catcode`\|=12}
No entanto, eu gostaria deacrescentarisso em \everymath
vez de apagar seu conteúdo anterior (se houver). eu tentei
\everymath{a}
\everymath{\the\everymath b}
mas não funciona. Qualquer ideia?
PS: esta pergunta é para TeX simples.
Responder1
O método não funcionará: se você tiver, digamos,
\section{Proof that $|x|\ge 0$}
a configuração de \catcode`|=12
não teria efeito, porque |
já teria sido tokenizada.
A maneira mais segura é dizer
\catcode`|=\active
\protected\def|{\ifmmode\expandafter\vert\else\expandafter\activebar\fi}
\def\activebar{...<whatever you want>...}
Se você quiser usar o Plain TeX sem extensões e-TeX, o comando resultante seria bastante frágil, então use com cuidado:
\def|{\relax\ifmmode\expandafter\vert\else\expandafter\activebar\fi}
(você encontra o motivo \relax
no TeXbook).
Vamos tentar um 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
Você consegue
! Argument of \\ has an extra }.
<inserted text>
\par
<to be read again>
}
porque |
já foi tokenizado quando o argumento de \beginsection
estava sendo absorvido.
Com
\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
você não recebe nenhum erro e a saída é a esperada:
Responder2
A. Ellet deu a resposta nos comentários (editar: apenas uma \expandafter
é necessária):
\everymath{a}
\everymath\expandafter{\the\everymath b}
define \everymath
paraab