[OS X TeX] OT: setting the look of hyperlinks with hyperref

Bruno Voisin bvoisin at mac.com
Mon Mar 29 05:57:00 EST 2004


Hi,

This is an OT posting in case some of the hyperref gurus on this list 
are listening. I've looked _very_ briefly at FAQs and at a 
comp.text.tex archive, but found no answer.

In short: is there an obvious interface for setting precisely the look 
of hyperlinks with hyperref.sty, without having to redefine low-level 
commands?

In all the gory details: I'm writing, in LaTeX, a PDF report calling 
the hyperref package and inserting hyperlinks through \url (for 
hyperlinks written in full) and \href (for hyperlinks anchored to some 
text). I've chosen the links to appear colored, which is achieved by 
setting the option colorlinks to true:

	\usepackage[dvipsnames]{color}
	\usepackage[colorlinks=true,
	            urlcolor=myblue,
	            linkcolor=myred,
	            bookmarks=true,
	            pdfstartview=FitH]{hyperref}

	\definecolor{myblue}  {named}{MidnightBlue}
	\definecolor{myred}   {named}{RedViolet}

At the same time, this option suppresses the box (invisible in Preview, 
visible in Adobe Reader) around the hyperlink.

Alas, in the same report I'm also using text coloring as a way to 
highlight different concepts:

	\definecolor{mygreen} {named}{PineGreen}
	\definecolor{myorange}{named}{Tan}
	\definecolor{mygrey}  {named}{CadetBlue}

	\newcommand{\link}[1]{\textcolor{mygreen}{#1}}
	\newcommand{\field}[1]{<<~\textcolor{myorange}{#1}~>>}
	\newcommand{\choice}[1]{<<~\textcolor{mygrey}{#1}~>>}

and I would like the hyperlinks to be visually different, so that no 
ambiguity arises, for example, for somebody reading a printed version 
of the report.

Hence I thought of having the hyperlinks colored _and_ underlined, as 
is usual with web browsers. Spending some time in the guts of 
hyperref.sty, and also getting the documented source code hyperref.dtx, 
I finally came out for \url (built on \url@) with the replacement of:

	\def\url@#1{\hyper at linkurl{\Hurl{#1}}{#1}}

by

	\def\url@#1{\hyper at linkurl{\underline{\Hurl{#1}}}{#1}}

and for \href (built on \href@ built on \href at split built on 
\hyper@@link built on \hyper at link@) with the replacement of:

	\def\hyper at link@[#1]#2#3#4{%
	  \protected at edef\Hy at tempa{#2}%
	  \ifx\Hy at tempa\@empty
	    \hyper at link{#1}{#3}{#4}%
	  \else
	    \expandafter\hyper at readexternallink#2\\{#1}{#3}{#4}%
	  \fi
	}

by

	\def\hyper at link@[#1]#2#3#4{%
	  \protected at edef\Hy at tempa{#2}%
	  \ifx\Hy at tempa\@empty
	    \hyper at link{#1}{#3}{\underline{#4}}%
	  \else
	    \expandafter\hyper at readexternallink#2\\{#1}{#3}{\underline{#4}}%
	  \fi
	}

It works, but I'm confused: is it really necessary to go to such 
low-level commands (especially in the second case)? Is there an obvious 
solution or interface that I've missed?

Bruno Voisin

-----------------------------------------------------
Please see <http://www.esm.psu.edu/mac-tex/> for list
guidelines, information, and LaTeX/TeX resources.





More information about the MacOSX-TeX mailing list