lang-url.mkiv /size: 5154 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=lang-url,
3
%D version=2008.01.22, % used to be lang-mis
4
%D title=\CONTEXT\ Language Macros,
5
%D subtitle=Language Options,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\registerctxluafile
{
lang
-
url
}{}
15 16
\unprotect
17 18
%D Traditionally this code is in the language namespace as
19
%D hyphenation relates to languages.
20 21
%D \macros
22
%D {hyphenatedurl}
23
%D
24
%D For those who want to put full \URL's in a text, we offer
25
%D
26
%D \startbuffer
27
%D \hyphenatedurl{http://optimist.optimist/optimist/optimist.optimist#optimist}
28
%D \stopbuffer
29
%D
30
%D \typebuffer
31
%D
32
%D which breaks at the appropriate places. Watch the \type{#}
33
%D hack.
34
%D
35
%D When passed as argument, like in \type {\goto}, one needs
36
%D to substitute a \type {\\} for each \type{#}.
37
%D
38
%D \startbuffer
39
%D \hyphenatedurl{http://this.is.a.rather/strange/reference#indeed}
40
%D \stopbuffer
41
%D
42
%D \typebuffer
43 44
\newtoks
\everyhyphenatedurl
45 46
\appendtoks
47
\resetfontfeature
48
\resetcharacterspacing
49
%
50
\let
\&
\letterampersand
51
\let
\#
\letterhash
52
\let
\~
\lettertilde
53
\let
\\
\letterbackslash
54
\let
\$
\letterdollar
55
\let
\^
\letterhat
56
\let
\_
\letterunderscore
57
\let
\{
\letterleftbrace
58
\let
\}
\letterrightbrace
59
\let
\|
\letterbar
60
\let
~
=
\lettertilde
61
\let
|
=
\letterbar
62
\let
\Ux\eUx
63
\to
\everyhyphenatedurl
64 65
\let
\hyphenatedurlseparator
\empty
% \periodcentered
66
\let
\hyphenatedurldiscretionary
\empty
67 68
\setnewconstant
\hyphenatedurllefthyphenmin
\plusthree
69
\setnewconstant
\hyphenatedurlrighthyphenmin
\plusthree
70 71
\def
\lang_url_more
{
\penalty
\plustenthousand
\hskip
\scratchskipone
\penalty
\plustenthousand
}
72
\def
\lang_url_less
{
\penalty
\plustenthousand
\hskip
\scratchskiptwo
\penalty
\plustenthousand
}
73
\def
\lang_url_trac
{
\penalty
\plustenthousand
\hsmash
{
\darkred
\vl
}
\penalty
\plustenthousand
}
74 75
\def
\lang_url_a
#
1
{
\lang_url_more
\char
#
1
\lang_url_show
\discretionary
{}{
\hyphenatedurlseparator
}{}}
76
\def
\lang_url_b
#
1
{
\lang_url_more
\discretionary
{
\hyphenatedurlseparator
}{}{}
\lang_url_show
\char
#
1
\relax
}
77
\def
\lang_url_d
{
\lang_url_more
\discretionary
{
\lang_url_show
}{
\lang_url_show
}{
\lang_url_show
}}
78
\def
\lang_url_l
#
1
{
\lang_url_less
\char
#
1
\relax
}
79
\def
\lang_url_c
#
1
{
\lang_url_more
\char
#
1
\relax
}
80
\def
\lang_url_L
#
1
{
\lang_url_less
\char
#
1
\relax
}
81
\def
\lang_url_C
#
1
{
\lang_url_more
\char
#
1
\relax
}
82 83
\unexpanded
\def
\showhyphenatedurlbreaks
% for old times sake
84
{
\let
\lang_url_show
\lang_url_trac
}
85 86
\installtextracker
87
{
languages
.
url
}
88
{
\let
\lang_url_show
\lang_url_trac
}
89
{
\let
\lang_url_show
\relax
}
90 91
\let
\lang_url_show
\relax
92 93
\unexpanded
\def
\sethyphenatedurlnormal
#
1
{
\clf_sethyphenatedurlcharacters
{
#
1
}{
\v!normal
}}
94
\unexpanded
\def
\sethyphenatedurlbefore
#
1
{
\clf_sethyphenatedurlcharacters
{
#
1
}{
\v!before
}}
95
\unexpanded
\def
\sethyphenatedurlafter
#
1
{
\clf_sethyphenatedurlcharacters
{
#
1
}{
\v!after
}}
96 97
% \sethyphenatedurlafter{ABCDEF}
98 99
\unexpanded
\def
\hyphenatedurl
#
1
%
100
{
\dontleavehmode
101
\begingroup
102
\the
\everyhyphenatedurl
103
\normallanguage
\zerocount
104
\let
\a
\lang_url_a
% after
105
\let
\b
\lang_url_b
% before
106
\let
\d
\lang_url_d
% disc
107
\let
\l
\lang_url_l
% letter
108
\let
\c
\lang_url_c
% character
109
\let
\L
\lang_url_L
% letter_nobreak
110
\let
\C
\lang_url_C
% character_nobreak
111
\scratchskipone
\zeropoint
\s!plus
\dimexpr
\emwidth
/
1
2
\s!minus
\dimexpr
\emwidth
/
2
4
\relax
% 1.00pt @ 12pt
112
\scratchskiptwo
\zeropoint
\s!plus
\dimexpr
\emwidth
/
4
8
\s!minus
\dimexpr
\emwidth
/
9
6
\relax
% 0.25pt @ 12pt
113
\normalexpanded
{
\noexpand
\clf_hyphenatedurl
114
{
\noexpand\detokenize
{
#
1
}}
%
115
\hyphenatedurllefthyphenmin
116
\hyphenatedurlrighthyphenmin
117
{
\hyphenatedurldiscretionary
}
%
118
}
%
119
\endgroup
}
120 121
%D \macros
122
%D {hyphenatedfilename}
123
%D
124
%D For the moment we treat filenames in a similar way,
125
%D
126
%D \starttyping
127
%D \hyphenatedfilename{here/there/filename.suffix}
128
%D \stoptyping
129 130
\ifx
\hyphenatedfilename
\undefined
\let
\hyphenatedfilename\hyphenatedurl
\fi
131 132
% \def\test#1%
133
% {\dontleavehmode
134
% \begingroup
135
% \tttf
136
% \hyphenatedurl {%
137
% \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
138
% \letterhash #1\letterhash #1\letterpercent #1\letterslash #1\letterampersand
139
% }%
140
% \endgroup}
141 142
% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
143 144
\protect
\endinput
145 146
% \setuppapersize[A7]
147
%
148
% \unexpanded\def\WhateverA#1%
149
% {\dontleavehmode
150
% \begingroup
151
% \prehyphenchar"B7\relax
152
% \setbox\scratchbox\hbox{\tttf#1}%
153
% \prehyphenchar`-\relax
154
% \unhbox\scratchbox
155
% \endgroup}
156
%
157
% \unexpanded\def\WhateverB#1%
158
% {\dontleavehmode
159
% \begingroup
160
% \tttf
161
% \prehyphenchar\minusone
162
% % \localrightbox{\llap{_}}%
163
% \localrightbox{\llap{\smash{\lower1.5ex\hbox{\char"2192}}}}%
164
% \setbox\scratchbox\hbox{#1}%
165
% \prehyphenchar`-\relax
166
% \unhbox\scratchbox
167
% \endgroup}
168
%
169
% \begingroup \hsize1cm
170
% \WhateverA{thisisaboringandverylongcommand}\par
171
% \WhateverB{thisisaboringandverylongcommand}\par
172
% \endgroup
173