Wednesday, March 5, 2008

Assign another catcode

The actual and more elegant solution for my problem with verbatim text in argument position decribed in the previous post is much simpler. Since the underscore “_” is the only nasty character which does not allow me to write things like “NA071112-01_E.008” as an argument of my \ru command the best solution for me is to assign the underscore another catcode (thanks to Enrico Gregorio). This simply achieved by …


\catcode`\_=12


… in the preamble. Thereby the underscore looses its subscript function (category code 8) and is treated like any other puctuation character (category code 12).

As a linguist I do not need the underscore as a shortcut for subscript in math mode. If I want, I can still do it by “\sb” instead of the “_”. (\sb is actually short enough.)

I then can define my \ru just like this:


\providecommand{\ru}[1]{#1}


(I may want to fill it with additional commands later.)

I get the feeling that changing the category code of certain special characters may be the most accessible (if not the only) way of accepting verbatim text as an argument of a command.

This whole thing around my \ru command motivates me to go through some introduction to TeX. Very nice explanation of catcodes and their purpose I found in Eijkhout’s TeX by Topic on p. 29.

D. E. Knuth certainly was a smart guy.

4 comments:

melroch said...

You shouldn't say "Knuth was a smart guy". He is a smart guy — an old man but still around. You really scared me!

Thanks for a great blog, BTW!

/BP — phiilologist and household chore hacker.

Anonymous said...

Found the solution to your problem. If you still care. :)

See "LaTeX and those pesky underscores!"

It basically boils down to

\begingroup \catcode_=\active
\gdef\foo{\begingroup\catcode_=\active\foox}
\gdef\foox{... do real work ...\endgroup}
\endgroup

buying term papers said...

I think I should say that your site in many respects opened my eyes on this matter.

buy a term paper said...

Today I made ​​a great discovery for himself / bagodarya only your site and this article