I have a XeLaTeX document in which I want some unicode symbols to be auto-substituted, like ¼ → 1/4, » → >>, « → <<. But instead of a long list like
\catcode`\¼=\active\def¼{1/4}
\catcode`\«=\active\def«{<<}
...
I want something more elegant, like
\subst¼{1/4}
\subst«{<<}
\subst—{---}
So, I need a macro which will take two parameters, make #1 active, and \def it with #2. The first part was easy:
\def\subst#1#2{
\catcode`#1=\active
...
}
The tricky part is the nested \def: no matter how I try, I cannot come up with anything working. The closest I got so far is defining commands like \¼ with
\expandafter\def\csname #1\endcsname{#2}
Which is of course not sufficient :)
How do I make it define those newly-made-active characters?
<<→«:-) – Andrey Vihrov May 13 '11 at 08:56pdflatex? – Martin Scharrer May 13 '11 at 09:33