Short version
Is there a way to pipe every symbol in a math environment unevaluated to an external program w/o manipulating the (La)TeX file directly (except for adding header files) or patching TeX itself?
Longer version
I wrote a program which performs certain transformations on (La)TeX code in mathmode. Until now I used to implement a very simplified TeX interpreter (doesn't follow \include
s/\usepackage
s etc.), which filtered out code between the usual suspects ($
…$
pairs, \begin
…\end{equation}
etc.). This approach fails when facing newly defined math environments or constructs which only partly work in mathmode.
So now I want to use the already existing TeX compiler to my advantage and want it to filter the crucial mathmode parts out for me (I'd then use \write18
or something to communicate with my external application). But I figured that redefining all the math environments or even the $
…$
or $$
…$$
pairs fails since this approach isn't safe against manipulation with symbol category codes (a user could just define |
to be the new $
).
So far the only thing I found which was related to automatically finding mathmode environments are the commands \everymath
and \everydisplay
. Unfortunately, I can't seem to figure out how to use them to accomplish my goals.
`
to mark your inline code as I did in my edit.$
enters math mode, and warn the user that he/she should not break them. A user willing to use your software will have no problems in complying.