3

I'd like to use in math mode instead the only letter g the \mbox{g} (with another tail). How possible to redefine it globally? I found example to redefine letter z:

\catcode`\z=\active \def z{Yawn, I'm tired}

But it does not work for letter g! The code

\catcode`\g=\active \def g{\mbox{g}}

returns errors.

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
nail
  • 101

1 Answers1

9

Making letters into active characters is definitely not a good idea.

For instance, after

\catcode`\g=\active

you are not allowed to use \begin any more.

For math mode there's a different solution:

\begingroup\lccode`~=`g \lowercase{\endgroup\def~}{\mbox{g}}
\mathcode`g="8000

This makes g into a math active character; since \mbox switches to text mode, the g will not cause problems.


With \catcode`\g=\active \def g{\mbox{g}} you're basically doing the same as

\def\foo{\mbox{\foo}}

which starts an infinite loop as soon as \foo is expanded.

egreg
  • 1,121,712