dmaze ([personal profile] dmaze) wrote2007-02-16 10:22 am
Entry tags:

Parsing -- gotta love it

In knee-jerk reaction to something that appeared on comp.compilers, I figured I'd go off and write a TeX file that defined, and invoked, a macro named \{} (that is, the name of the macro is \{}, not empty).


% create a strangely-named macro
\expandafter\def\csname {}\endcsname{foo}

% invoke it
\catcode`\{=11
\catcode`\}=11
\{}

% switch back to sanity and quit
\catcode`\{=1
\catcode`\}=2
\bye



This has all kinds of terrible implications. Mostly they're only exploited by the LaTeX \makeatletter and \makeatother macros to "hide" things from non-package code. But nothing actually stops you from creating a macro named \$; if I understand the implications of \active, nothing stops you from creating a macro named just $ either and thereby confusing everybody who expects math mode.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org