Problem with \_ in hyperref. Was Re: [OS X TeX] Verbatim mode question...

Ross Moore ross at ics.mq.edu.au
Tue Jun 18 18:53:03 EDT 2002



> 
> If I try to use \_ in an \href (from the hyperref package) as in:
> 
> 	\newcommand{\ljuser}[2]
> 	{\href{http://www.livejournal.com/userinfo.bml?user=#1}{{\sf #1} (#2)}}
> 
> The problem is that if I use it as in:
> 
> 	\ljuser{foo_bar}{blah}
> 
> the \sf does NOT like the unescaped underscore.
> 
> Is there a way for me to deal with this without a kludge like having 
> to give it 3 arguments, with 2 of them being the same except for how 

Not really; for there are quite distinct interpretations for _

 1.  as  character 95 (underscore) in latin1, for URLs
 2.  underscores in text (via \_ ) are not characters at all:
      \def\_{\leavevmode \kern.06em \vbox{\hrule width.3em}}
     (from  plain.tex )
     This draws the underline as a TeX rule.

In TeX's usual OT1-encoded fonts, character 95 is an accent.


> underscores are given, as in:
> 
> 	\ljuser{foo_bar}{foo\_bar}{blah}

You can make this simpler to use by having the 1st argument optional:

\newcommand{\ljuser}[3][]{\bgroup
  \def\tmp{#1}\def\empty{}%
  \ifx\tmp\empty
        \href{http://www.livejournal.com/userinfo.bml?user=#2}{{\sf #2} (#3)}%
  \else
        \href{http://www.livejournal.com/userinfo.bml?user=#1}{{\sf #2} (#3)}%
  \fi
 \egroup}


Now both of these work as expected:

\ljuser[foo_bar]{foo\_bar}{blah}
\ljuser{index.html}{directory page}


Note the [..]  that can be used only when needed, to get around
problems with special characters due to different font encodings
or macro expansions between the URL portion and the visible text.



Hope this helps,

	Ross

> 
> Josh
> -- 
> ----------------------------------------------------------------------------
> Josh Hodas / Associate Professor        Office Phone: (909) 621-8650
> Director, Computer Science Clinic       Clinic Sec'y: (909) 607-8379
> Computer Science / Harvey Mudd College  Home Phone:   (909) 625-1179
> 1250 North Dartmouth Avenue             E-Mail:       hodas at cs.hmc.edu
> Claremont, CA 91711                     WWW :  http://www.cs.hmc.edu/~hodas/
> 
> -----------------------------------------------------------------
> Threaded list archives can be found at:
> <http://www.masda.vxu.se/~pku/MacOSX_TeX/>
> -----------------------------------------------------------------
> To UNSUBSCRIBE, send email to <info at email.esm.psu.edu> with
> "unsubscribe macosx-tex" (no quotes) in the body.
> For additional HELP, send email to <info at email.esm.psu.edu> with
> "help" (no quotes) in the body.
> -----------------------------------------------------------------


-----------------------------------------------------------------
Threaded list archives can be found at:
<http://www.masda.vxu.se/~pku/MacOSX_TeX/>
-----------------------------------------------------------------
To UNSUBSCRIBE, send email to <info at email.esm.psu.edu> with
"unsubscribe macosx-tex" (no quotes) in the body.
For additional HELP, send email to <info at email.esm.psu.edu> with
"help" (no quotes) in the body.
-----------------------------------------------------------------




More information about the MacOSX-TeX mailing list