-
Notifications
You must be signed in to change notification settings - Fork 0
/
breakurl.sty
309 lines (282 loc) · 8.07 KB
/
breakurl.sty
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
%%
%% This is file `breakurl.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% breakurl.dtx (with options: `package')
%%
%% This is a generated file.
%%
%% Copyright (C) 2005 by Vilar Camara Neto.
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.2 of this license or (at your option) any later
%% version. The latest version of this license is in:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.2 or later is part of all distributions of
%% LaTeX version 1999/12/01 or later.
%%
%% Currently this work has the LPPL maintenance status "maintained".
%%
%% The Current Maintainer of this work is Vilar Camara Neto.
%%
%% This work consists of the files breakurl.dtx and
%% breakurl.ins and the derived file breakurl.sty.
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{breakurl}
[2009/01/24 v1.30 Breakable hyperref URLs]
\RequirePackage{xkeyval}
\RequirePackage{ifpdf}
\ifpdf
% Dummy package options
\DeclareOptionX{preserveurlmacro}{}
\DeclareOptionX{hyphenbreaks}{}
\DeclareOptionX{vertfit}{}
\ProcessOptionsX\relax
\PackageWarning{breakurl}{%
You are using breakurl while processing via pdflatex.\MessageBreak
\string\burl\space will be just a synonym of \string\url.\MessageBreak}
\DeclareRobustCommand{\burl}{\url}
\DeclareRobustCommand*{\burlalt}{\hyper@normalise\burl@alt}
\def\burl@alt#1#2{\hyper@linkurl{\Hurl{#1}}{#2}}
\expandafter\endinput
\fi
\@ifpackageloaded{hyperref}{}{%
\PackageError{breakurl}{The breakurl depends on hyperref package}%
{I can't do anything. Please type X <return>, edit the source file%
\MessageBreak
and add \string\usepackage\string{hyperref\string} before
\string\usepackage\string{breakurl\string}.}
\endinput
}
\newif\if@preserveurlmacro\@preserveurlmacrofalse
\newif\if@burl@fitstrut\@burl@fitstrutfalse
\newif\if@burl@fitglobal\@burl@fitglobalfalse
\newtoks\burl@toks
\let\burl@charlistbefore\empty
\let\burl@charlistafter\empty
\def\burl@addtocharlistbefore{\g@addto@macro\burl@charlistbefore}
\def\burl@addtocharlistafter{\g@addto@macro\burl@charlistafter}
\bgroup
\catcode`\&=12\relax
\hyper@normalise\burl@addtocharlistbefore{%}
\hyper@normalise\burl@addtocharlistafter{:/.?#&_,;!}
\egroup
\def\burl@growmif#1#2{%
\g@addto@macro\burl@mif{\def\burl@ttt{#1}\ifx\burl@ttt\@nextchar#2\else}%
}
\def\burl@growmfi{%
\g@addto@macro\burl@mfi{\fi}%
}
\def\burl@defifstructure{%
\let\burl@mif\empty
\let\burl@mfi\empty
\expandafter\@tfor\expandafter\@nextchar\expandafter:\expandafter=%
\burl@charlistbefore\do{%
\expandafter\burl@growmif\@nextchar\@burl@breakbeforetrue
\burl@growmfi
}%
\expandafter\@tfor\expandafter\@nextchar\expandafter:\expandafter=%
\burl@charlistafter\do{%
\expandafter\burl@growmif\@nextchar\@burl@breakaftertrue
\burl@growmfi
}%
}
\AtEndOfPackage{\burl@defifstructure}
\def\burl@setvertfit#1{%
\lowercase{\def\burl@temp{#1}}%
\def\burl@opt{local}\ifx\burl@temp\burl@opt
\@burl@fitstrutfalse\@burl@fitglobalfalse
\else\def\burl@opt{strut}\ifx\burl@temp\burl@opt
\@burl@fitstruttrue\@burl@fitglobalfalse
\else\def\burl@opt{global}\ifx\burl@temp\burl@opt
\@burl@fitstrutfalse\@burl@fitglobaltrue
\else
\PackageWarning{breakurl}{Unrecognized vertfit option `\burl@temp'.%
\MessageBreak
Adopting default `local'}
\@burl@fitstrutfalse\@burl@fitglobalfalse
\fi\fi\fi
}
\DeclareOptionX{preserveurlmacro}{\@preserveurlmacrotrue}
\DeclareOptionX{hyphenbreaks}{%
\bgroup
\catcode`\&=12\relax
\hyper@normalise\burl@addtocharlistafter{-}%
\egroup
}
\DeclareOptionX{vertfit}[local]{\burl@setvertfit{#1}}
\ProcessOptionsX\relax
\def\burl@hyper@linkurl#1#2{%
\begingroup
\hyper@chars
\burl@condpdflink{#1}%
\endgroup
}
\def\burl@condpdflink#1{%
\literalps@out{
/burl@bordercolor {\@urlbordercolor} def
/burl@border {\@pdfborder} def
}%
\if@burl@fitstrut
\sbox\pdf@box{#1\strut}%
\else\if@burl@fitglobal
\sbox\pdf@box{\burl@url}%
\else
\sbox\pdf@box{#1}%
\fi\fi
\dimen@\ht\pdf@box\dimen@ii\dp\pdf@box
\sbox\pdf@box{#1}%
\ifdim\dimen@ii=\z@
\literalps@out{BU.SS}%
\else
\lower\dimen@ii\hbox{\literalps@out{BU.SS}}%
\fi
\ifHy@breaklinks\unhbox\else\box\fi\pdf@box
\ifdim\dimen@=\z@
\literalps@out{BU.SE}%
\else
\raise\dimen@\hbox{\literalps@out{BU.SE}}%
\fi
\pdf@addtoksx{H.B}%
}
\DeclareRobustCommand*{\burl}{%
\leavevmode
\begingroup
\let\hyper@linkurl=\burl@hyper@linkurl
\catcode`\&=12\relax
\hyper@normalise\burl@
}
\DeclareRobustCommand*{\burlalt}{%
\begingroup
\let\hyper@linkurl=\burl@hyper@linkurl
\catcode`\&=12\relax
\hyper@normalise\burl@alt
}
\newif\if@burl@breakbefore
\newif\if@burl@breakafter
\newif\if@burl@prevbreakafter
\bgroup
\catcode`\&=12\relax
\gdef\burl@#1{%
\def\burl@url{#1}%
\def\burl@urltext{#1}%
\burl@doit
}
\gdef\burl@alt#1{%
\def\burl@url{#1}%
\hyper@normalise\burl@@alt
}
\gdef\burl@@alt#1{%
\def\burl@urltext{#1}%
\burl@doit
}
\gdef\burl@doit{%
\burl@toks{}%
\let\burl@UrlRight\UrlRight
\let\UrlRight\empty
\@burl@prevbreakafterfalse
\@ifundefined{@urlcolor}{\Hy@colorlink\@linkcolor}{\Hy@colorlink\@urlcolor}%
\expandafter\@tfor\expandafter\@nextchar\expandafter:\expandafter=%
\burl@urltext\do{%
\if@burl@breakafter\@burl@prevbreakaftertrue
\else\@burl@prevbreakafterfalse\fi
\@burl@breakbeforefalse
\@burl@breakafterfalse
\expandafter\burl@mif\burl@mfi
\if@burl@breakbefore
% Breakable if the current char is in the `can break before' list
\burl@flush\linebreak[0]%
\else
\if@burl@prevbreakafter
\if@burl@breakafter\else
% Breakable if the current char is not in any of the `can break'
% lists, but the previous is in the `can break after' list.
% This mechanism accounts for sequences of `break after' characters,
% where a break is allowed only after the last one
\burl@flush\linebreak[0]%
\fi
\fi
\fi
\expandafter\expandafter\expandafter\burl@toks
\expandafter\expandafter\expandafter{%
\expandafter\the\expandafter\burl@toks\@nextchar}%
}%
\let\UrlRight\burl@UrlRight
\burl@flush
\literalps@out{BU.E}%
\Hy@endcolorlink
\endgroup
}
\egroup
\def\the@burl@toks{\the\burl@toks}
\def\burl@flush{%
\expandafter\def\expandafter\burl@toks@def\expandafter{\the\burl@toks}%
\literalps@out{/BU.L (\burl@url) def}%
\hyper@linkurl{\expandafter\Hurl\expandafter{\burl@toks@def}}{\burl@url}%
\global\burl@toks{}%
\let\UrlLeft\empty
}%
\if@preserveurlmacro\else\let\url\burl\let\urlalt\burlalt\fi
\AtBeginDvi{%
\headerps@out{%
/burl@stx null def
/BU.S {
/burl@stx null def
} def
/BU.SS {
currentpoint
/burl@lly exch def
/burl@llx exch def
burl@stx null ne {burl@endx burl@llx ne {BU.FL BU.S} if} if
burl@stx null eq {
burl@llx dup /burl@stx exch def /burl@endx exch def
burl@lly dup /burl@boty exch def /burl@topy exch def
} if
burl@lly burl@boty gt {/burl@boty burl@lly def} if
} def
/BU.SE {
currentpoint
/burl@ury exch def
dup /burl@urx exch def /burl@endx exch def
burl@ury burl@topy lt {/burl@topy burl@ury def} if
} def
/BU.E {
BU.FL
} def
/BU.FL {
burl@stx null ne {BU.DF} if
} def
/BU.DF {
BU.BB
[ /H /I /Border [burl@border] /Color [burl@bordercolor]
/Action << /Subtype /URI /URI BU.L >> /Subtype /Link BU.B /ANN pdfmark
/burl@stx null def
} def
/BU.BB {
burl@stx HyperBorder sub /burl@stx exch def
burl@endx HyperBorder add /burl@endx exch def
burl@boty HyperBorder add /burl@boty exch def
burl@topy HyperBorder sub /burl@topy exch def
} def
/BU.B {
/Rect[burl@stx burl@boty burl@endx burl@topy]
} def
/eop where {
begin
/@ldeopburl /eop load def
/eop { SDict begin BU.FL end @ldeopburl } def
end
} {
/eop { SDict begin BU.FL end } def
} ifelse
}%
}
\endinput
%%
%% End of file `breakurl.sty'.