summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lang-url.mkiv
blob: 8990dccd86fce35c97bfeb30b8f5f592fe0ca51e (plain)
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
%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 ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\registerctxluafile{lang-url}{1.001}

\unprotect

%D Traditionally this code is in the language namespace as
%D hyphenation relates to languages.

%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

\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

\let\hyphenatedurlseparator    \empty % \periodcentered
\let\hyphenatedurldiscretionary\empty

\setnewconstant\hyphenatedurllefthyphenmin \plusthree
\setnewconstant\hyphenatedurlrighthyphenmin\plusthree

\def\lang_url_more{\penalty\plustenthousand\hskip\scratchskipone\penalty\plustenthousand}
\def\lang_url_less{\penalty\plustenthousand\hskip\scratchskiptwo\penalty\plustenthousand}
\def\lang_url_trac{\penalty\plustenthousand\hsmash{\darkred\vl}\penalty\plustenthousand}

\def\lang_url_a#1{\lang_url_more\char#1\lang_url_show\discretionary{}{\hyphenatedurlseparator}{}}
\def\lang_url_b#1{\lang_url_more\discretionary{\hyphenatedurlseparator}{}{}\lang_url_show\char#1\relax}
\def\lang_url_d#1{\lang_url_more\discretionary{\lang_url_show}{\lang_url_show}{\lang_url_show}}
\def\lang_url_l#1{\lang_url_less\char#1\relax}
\def\lang_url_c#1{\lang_url_more\char#1\relax}
\def\lang_url_L#1{\lang_url_less\char#1\relax}
\def\lang_url_C#1{\lang_url_more\char#1\relax}

\unexpanded\def\showhyphenatedurlbreaks % for old times sake
  {\let\lang_url_show\lang_url_trac}

\installtextracker
  {languages.url}
  {\let\lang_url_show\lang_url_trac}
  {\let\lang_url_show\relax}

\let\lang_url_show\relax

\unexpanded\def\sethyphenatedurlnormal#1{\ctxcommand{hyphenatedurl.setcharacters(\!!bs#1\!!es,0)}} % Lua names will change
\unexpanded\def\sethyphenatedurlbefore#1{\ctxcommand{hyphenatedurl.setcharacters(\!!bs#1\!!es,1)}} % Lua names will change
\unexpanded\def\sethyphenatedurlafter #1{\ctxcommand{hyphenatedurl.setcharacters(\!!bs#1\!!es,2)}} % Lua names will change

% \sethyphenatedurlafter{ABCDEF}

\unexpanded\def\hyphenatedurl#1%
  {\dontleavehmode
   \begingroup
   \the\everyhyphenatedurl
   \normallanguage\zerocount
   \let\a\lang_url_a % after
   \let\b\lang_url_b % before
   \let\d\lang_url_d % disc
   \let\l\lang_url_l % letter
   \let\c\lang_url_c % character
   \let\L\lang_url_L % letter_nobreak
   \let\C\lang_url_C % character_nobreak
   \scratchskipone\zeropoint\s!plus\dimexpr\emwidth/12\s!minus\dimexpr\emwidth/24\relax % 1.00pt @ 12pt
   \scratchskiptwo\zeropoint\s!plus\dimexpr\emwidth/48\s!minus\dimexpr\emwidth/96\relax % 0.25pt @ 12pt
   \normalexpanded{\noexpand\ctxcommand{hyphenatedurl(
        \!!bs\noexpand\detokenize{#1}\!!es,
        \number\hyphenatedurllefthyphenmin,
        \number\hyphenatedurlrighthyphenmin,
        "\hyphenatedurldiscretionary"
    )}}%
   \endgroup}

%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