[texhax] What's wrong with \catcode`\_=12

Yue Wu vanopen at gmail.com
Thu Oct 6 04:52:43 CEST 2011


On Thu, Oct 06, 2011 at 02:53:00AM +0200, Heiko Oberdiek wrote:
> On Thu, Oct 06, 2011 at 08:29:21AM +0800, Yue Wu wrote:
> 
> > I want to define a macro to let _ can be directly used in it but failed,
> > The minimum failed example:
> > 
> > \def\mytest#1{{\chardef\_=95 \catcode`\_=12 #1}}
> > \mytest{foo_bar}
> 
> The definition text of \mytest is executed *after* the macro's
> argument is read and tokenized. Therefore the catcode change
> comes too late. If \mytest is not used inside the argument
> of other commands, the catcode can be changed the following way:

Thank you for detailed explanation!

> 
> \def\mytest{%
>   \begingroup
>   \catcode`\_=12 %
>   \mytesti
> }
> \def\mytesti#1{%
>   \endgroup
>   #1%
> }
> \mytest{foo_bar}
> 
> What's the purpose of "\chardef\_=95"?


I want the char `_' to produce a literal `_' as it is, but with the
macros following, it will produce a `˙'.


> That "\_" prints as "_"?
> 
> \def\mytest{%
>   \begingroup
>   \catcode`\_=12 %
>   \mytesti
> }
> \def\mytesti#1{%
>   \chardef\_=95 %
>   #1%
>   \endgroup
> }
> \mytest{foo_bar\_bla}
> 
> Yours sincerely
>   Heiko Oberdiek
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
> 
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University(中國藥科大學)
No.24, Tongjia Xiang Street, Nanjing 210009, China


More information about the texhax mailing list