I know this is not something that you’re supposed to do. But for fun, I played around with the idea of changing the \mathcode
of all letters to "8000
and defining them as commands. Each such command would then correspond to the variable with that symbol. Below, I tried doing this with the letter j
, though it partly failed. Similarly, I would like to redefine +
, -
, and all the other common math symbols.
So far, everything seems to work more or less as before. Command names, environment names, and key names containing j
seem to work just fine. I have four questions:
- Which LaTeX functionality would you break if you did this for all letters? What if you did it for common symbols like
+
and-
? - How can I fix the below MWE so that
j
simply printsj
(using\oldletter
caused a loop)? - Am I doing it the “right way”, or should I rather use a different construction, e.g. using
\everymath
,\everydisplay
, and\AtBeginDocument
? - What would be the best way to wrap all of this functionality into a single command, called something like
\RedefineMathLetter{<letter>}
or\RedefineMathSymbol{<symbol>}
?
\documentclass{article}
\let\oldletter=j
\mathcode`\j="8000
\catcode`\j=\active
\NewDocumentCommand{j}{ o }{%
J% using \oldletter caused a loop
\IfValueT{#1}{_{#1}}%
}
\catcode`\j=11
\begin{document}
\( j = j[1] \)
\end{document}