[texhax] HTML specials with '_' character

Michael M. Tung michael.m.tung at gmail.com
Sun Feb 17 20:27:54 CET 2008


Reinhard Kotucha [reinhard.kotucha at web.de] wrote:
> Michael M. Tung writes:
>  > Hi!
>  > 
>  > I have problems with my following macro in plain TeX
>  > 
>  > \def\mailto#1{
>  >   \special{html:<a href="mailto:#1">}%
>  >           {\tt #1}
>  >   \special{html:</a>}
>  > 	 }
>  > 
>  > which creates a hyperlink for mailing in the final PDF
>  > file. For standard emails with letters and '@' it works
>  > fine. However such things as
>  > 
>  >   \mailto{test_user at yahoo.com}
>  > 
>  > creates an error requiring math mode for '_'.  Defining
> 
> 
> \catcode`\_=12
> \def\mailto{\catcode`\_=12\relax\@mailto}
> 
> \def\@mailto#1{
>   \special{html:<a href="mailto:#1">}%
>           {\tt #1}
>   \special{html:</a>}
>   \catcode`\_=8\relax}
> \catcode`\_=8
> 
> $$ a_1 $$
> 
> \mailto{test_user at yahoo.com}
> 
> $$ a_2 $$
> \end
> 
> 
> \mailto changes the catcode and calls \@mailto, which takes the
> argument. \@mailto also has to restore the catcode.
> 
> The catcode of _ has be be set to 12 while the macro is read and has
> to be restored later.  This is not necessary if you replace `\_ by the
> ASCII character number, for instance \catcode95=12.
> 
> Regards,
>   Reinhard
> 

Dear Reinhard,

many thanks for your speedy reply for the \mailto which now works
perfectly!

I was trying to use the same logic to add another special macro to
my style file, e.g. altogether the code would have

\catcode`\_=12
\def\mailto{\catcode`\_=12\relax\@mailto}
\def\@mailto#1{
  \special{html:<a href="mailto:#1">}%
          {\tt #1}
  \special{html:</a>}
  \catcode`\_=8\relax
  }
\catcode`\_=8

\catcode`\~=12
\def\href{\catcode`\~=12\relax\@href}
\def\@href#1#2{
  \special{html:<a href="#1">}%
          {\tt #2}
  \special{html:</a>}
  \catcode`\~=13\relax
}
\catcode`\~13

For \href the only difference is that I used catcode assignment 13
to mark the '~' active at the end. Unfortunately I get the following
error log:

! Use of \@ doesn't match its definition.
\mailto ->\catcode `\_=12\relax \@m
                                   ailto
l.12 \mailto
            {test_user at yahoo.com}

What I am doing wrong? I don't see where I redefine '\@'...

Best, Mike




More information about the texhax mailing list