summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lang-url.mkxl
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/lang-url.mkxl')
-rw-r--r--tex/context/base/mkiv/lang-url.mkxl167
1 files changed, 167 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/lang-url.mkxl b/tex/context/base/mkiv/lang-url.mkxl
new file mode 100644
index 000000000..bb51f838a
--- /dev/null
+++ b/tex/context/base/mkiv/lang-url.mkxl
@@ -0,0 +1,167 @@
+%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}{}
+
+\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
+ \resetfontfeature
+ \resetcharacterspacing
+ %
+ \enforced\let\&\letterampersand
+ \enforced\let\#\letterhash
+ \enforced\let\~\lettertilde
+ \enforced\let\\\letterbackslash
+ \enforced\let\$\letterdollar
+ \enforced\let\^\letterhat
+ \enforced\let\_\letterunderscore
+ \enforced\let\{\letterleftbrace
+ \enforced\let\}\letterrightbrace
+ \enforced\let\|\letterbar
+ \enforced\let~=\lettertilde
+ \enforced\let|=\letterbar
+ \enforced\let\Ux\eUx
+\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 {\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}
+
+\permanent\protected\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
+
+\permanent\protected\def\sethyphenatedurlnormal#1{\clf_sethyphenatedurlcharacters{#1}{\v!normal}}
+\permanent\protected\def\sethyphenatedurlbefore#1{\clf_sethyphenatedurlcharacters{#1}{\v!before}}
+\permanent\protected\def\sethyphenatedurlafter #1{\clf_sethyphenatedurlcharacters{#1}{\v!after }}
+
+% \sethyphenatedurlafter{ABCDEF}
+
+\permanent\protected\def\hyphenatedurl#1%
+ {\dontleavehmode
+ \begingroup
+ \the\everyhyphenatedurl
+ \normallanguage\zerocount % \nohyphens in mkiv
+ \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
+ \unprotect
+ \normalexpanded{\noexpand\clf_hyphenatedurl
+ {\noexpand\detokenize{#1}}%
+ \hyphenatedurllefthyphenmin
+ \hyphenatedurlrighthyphenmin
+ {\hyphenatedurldiscretionary}%
+ }%
+ \protect
+ \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 \aliased\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
+
+% \setuppapersize[A7]
+%
+% \protected\def\WhateverA#1%
+% {\dontleavehmode
+% \begingroup
+% \prehyphenchar"B7\relax
+% \setbox\scratchbox\hbox{\tttf#1}%
+% \prehyphenchar`-\relax
+% \unhbox\scratchbox
+% \endgroup}
+%
+% \protected\def\WhateverB#1%
+% {\dontleavehmode
+% \begingroup
+% \tttf
+% \prehyphenchar\minusone
+% % \localrightbox{\llap{_}}%
+% \localrightbox{\llap{\smash{\lower1.5ex\hbox{\char"2192}}}}%
+% \setbox\scratchbox\hbox{#1}%
+% \prehyphenchar`-\relax
+% \unhbox\scratchbox
+% \endgroup}
+%
+% \begingroup \hsize1cm
+% \WhateverA{thisisaboringandverylongcommand}\par
+% \WhateverB{thisisaboringandverylongcommand}\par
+% \endgroup