# [texhax] making underscore a letter

Morten Høgholm morten.hoegholm at gmail.com
Thu Apr 19 14:42:08 CEST 2007

On 4/19/07, Adam ENDRODI <borso at vekoll.saturnus.vein.hu> wrote:

> Do you know about a compelling reason why '_' is left to be the
> subscription character in normal mode in LaTeX?
>
> I'm writing a package of authoring macros, some of them are like
>
> \def\Code#1{\hypertarget{#1}{\texttt{#1}}}
>
> so later #1 can be \hyperlink-ed.  Now, \Code{some_funny_function()}
> is obviously a problem: left as it is makes latex complaint, escaping
> the underscores makes hyperref think weird things.
>
> To cut the problem short I've decided to make '_' a letter, so latex
> would accept it in normal mode:
>
> \catcode_=11
> \everymath\expandafter{\the\everymath\catcode_=8}
> \everydisplay\expandafter{\the\everydisplay\catcode_=8}
>
> What I'd like to know is, do you agree with this approach?
> What trouble should I prepare for?

The usual trouble of trying to change catcodes on the fly: Once an
argument is read, catcodes are locked and can't change, unless you go
via \scantokens or a temporary file (which is what \scantokens is only
much faster).

Take a look at the package underscore. Instructions in the package
file itself IIRC.
--
Morten
`