summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/plain/zztex/zzhyper.tex
blob: cf20d36eb2bd75ed3ba64871c07b410f984af20f (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Module:    PDF Hyperlink Facility
%
% Synopsis:  This module provides facilities for creating PDF hyperlinks
%            in the document.
%
% Author:    Paul C. Anagnostopoulos
% Created:   12 March 2014
%
% Copyright 1989--2020 by Paul C. Anagnostopoulos
% under The MIT License (opensource.org/licenses/MIT)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%                       Control Hyperlinking
%                       ------- ------------


% If hyperlinking is turned off, then we also clear the button color.

\def \setPDFhyperlinks #1{%
  \global\setflag \PDFhyperlinks = #1\relax
  \if \notp{#1}\PDFbuttoncolor = {}\fi}

%                       Hyperlink Marks
%                       --------- -----


% This macro generates a hyperlink mark that can be used as the target
% of a button.

\def \PDFmark #1{%
  \if \PDFhyperlinks
    \special{mark: #1}%
    \if \vmodep \repeatpenalty \fi      % In case glue follows \special.
  \fi}

%                       Hyperlink Buttons
%                       --------- -------


\def \pagebutton #1#2{%                                         {folio}{text}
  \if \PDFhyperlinks
    \ztextbutton{P:#1}{#2}%
    \if \emptytoksp{\PDFbuttoncolor}%
      #2%
    \else
      \colortext{\the\PDFbuttoncolor}{#2}%
    \fi
  \else
    #2%
  \fi}

\def \tagbutton #1#2{%                                          {tag}{text}
  \if \PDFhyperlinks
    \ztextbutton{T:#1}{#2}%
    \if \emptytoksp{\PDFbuttoncolor}%
      #2%
    \else
      \colortext{\the\PDFbuttoncolor}{#2}%
    \fi
  \else
    #2%
  \fi}

\def \URLbutton #1#2{%                                          {URL}{text}
  \if \PDFhyperlinks
    \ztextbutton{#1}{#2}%
    \if \emptytoksp{\PDFbuttoncolor}%
      #2%
    \else
      \colortext{\the\PDFbuttoncolor}{#2}%
    \fi
  \else
    #2%
  \fi}

\def \colorbuttontext {%
  \if \andp{\PDFhyperlinks}{\notp{\emptytoksp{\PDFbuttoncolor}}}%
    \color{\the\PDFbuttoncolor}%
  \fi}

\def \endcolorbuttontext {%
  \if \andp{\PDFhyperlinks}{\notp{\emptytoksp{\PDFbuttoncolor}}}%
    \endcolor
  \fi}

%                       Low-Level Button Macros
%                       --------- ------ ------


% These low-level macros do not check \PDFhyperlinks.


\def \ztextbutton #1#2{%                                        {mark}{text}
  \measuretextwidth{\tdimena}{#2}%
  \zwidthbutton{#1}{\tdimena}}

\def \zwidthbutton #1#2{%                                       {mark}{width-expr}
  \calculate \tdimena = {#2}%
  \if \hmodep
    \smash{\lower .5ex \hbox{%
      \special{button: \number\tdimena\space
                       \number\normalbaselineskip\space #1}}}%
  \else
      \special{button: \number\tdimena\space
                       \number\normalbaselineskip\space #1}%
  \fi}

\def \zURLbutton #1#2{%                                         {url}{text}
  \measuretextwidth{\tdimena}{#2}%
  \def \zurltext {#1}%
  \smash{\lower .5ex \hbox{%
    \special{button: \number\tdimena\space
                     \number\normalbaselineskip\space
                     \expandafter\zdefof \meaning\zurltext\zmark}}}}

%                       Email Addresses and URLs
%                       ----- --------- --- ----


\def \zurlprefix {}


\def \urltext #1#2{%                            {font}{break before .?}{url}
  \bgroup
    #1%
    \setflag \zurldotbreak = #2%
    \catcode `\& = \catactive
    \catcode `\. = \catactive
    \catcode `\/ = \catactive
    \catcode `\@ = \catactive
    \catcode `\_ = \catactive
    \zurltexta}

\def \zurltexta #1{%                            {url}
  \zurltextb #1\-\-\zmark}

\def \zurltextb #1\-#2\-#3\zmark{%              part1\-part2\-part3\zmark
  \expandafter\def \expandafter\zfullurl \expandafter{\zurlprefix #1#2}%
  \zurltextc{#1}%
  \if \notp{\emptyargp{#2}}%
    \break
    \zurltextc{#2#3}%
  \fi
  \egroup
  \gdef \zurlprefix {}}

{\catcode `\& = \catactive
 \catcode `\. = \catactive
 \catcode `\/ = \catactive
 \catcode `\@ = \catactive
 \catcode `\_ = \catactive

\gdef \zurltextc #1{%                           {url-text}
  \def &{\ampersand \discretionary{}{}{}}%      % Break after &
  \let \& = &%
  \if \zurldotbreak
    \def .{\discretionary{}{}{}\char"2E }%      % Break before .
  \else
    \def .{\char"2E \discretionary{}{}{}}%      % Break after .
  \fi
  \def /{\char"2F \discretionary{}{}{}}%        % Break after /
  \def @{\atsign \discretionary{}{}{}}%         % Break after @
  \let \@ = @%
  \let _ = \underscore                          % Set _
  \let ~ = \tilde                               % Set ~
  \def \-{\discretionary{}{}{}}%                % No hyphenation
  \if \PDFhyperlinks
    \expandafter\zURLbutton \expandafter{\zfullurl}{#1}%
  \fi
  \colorbuttontext
    #1%
  \endcolorbuttontext}

} % \catcode

%                       Digital Object Identifiers
%                       ------- ------ -----------


\def \DOI {%                                                    {number}
  \def \zurlprefix {http://dx.doi.org/}%
  \ensurepar \url}