[texhax] HTML specials with '_' character

Reinhard Kotucha reinhard.kotucha at web.de
Sun Feb 17 15:20:27 CET 2008


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

-- 
----------------------------------------------------------------------------
Reinhard Kotucha			              Phone: +49-511-4592165
Marschnerstr. 25
D-30167 Hannover	                      mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------


More information about the texhax mailing list