summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/doi/doi.sty
blob: 5d8e5dbcfce1ed3976d7dc9f1b69cd64902be1b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{doi}[2007/07/24 handle doi numbers]

%% This style file is based original code written by Heiko Oberdiek 
%% and published on comp.text.tex. It was packaged with permission  
%% 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.
%%
%% Original discussion on Google under:
%% http://groups.google.com/group/comp.text.tex/msg/922919daa207d613
%%
%% You can hyperlink DOI numbers to dx.doi.org. Some publishers have elected to 
%% use some nasty characters in their doi numbering scheme (<, >, ; have all 
%% been spotted). This will either upset (La)TeX, or your pdf reader. This style 
%% file contains a user-level command \doi{}, which takes a doi number, 
%% and creates a hyperlink from it. The format of the doi can be controlled by 
%% redefining the \doitext command, which does not take an argument (unlike the
%% command with the same name in the doipubmed package). 
%%
%% Note: the \doi{} command connot be used within other macros.
 
%% Change history:
%% December 15, 2003: original code posted on Usenet (see link above)
%% Somewhere in 2005: Bruno Voisin suggests some changes to accomodate the 
%%     Apple pdf framework on the Tex on Mac OS X mailing list.
%% April 2007: Maarten packages the lot, and Karl Ove Hufthammer fixes a 
%%     few bugs introduced by Maarten (oops).
%%     A \doitext command is added, following the example from doipubmed.
%%     Some comments are added to make the code a little more readable.
%% July 2007: Michael Orlov sends in a patch to correctly handle underscores.

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

%% to change the default prefix, redefine this command within your own code.
%% It takes no argument, which is different from the doipubmed package.
\newcommand{\doitext}{doi:}

%% the meat of the code
%% the first command opens a group, and changes a few catcodes.
\newcommand*{\doi}{% 
  \begingroup 
  \lccode`\~=`\#\relax 
  \lowercase{\def~{\#}}%
  \lccode`\~=`\_\relax
  \lowercase{\def~{\_}}%
  \lccode`\~=`\<\relax 
  \lowercase{\def~{\textless}}%
  \lccode`\~=`\>\relax 
  \lowercase{\def~{\textgreater}}%
  \lccode`\~=0\relax 
  \catcode`\#=\active 
  \catcode`\_=\active 
  \catcode`\<=\active 
  \catcode`\>=\active 
  \@doi
}

%% this is the actual command which processes the argument, with the catcodes 
%% set in the previous command
%% it closes the group, and spits out the url.
\def\@doi#1{% 
  \let\#\relax
  \let\_\relax
  \let\textless\relax 
  \let\textgreater\relax 
  \edef\x{\toks0={{#1}}}% 
  \x
  \edef\#{\@percentchar23}%
  \edef\_{_}%
  \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\doitext\the\toks1 \the\toks0}%
  \x
}

%% that's all folks.
\endinput