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
|
%D \module
%D [ file=lang-url,
%D version=2008.01.22, % used to be lang-mis
%D title=\CONTEXT\ Language Macros,
%D subtitle=Language Options,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\unprotect
%D This is rather old code. The following solution was used
%D for a long time and is kind of built-up over the years.
\ifx\\\undefined \let\\\crlf \fi
%D \macros
%D {hyphenatedurl}
%D
%D For those who want to put full \URL's in a text, we offer
%D
%D \startbuffer
%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
%D \stopbuffer
%D
%D \typebuffer
%D
%D which breaks at the appropriate places. Watch the \type{#}
%D hack.
%D
%D When passed as argument, like in \type {\goto}, one needs
%D to substitute a \type {\\} for each \type{#}.
%D
%D \startbuffer
%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
%D \stopbuffer
%D
%D \typebuffer
\ifx\urlsplitmode\undefined \chardef\urlsplitmode\plusone \fi
% 0 => don't split
% 1 => . : na, rest voor
% 2 => alles na
% 3 => alles voor
% \bgroup \catcode`\~=\active \catcode`\/=\active
%
% \unexpanded\gdef\hyphenatedurl#1% {}{} handles accents
% {\bgroup
% \ifnum\hyphenpenalty<10000 \else
% \def\discretionary##1##2##3{##1\allowbreak##2}%
% \fi
% \obeyhyphens
% \def\splitbefore##1%
% {\setbox\scratchbox=\hbox{##1{}{}}%
% \ifcase\urlsplitmode
% \box\scratchbox
% \or
% \postwordbreak\box\scratchbox\prewordbreak
% \or
% \prewordbreak\discretionary{\box\scratchbox}{}{\box\scratchbox}\prewordbreak
% \else
% \postwordbreak\box\scratchbox\prewordbreak
% \fi}%
% \def\splitafter##1%
% {\ifcase\urlsplitmode
% ##1{}{}%
% \or
% \prewordbreak\discretionary{##1{}{}}{}{##1{}{}}\prewordbreak
% \or
% \prewordbreak\discretionary{##1{}{}}{}{##1{}{}}\prewordbreak
% \else
% \prewordbreak\discretionary{}{##1{}{}}{##1{}{}}\prewordbreak
% \fi}%
% \def\splitanyway##1%
% {\prewordbreak##1\prewordbreak}%
% \def\flushurl%
% {\savedurl\let\savedurl\empty}%
% \def\\%
% {\spliturl\#}%
% \let\~=\lettertilde\let~=\~%
% \let\/=\letterslash\let/=\/%
% \let\savedurl\empty
% \scratchcounter\zerocount % used for hyphenmethod
% \handletokens#1\with\scanurl\savedurl
% \egroup}
%
% \egroup
% \chardef\urlhyphenmethod=0
% \def\scanurl#1%
% {\advance\scratchcounter\plusone
% \ifx#1\blankspace
% \flushurl\splitanyway\normalspace
% \else\ifx#1\ %
% \flushurl\splitanyway\normalspace
% \else\ifx#1\space
% \flushurl\splitanyway\normalspace
% \else\ifx#1\~%
% \flushurl\splitbefore\~%
% \else\ifx#1\#%
% \flushurl\splitbefore\#%
% \else\ifx#1\&%
% \flushurl\splitbefore\&%
% \else\ifx#1\%%
% \flushurl\splitbefore\%%
% \else\ifx#1\_%
% \flushurl\splitbefore\_%
% \else\if\noexpand#1\relax
% #1%
% \else\ifnum\catcode`#1=8
% \flushurl\splitbefore\_%
% \else\ifnum\catcode`#1=6
% \flushurl\splitbefore\#%
% \else\ifnum\catcode`#1=4
% \flushurl\splitbefore\&%
% \else\expandafter\if\string#1\lettertilde
% \flushurl\splitbefore\~%
% \else\expandafter\if\string#1\letterpercent
% \flushurl\splitbefore\%%
% \else\expandafter\if\string#1\letterunderscore
% \flushurl\splitbefore\_%
% \else\expandafter\if\string#1\letterquestionmark
% \flushurl\splitafter\letterquestionmark
% \else\expandafter\if\string#1\letterat
% \flushurl\splitafter\letterat
% \else\expandafter\if\string#1\letterslash
% \edef\savedurl{\savedurl\letterslash}%
% \else\expandafter\if\string#1+%
% \flushurl\splitafter+%
% \else\expandafter\if\string#1:%
% \flushurl\splitafter:%
% \else\expandafter\if\string#1.%
% \flushurl\splitafter.%
% \else\expandafter\if\string#1(%
% \flushurl\splitbefore(%
% \else\expandafter\if\string#1)%
% \flushurl\splitafter)%
% \else
% \ifx\savedurl\empty\else
% \splitbefore\savedurl
% \let\savedurl\empty
% \fi
% \ifcase\urlhyphenmethod
% \string#1%
% \else
% \ifnum\scratchcounter>\plusthree % so, \http: will not break
% \edef\savedurl{\string#1}%
% \else
% \string#1%
% \fi
% \fi
% \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
%D The following approach takes more resources but is cleaner (after all, we now
%D have huge \TEX's. It's is basically a \TEX\ version of the \MKIV\ variant.
\newtoks\everyhyphenatedurl
\appendtoks
\let\&\letterampersand
\let\#\letterhash
\let\~\lettertilde
\let\\\letterbackslash
\let\$\letterdollar
\let\^\letterhat
\let\_\letterunderscore
\let\{\letterleftbrace
\let\}\letterrightbrace
\let\|\letterbar
\let~=\lettertilde
\let|=\letterbar
\to \everyhyphenatedurl
\def\hyphenatedurlseparator{} % \periodcentered
\def\dohyphenatedurlnormal#1{\char#1\relax}%
\def\dohyphenatedurlafter #1{\char#1\discretionary{}{\hyphenatedurlseparator}{}}%
\def\dohyphenatedurlbefore#1{\discretionary{\hyphenatedurlseparator}{}{}\char#1\relax}%
% 0=normal 1=before 2=after
\def\sethyphenatedurlnormal#1{\expandafter\chardef\csname url @ #1\endcsname\zerocount}
\def\sethyphenatedurlbefore#1{\expandafter\chardef\csname url @ #1\endcsname\plusone }
\def\sethyphenatedurlafter #1{\expandafter\chardef\csname url @ #1\endcsname\plustwo }
\sethyphenatedurlbefore !
\sethyphenatedurlbefore "
\sethyphenatedurlbefore \letterhash
\sethyphenatedurlbefore \letterdollar
\sethyphenatedurlbefore \letterpercent
\sethyphenatedurlbefore \letterampersand
\sethyphenatedurlbefore (
\sethyphenatedurlbefore *
\sethyphenatedurlbefore +
\sethyphenatedurlbefore ,
\sethyphenatedurlbefore -
\sethyphenatedurlbefore .
\sethyphenatedurlbefore /
\sethyphenatedurlbefore :
\sethyphenatedurlbefore ;
\sethyphenatedurlbefore <
\sethyphenatedurlbefore =
\sethyphenatedurlbefore >
\sethyphenatedurlbefore ?
\sethyphenatedurlbefore @
\sethyphenatedurlbefore [
\sethyphenatedurlbefore \letterbackslash
\sethyphenatedurlbefore ^
\sethyphenatedurlbefore _
\sethyphenatedurlbefore `
\sethyphenatedurlbefore \letteropenbrace
\sethyphenatedurlbefore \letterbar
\sethyphenatedurlbefore \lettertilde
\sethyphenatedurlafter '
\sethyphenatedurlafter )
\sethyphenatedurlafter ]
\sethyphenatedurlafter \letterclosebrace
\unexpanded \def\hyphenatedurl#1%
{\dontleavehmode
\begingroup
\the\everyhyphenatedurl
\edef\ascii{#1}%
\expanded{\handletokens{\detokenize\expandafter{\ascii}}}\with\dohyphenatedurl
\endgroup}
\def\dohyphenatedurl#1%
{\ifcase\executeifdefined{url @ #1}\zerocount\relax
\expandafter\dohyphenatedurlnormal
\or
\expandafter\dohyphenatedurlbefore
\or
\expandafter\dohyphenatedurlafter
\fi{\number`#1}}
% maybe ... to be finished
%
% \def\hyphenatedstring#1%
% {\bgroup
% \nohyphens
% \def\next##1{##1\doif{##1}{-}{\allowbreak}}%
% \handletokens#1\with\next
% \egroup}
%
% {\hsize1cm\hyphenatedstring{ABXXXXXXXXXXC-12345-12345}}
%D \macros
%D {hyphenatedfilename}
%D
%D For the moment we treat filenames in a similar way,
%D
%D \starttyping
%D \hyphenatedfilename{here/there/filename.suffix}
%D \stoptyping
\ifx\hyphenatedfilename\undefined \let\hyphenatedfilename\hyphenatedurl \fi
% \def\test#1%
% {\dontleavehmode
% \begingroup
% \tttf
% \hyphenatedurl {%
% \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
% \letterhash #1\letterhash #1\letterpercent #1\letterslash #1\letterampersand
% }%
% \endgroup}
% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
\protect \endinput
% \bgroup
% \gdef\lettercolon{:}
% \catcode`\:=\active
% \catcode`\^=\active
% \catcode`\/=\active
% \catcode`\~=\active
% \gdef\theurlcolon {\nobreak\hbox{\lettercolon}\allowbreak}
% \gdef\theurlslash#1{\nobreak\hbox{\letterslash}\ifx#1\relax\else\ifnum`/=\expandafter`\string#1\else\allowbreak\fi#1\fi}
% \gdef\theurlhat {\allowbreak\hbox{\letterhat}\nobreak}
% \gdef\theurltilde {\allowbreak\hbox{\lettertilde}\nobreak}
% \gdef\ForMojcaWhoLikesHacks#1%
% {\dontleavehmode
% \begingroup
% \mathcode`\:="8000 \let:\theurlcolon
% \mathcode`\^="8000 \let^\theurlhat
% \mathcode`\/="8000 \let/\theurlslash
% \mathcode`\~="8000 \let~\theurltilde
% \everymath\emptytoks
% \mathsurround\zeropoint$\tf#1\relax$%
% \endgroup}
% \egroup
% \hsize 1mm \ForMojcaWhoLikesHacks{http://www.sil.org//silesr/}
|