[OS X TeX] Hyperlink failure with TeXShop and Preview

Bruno Voisin bvoisin at mac.com
Sat Feb 10 11:22:54 CET 2007


Le 10 févr. 07 à 10:45, Maarten Sneep a écrit :

> Yes, that is possible. Search for "Reformat Strings for DOI-Links"  
> in comp.text.tex on google (groups).
> I've packaged the code in a style file. Perhaps it is a good idea  
> to ask Heiko to put it in a small style file on CTAN. It is not  
> completely trivial.

Many thanks Maarten, that's exactly what I had been looking for.

However, it doesn't work as is: for hyperlinks containing "<" and ">"  
to be recognized by Preview and TeXShop, you need to edit two lines  
of the macro, replacing

     \edef\textless{\string<}%
     \edef\textgreater{\string>}%

by

     \edef\textless{\@percentchar3C}%
     \edef\textgreater{\@percentchar3E}%

Then I can simply use:

\doi{10.1002/1099-095X(200102)12:1<57::AID-ENV446>3.0.CO;2-1}

instead of:

\href{http://dx.doi.org/10.1002/1099-095X(200102)12:1\%3C57::AID- 
ENV446\%3E3.0.CO;2-1}
      {DOI:10.1002/1099-095X(200102)12:1<57::AID-ENV446>3.0.CO;2-1}

To summarize: in order to make my little primitive macro

\newcommand{\doi}[1]{\href{http://dx.doi.org/#1}{doi:#1}}

work in all cases, you have to use instead Heiko Oberdiek's (slightly  
edited) code:

\makeatletter
\newcommand*{\doi}{%
   \begingroup
     \lccode`\~=`\#\relax
     \lowercase{%
       \def~{\#}%
     }%
     \lccode`\~=`\<\relax
     \lowercase{%
       \def~{\textless}%
     }%
     \lccode`\~=`\>\relax
     \lowercase{%
       \def~{\textgreater}%
     }%
     \lccode`\~=0\relax
     \catcode`\#=\active
     \catcode`\<=\active
     \catcode`\>=\active
     \@doi
}%
\def\@doi#1{%
     \let\#\relax
     \let\textless\relax
     \let\textgreater\relax
     \edef\x{%
       \toks0={{doi:#1}}%
     }%
     \x
     \edef\#{\@percentchar23}%
     \edef\textless{\@percentchar3C}%
     \edef\textgreater{\@percentchar3E}%
     \edef\x{%
       \toks1={\noexpand\href{http://dx.doi.org/#1}}%
     }%
     \x
     \edef\x{%
       \endgroup
       \the\toks1 \the\toks0 %
     }%
   \x
}
\makeatother

Hope this may help others as well,

Bruno Voisin
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the macostex-archives mailing list