lang-url.mkiv /size: 4972 b    last modification: 2021-10-28 13:50
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 % \nohyphens in mkiv
104   \scratchskipone\zeropoint\s!plus\dimexpr\emwidth/12\s!minus\dimexpr\emwidth/24\relax % 1.00pt @ 12pt
105   \scratchskiptwo\zeropoint\s!plus\dimexpr\emwidth/48\s!minus\dimexpr\emwidth/96\relax % 0.25pt @ 12pt
106   \unprotect
107   \normalexpanded{\noexpand\clf_hyphenatedurl
108     {\noexpand\detokenize{#1}}%
109     \hyphenatedurllefthyphenmin
110     \hyphenatedurlrighthyphenmin
111     {\hyphenatedurldiscretionary}%
112   }%
113   \protect
114   \endgroup}
115
116%D \macros
117%D   {hyphenatedfilename}
118%D
119%D For the moment we treat filenames in a similar way,
120%D
121%D \starttyping
122%D \hyphenatedfilename{here/there/filename.suffix}
123%D \stoptyping
124
125\ifx\hyphenatedfilename\undefined \let\hyphenatedfilename\hyphenatedurl \fi
126
127% \def\test#1%
128%   {\dontleavehmode
129%    \begingroup
130%    \tttf
131%    \hyphenatedurl {%
132%      \letterampersand #1\letterampersand #1\letterampersand #1\letterampersand #1\letterampersand
133%      \letterhash      #1\letterhash      #1\letterpercent   #1\letterslash     #1\letterampersand
134%    }%
135%    \endgroup}
136
137% \dorecurse{100}{\test{a} \test{ab} \test{abc} \test{abcd} \test{abcde} \test{abcdef}}
138
139\protect \endinput
140
141% \setuppapersize[A7]
142%
143% \unexpanded\def\WhateverA#1%
144%   {\dontleavehmode
145%    \begingroup
146%    \prehyphenchar"B7\relax
147%    \setbox\scratchbox\hbox{\tttf#1}%
148%    \prehyphenchar`-\relax
149%    \unhbox\scratchbox
150%    \endgroup}
151%
152% \unexpanded\def\WhateverB#1%
153%   {\dontleavehmode
154%    \begingroup
155%    \tttf
156%    \prehyphenchar\minusone
157%  % \localrightbox{\llap{_}}%
158%    \localrightbox{\llap{\smash{\lower1.5ex\hbox{\char"2192}}}}%
159%    \setbox\scratchbox\hbox{#1}%
160%    \prehyphenchar`-\relax
161%    \unhbox\scratchbox
162%    \endgroup}
163%
164% \begingroup \hsize1cm
165%   \WhateverA{thisisaboringandverylongcommand}\par
166%   \WhateverB{thisisaboringandverylongcommand}\par
167% \endgroup
168