Debian Codegraph @

texmf-dist/tex/plain/zztex/zzhyper.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: PDF Hyperlink Facility
4 %
5 % Synopsis: This module provides facilities for creating PDF hyperlinks
6 % in the document.
7 %
8 % Author: Paul C. Anagnostopoulos
9 % Created: 12 March 2014
10 %
11 % Copyright 1989--2020 by Paul C. Anagnostopoulos
12 % under The MIT License (opensource.org/licenses/MIT)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 % Control Hyperlinking
17 % ------- ------------
18
19
20 % If hyperlinking is turned off, then we also clear the button color.
21
22 \def \setPDFhyperlinks #1{%
23 \global\setflag \PDFhyperlinks = #1\relax
24 \if \notp{#1}\PDFbuttoncolor = {}\fi}
25
26 % Hyperlink Marks
27 % --------- -----
28
29
30 % This macro generates a hyperlink mark that can be used as the target
31 % of a button.
32
33 \def \PDFmark #1{%
34 \if \PDFhyperlinks
35 \special{mark: #1}%
36 \if \vmodep \repeatpenalty \fi % In case glue follows \special.
37 \fi}
38
39 % Hyperlink Buttons
40 % --------- -------
41
42
43 \def \pagebutton #1#2{% {folio}{text}
44 \if \PDFhyperlinks
45 \ztextbutton{P:#1}{#2}%
46 \if \emptytoksp{\PDFbuttoncolor}%
47 #2%
48 \else
49 \colortext{\the\PDFbuttoncolor}{#2}%
50 \fi
51 \else
52 #2%
53 \fi}
54
55 \def \tagbutton #1#2{% {tag}{text}
56 \if \PDFhyperlinks
57 \ztextbutton{T:#1}{#2}%
58 \if \emptytoksp{\PDFbuttoncolor}%
59 #2%
60 \else
61 \colortext{\the\PDFbuttoncolor}{#2}%
62 \fi
63 \else
64 #2%
65 \fi}
66
67 \def \URLbutton #1#2{% {URL}{text}
68 \if \PDFhyperlinks
69 \ztextbutton{#1}{#2}%
70 \if \emptytoksp{\PDFbuttoncolor}%
71 #2%
72 \else
73 \colortext{\the\PDFbuttoncolor}{#2}%
74 \fi
75 \else
76 #2%
77 \fi}
78
79 \def \colorbuttontext {%
80 \if \andp{\PDFhyperlinks}{\notp{\emptytoksp{\PDFbuttoncolor}}}%
81 \color{\the\PDFbuttoncolor}%
82 \fi}
83
84 \def \endcolorbuttontext {%
85 \if \andp{\PDFhyperlinks}{\notp{\emptytoksp{\PDFbuttoncolor}}}%
86 \endcolor
87 \fi}
88
89 % Low-Level Button Macros
90 % --------- ------ ------
91
92
93 % These low-level macros do not check \PDFhyperlinks.
94
95
96 \def \ztextbutton #1#2{% {mark}{text}
97 \measuretextwidth{\tdimena}{#2}%
98 \zwidthbutton{#1}{\tdimena}}
99
100 \def \zwidthbutton #1#2{% {mark}{width-expr}
101 \calculate \tdimena = {#2}%
102 \if \hmodep
103 \smash{\lower .5ex \hbox{%
104 \special{button: \number\tdimena\space
105 \number\normalbaselineskip\space #1}}}%
106 \else
107 \special{button: \number\tdimena\space
108 \number\normalbaselineskip\space #1}%
109 \fi}
110
111 \def \zURLbutton #1#2{% {url}{text}
112 \measuretextwidth{\tdimena}{#2}%
113 \def \zurltext {#1}%
114 \smash{\lower .5ex \hbox{%
115 \special{button: \number\tdimena\space
116 \number\normalbaselineskip\space
117 \expandafter\zdefof \meaning\zurltext\zmark}}}}
118
119 % Email Addresses and URLs
120 % ----- --------- --- ----
121
122
123 \def \zurlprefix {}
124
125
126 \def \urltext #1#2{% {font}{break before .?}{url}
127 \bgroup
128 #1%
129 \setflag \zurldotbreak = #2%
130 \catcode `\& = \catactive
131 \catcode `\. = \catactive
132 \catcode `\/ = \catactive
133 \catcode `\@ = \catactive
134 \catcode `\_ = \catactive
135 \zurltexta}
136
137 \def \zurltexta #1{% {url}
138 \zurltextb #1\-\-\zmark}
139
140 \def \zurltextb #1\-#2\-#3\zmark{% part1\-part2\-part3\zmark
141 \expandafter\def \expandafter\zfullurl \expandafter{\zurlprefix #1#2}%
142 \zurltextc{#1}%
143 \if \notp{\emptyargp{#2}}%
144 \break
145 \zurltextc{#2#3}%
146 \fi
147 \egroup
148 \gdef \zurlprefix {}}
149
150 {\catcode `\& = \catactive
151 \catcode `\. = \catactive
152 \catcode `\/ = \catactive
153 \catcode `\@ = \catactive
154 \catcode `\_ = \catactive
155
156 \gdef \zurltextc #1{% {url-text}
157 \def &{\ampersand \discretionary{}{}{}}% % Break after &
158 \let \& = &%
159 \if \zurldotbreak
160 \def .{\discretionary{}{}{}\char"2E }% % Break before .
161 \else
162 \def .{\char"2E \discretionary{}{}{}}% % Break after .
163 \fi
164 \def /{\char"2F \discretionary{}{}{}}% % Break after /
165 \def @{\atsign \discretionary{}{}{}}% % Break after @
166 \let \@ = @%
167 \let _ = \underscore % Set _
168 \let ~ = \tilde % Set ~
169 \def \-{\discretionary{}{}{}}% % No hyphenation
170 \if \PDFhyperlinks
171 \expandafter\zURLbutton \expandafter{\zfullurl}{#1}%
172 \fi
173 \colorbuttontext
174 #1%
175 \endcolorbuttontext}
176
177 } % \catcode
178
179 % Digital Object Identifiers
180 % ------- ------ -----------
181
182
183 \def \DOI {% {number}
184 \def \zurlprefix {http://dx.doi.org/}%
185 \ensurepar \url}