\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{doi}[2005/03/24 handle doi numbers]
%% original code written by Heiko Oberdiek and published on comp.text.tex
%% Packaged as a style file by Maarten Sneep, with some minor 
%% changes suggested by Bruno Voisin to accomodate the Apple 
%% pdf framework
%%
%% This code is placed under the LPPL

%% We need hyperref, but you probably want to load hyperref 
%% beforehand, or set some options later on.
\RequirePackage{hyperref}

\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={{#1}}}% 
  \x
  \edef\#{\@percentchar23}%
  \edef\textless{\@percentchar3C}% instead of {\string<} for Apple
  \edef\textgreater{\@percentchar3E}% instead of {\sting>} for Apple
  \edef\x{\toks1={\noexpand\href{http://dx.doi.org/#1}}}% 
  \x
  \edef\x{\endgroup\the\toks1 \the\toks0}
  \x
}
