| 1 |
% url.sty ver 3.4 16-Sep-2013 Donald Arseneau [email protected] |
| 2 |
% Copyright 1996-2013 Donald Arseneau, Vancouver, Canada. |
| 3 |
% This program can be used, distributed, and modified under the terms |
| 4 |
% of the LaTeX Project Public License, version 2 or later. |
| 5 |
% |
| 6 |
% A form of \verb that allows linebreaks at certain characters or |
| 7 |
% combinations of characters, accepts reconfiguration, and can usually |
| 8 |
% be used in the argument to another command. It is intended for email |
| 9 |
% addresses, hypertext links, directories/paths, etc., which normally |
| 10 |
% have no spaces. The font may be selected using the \urlstyle command, |
| 11 |
% and new url-like commands can be defined using \urldef. |
| 12 |
% |
| 13 |
% Usage: Conditions: |
| 14 |
% \url{ } If the argument contains any "%" or "^^", or ends with |
| 15 |
% "\", it can't be used in the argument to another command. |
| 16 |
% The argument must not contain unbalanced braces. |
| 17 |
% \url| | ...where "|" is any character not used in the argument and not |
| 18 |
% "{" or a space. The same restrictions as above except that the |
| 19 |
% argument may contain unbalanced braces. |
| 20 |
% \urldef\xyz\url{ } |
| 21 |
% \xyz a defined-url: "\xyz" can be used anywhere, no matter what |
| 22 |
% characters it contains. |
| 23 |
% \DeclareUrlCommand\abc{settings}: makes \abc{ } like \url{ } with settings |
| 24 |
% |
| 25 |
% See url.tex/url.pdf for documentation. Some info after \endinput |
| 26 |
% |
| 27 |
% Required catcodes during loading: letters @ = letter, |
| 28 |
% ` = > < . [ ] + - digits = other, |
| 29 |
% { } \ ~ # % $ _ ^ = their normal |
| 30 |
|
| 31 |
% default style assignments |
| 32 |
\def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]% |
| 33 |
\do\)\do\,\do\?\do\&\do\'\do+\do\=\do\#}% |
| 34 |
\def\UrlBigBreaks{\do\:\do@url@hyp}% |
| 35 |
\def\UrlNoBreaks{\do\(\do\[\do\{\do\<}% |
| 36 |
% any ordinary characters that aren't usually: |
| 37 |
\def\UrlOrds{\do\*\do\-\do\~\do\'\do\"\do\-}% |
| 38 |
\def\UrlSpecials{\do\ {\Url@space}\do\%{\Url@percent}\do\^^M{\Url@space}% |
| 39 |
\Url@force@Tilde}% package option may force faked text-ascii-tilde |
| 40 |
|
| 41 |
\@namedef{Url@OT1encSpecials}{% |
| 42 |
% *Some* latin-1 or windows characters that ot1 has elsewhere: OE oe ss |
| 43 |
\do\^^8c{\mathchar30 }\do\^^9c{\mathchar27 }\do\^^df{\mathchar25 }% |
| 44 |
\do\~{\lower.45ex\hbox{\m@th$\mathchar126$}}% For tt style |
| 45 |
% lots more to add, but I should later link into inputenc |
| 46 |
\do\^^b5{\mu}% |
| 47 |
\Url@OTnonTT % more for any but typewriter |
| 48 |
} |
| 49 |
|
| 50 |
\def\Url@OTnonTT{\do\<{\langle}\do\>{\mathbin{\rangle}}\do |
| 51 |
\_{\_\penalty\@m}\do\|{\mid}\do\{{\lbrace}\do\}{\mathbin{\rbrace}}\do |
| 52 |
\\{\mathbin{\backslash}}\UrlTildeSpecial} |
| 53 |
|
| 54 |
% *Some* latin-1 or windows characters. Most will pass through safely to T1 enc |
| 55 |
% mu inverted-? OE oe |
| 56 |
% lots more to add, but I should later link into inputenc |
| 57 |
\@namedef{Url@T1encSpecials}{\do\^^b5{\mu}\do\^^bf{\mathchar190 }% |
| 58 |
\do\^^8c{\mathchar215 }\do\^^9c{\mathchar247 }\do\^^df{\mathchar255 }% |
| 59 |
\do\^^ff{\mathchar184 }} |
| 60 |
|
| 61 |
\@namedef{Url@LY1encSpecials}{\do\~{\mathchar158 }} |
| 62 |
|
| 63 |
\def\UrlTildeSpecial{\do\~{\raise.45ex\hbox{\m@th$\scriptstyle\sim$}}} |
| 64 |
\let\Url@force@Tilde\relax |
| 65 |
|
| 66 |
\def\url@ttstyle{% |
| 67 |
\@ifundefined{selectfont}{\def\UrlFont{\tt}}{\def\UrlFont{\ttfamily}}} |
| 68 |
|
| 69 |
\def\url@rmstyle{% |
| 70 |
\@ifundefined{selectfont}{\def\UrlFont{\rm}}{\def\UrlFont{\rmfamily}}} |
| 71 |
|
| 72 |
\def\url@sfstyle{% |
| 73 |
\@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\sffamily}}} |
| 74 |
|
| 75 |
\def\url@samestyle{\def\UrlFont{}} |
| 76 |
|
| 77 |
\@ifundefined{strip@prefix}{\def\strip@prefix#1>{}}{} |
| 78 |
\@ifundefined{verbatim@nolig@list}{\def\verbatim@nolig@list{\do\`}}{} |
| 79 |
|
| 80 |
% \Url sets up the reading the argument verbatim if possible |
| 81 |
\def\Url{% |
| 82 |
\Url@movingtest |
| 83 |
\ifmmode\@inmatherr$\fi %$ |
| 84 |
\let\do\@makeother \dospecials % verbatim catcodes |
| 85 |
\catcode`{\@ne \catcode`}\tw@ % with exceptions |
| 86 |
\catcode`\ =10 % allow "\url {x}" |
| 87 |
\catcode`\#=6 % always # -> ##, so I can later convert ## -> # |
| 88 |
\@ifnextchar\bgroup{\obeyspaces\obeylines\Url@z}\Url@y} |
| 89 |
|
| 90 |
% \Url@y read arguments delimited like |...|, passing to \Url@z |
| 91 |
\def\Url@y#1{\catcode`{11 \catcode`}11\obeyspaces\obeylines |
| 92 |
\def\@tempa##1#1{\Url@z{##1}}\@tempa} |
| 93 |
|
| 94 |
% \Url@z read arguments delimited like {...}, verbatimizes with \meaning, |
| 95 |
% performs character translations, then invokes the formatter. |
| 96 |
\def\Url@z#1{\toks@{#1}\edef\Url@String{\the\toks@}% |
| 97 |
\edef\Url@String{\expandafter\strip@prefix\meaning\Url@String}% |
| 98 |
%\if\urldebug \message{------------------------------------------------------}% |
| 99 |
%\message{ \Url@String}\fi |
| 100 |
% \meaning introduces spurious spaces in the text, so it would be nice |
| 101 |
% to preserve the real spaces before \meaning, but that doesn't work -- |
| 102 |
% we can only do replacement on streams of non-syntactic characters. |
| 103 |
\Url@ObeySp % may be no-op; otherwise put ordinary (12) space characters |
| 104 |
%\if\urldebug \message{ \Url@String}\fi |
| 105 |
% we left the catcode of # with its normal value (6) so \meaning |
| 106 |
% doubles it to ##. Now we convert back to single #. This allows |
| 107 |
% \url{#} to appear in the arguments of other commands, where we can't |
| 108 |
% make # be an ordinary character. We make the single # active rather |
| 109 |
% than `other' to support hyperref.sty. |
| 110 |
\Url@acthash |
| 111 |
%\if\urldebug \message{ \Url@String}\fi |
| 112 |
% Also make % active to support hyperref. |
| 113 |
\Url@actpercent |
| 114 |
% now do any hyper referencing due to hyperref (or perform a url-def) |
| 115 |
\Url@HyperHook |
| 116 |
% Now do the formatting in a group (can also have \Url@HyperHook take |
| 117 |
% this as an argument. |
| 118 |
{\Url@FormatString}% |
| 119 |
\endgroup} |
| 120 |
|
| 121 |
\let\Url@ObeySp\@empty |
| 122 |
\let\UrlRight\@empty |
| 123 |
\let\UrlLeft\@empty |
| 124 |
\let\Url@HyperHook\@empty |
| 125 |
|
| 126 |
% This is the normal way to format the strings, using math mode. |
| 127 |
\def\Url@FormatString{% |
| 128 |
\UrlFont \Url@MathSetup |
| 129 |
$\fam\z@ \textfont\z@\font |
| 130 |
\expandafter\UrlLeft\Url@String\UrlRight |
| 131 |
\m@th$% |
| 132 |
% \if\urldebug \showlists \fi |
| 133 |
}% |
| 134 |
|
| 135 |
\def\Url@MathSetup{% |
| 136 |
\medmuskip\Urlmuskip \thickmuskip\medmuskip \thinmuskip0mu% |
| 137 |
\relpenalty\UrlBigBreakPenalty \binoppenalty\UrlBreakPenalty |
| 138 |
\expandafter\let\expandafter\UrlEncSpecials\csname Url@\f@encoding encSpecials\endcsname |
| 139 |
% Insert test for unknown encodings here \ifx\UrlEncSpecials\relax |
| 140 |
\ifdim\fontdimen\thr@@\font=\z@ \let\Url@OTnonTT\relax \fi |
| 141 |
\@tempcnta\z@ % \fam\multiply\@tempcnta\@cclvi |
| 142 |
\let\do\set@mathcode \UrlOrds % ordinary characters that were special |
| 143 |
\advance\@tempcnta 8192 \UrlBreaks % bin |
| 144 |
\advance\@tempcnta 4096 \UrlBigBreaks % rel |
| 145 |
\advance\@tempcnta 4096 \UrlNoBreaks % open |
| 146 |
\let\do\set@mathact \UrlSpecials \UrlEncSpecials % active |
| 147 |
\let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures |
| 148 |
} |
| 149 |
|
| 150 |
\def\set@mathcode#1{\count@`#1\advance\count@\@tempcnta |
| 151 |
%\message{Set mathcode of \string #1 (\number`#1) = \number`#1 + \number\@tempcnta. }% |
| 152 |
\mathcode`#1\count@} |
| 153 |
\def\set@mathact#1#2{\mathcode`#1=32768 \begingroup |
| 154 |
\lccode`\~`#1\lowercase{\endgroup\def~}{#2}} |
| 155 |
\def\set@mathnolig#1{\ifnum\mathcode`#1<32768 |
| 156 |
\begingroup\lccode`\~`#1\lowercase{\endgroup |
| 157 |
\edef~}{\mathchar\number\mathcode`#1\sb{\/}}% |
| 158 |
\mathcode`#1=32768 \fi} |
| 159 |
|
| 160 |
\def\Url@movingtest{\begingroup |
| 161 |
\ifx\let\HyPsd@LetCommand % we are already in a pdf string! |
| 162 |
\expandafter\Url@unmove \fi % give the argument and hope for the best |
| 163 |
\let\Url@moving\relax\relax\relax |
| 164 |
\ifx\Url@moving\relax\else \expandafter\Url@unmove \fi |
| 165 |
\endgroup} |
| 166 |
\long\def\Url@unmove#1\Url@y{\endgroup \ifx\protect\relax\else\protect\Url\fi} |
| 167 |
\edef\Url@moving{\csname Url Error\endcsname} |
| 168 |
\expandafter\edef\Url@moving |
| 169 |
{\csname url used in a moving argument.\endcsname} |
| 170 |
\expandafter\expandafter\expandafter \let \Url@moving\@undefined |
| 171 |
|
| 172 |
\def\urldef#1#2{\begingroup \setbox\z@\hbox\bgroup |
| 173 |
\def\Url@HyperHook##1\endgroup{\Url@def{#1}{#2}}% |
| 174 |
% Because hyperref breaks \urldef and does not define its own (Grrrr!)... |
| 175 |
\def\url@##1{\egroup\endgroup\DeclareRobustCommand#1{#2{##1}}}% |
| 176 |
#2} |
| 177 |
\def\Url@def#1#2{% |
| 178 |
\toks0\expandafter{\Url@String}% |
| 179 |
\protected@edef\Url@String{\Url@String}% |
| 180 |
\toks1\expandafter{\Url@String}% |
| 181 |
\edef\Url@String{\endgroup\egroup\endgroup\def |
| 182 |
\expandafter\noexpand\csname\expandafter\@gobble\string#1 \endcsname |
| 183 |
{\noexpand\Url@eitherdef{\the\toks1}{\noexpand#2{\the\toks0}}}}% |
| 184 |
\Url@String |
| 185 |
\edef#1{\noexpand\protect |
| 186 |
\expandafter\noexpand\csname\expandafter\@gobble\string#1 \endcsname}% |
| 187 |
} |
| 188 |
\def\Url@eitherdef{\ifx\let\HyPsd@LetCommand % we are already in a pdf string! |
| 189 |
\expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi} |
| 190 |
|
| 191 |
\def\urlstyle#1{\expandafter\protect\csname url@#1style\endcsname} |
| 192 |
|
| 193 |
\def\DeclareUrlCommand#1#2{\def#1{\leavevmode\begingroup #2\Url}} |
| 194 |
|
| 195 |
% Sample (and default) configuration: |
| 196 |
% |
| 197 |
\DeclareUrlCommand\url{} |
| 198 |
\urlstyle{tt} |
| 199 |
% |
| 200 |
\newmuskip\Urlmuskip \Urlmuskip=0mu |
| 201 |
\mathchardef\UrlBreakPenalty=\binoppenalty |
| 202 |
\mathchardef\UrlBigBreakPenalty=\relpenalty |
| 203 |
% |
| 204 |
% picTeX defines \path, so declare it optionally: |
| 205 |
\@ifundefined{path}{\DeclareUrlCommand\path{\urlstyle{tt}}}{} |
| 206 |
% |
| 207 |
% too many styles define \email like \address, so I will not define it. |
| 208 |
% \DeclareUrlCommand\email{\urlstyle{rm}} |
| 209 |
|
| 210 |
% Process LaTeX \package options |
| 211 |
% |
| 212 |
\let\Url@sppen\@M |
| 213 |
\def\Url@space{\penalty\Url@sppen} |
| 214 |
\def\do@url@hyp{}% by default, no breaks after hyphens |
| 215 |
|
| 216 |
\@ifundefined{ProvidesPackage}{ |
| 217 |
}{\ProvidesPackage |
| 218 |
{url}[2013/09/16 \space ver 3.4 \space Verb mode for urls, etc.] |
| 219 |
\DeclareOption{hyphens}{\def\do@url@hyp{\do\-}}% allow breaks after hyphens |
| 220 |
\DeclareOption{obeyspaces}{\let\Url@ObeySp\relax}% a flag for later |
| 221 |
\DeclareOption{spaces}{\def\Url@sppen{\UrlBreakPenalty}} |
| 222 |
\DeclareOption{LY1}{} |
| 223 |
\DeclareOption{T1}{} |
| 224 |
\DeclareOption{allowmove}{\let\Url@moving\@empty} |
| 225 |
\DeclareOption{lowtilde}{% |
| 226 |
\def\UrlTildeSpecial{\do\~{\raise.2ex\hbox{\m@th$\scriptstyle\sim$}}} |
| 227 |
\let\Url@force@Tilde\UrlTildeSpecial |
| 228 |
} |
| 229 |
\ProcessOptions\relax |
| 230 |
\ifx\Url@ObeySp\relax % [obeyspaces] was declared |
| 231 |
\begingroup \lccode`+=32 \lowercase |
| 232 |
{\endgroup \def\Url@ObeySp{\Url@Edit\Url@String{ }{+}}} |
| 233 |
\def\Url@space{\penalty\Url@sppen\ } |
| 234 |
\fi |
| 235 |
} |
| 236 |
\ifx\f@encoding\undefined \def\f@encoding{OT1}\fi |
| 237 |
|
| 238 |
\begingroup |
| 239 |
% \Url@acthash: convert `other' (doubled) ## to active # |
| 240 |
% \Url@actpercent: convert `other' % to active % |
| 241 |
\lccode`+=`\# \lccode`\~=`\# |
| 242 |
\lowercase {\long\gdef\Url@acthash{\Url@Edit\Url@String{++}{~}% |
| 243 |
\ifnum\mathcode`\#<32768 \def~{\#}\fi}}% |
| 244 |
\lccode`+=`\% \lccode`\~=`\% |
| 245 |
\lowercase {\long\gdef\Url@actpercent{\Url@Edit\Url@String{+}{~}% |
| 246 |
\ifnum\mathcode`\%<32768 \def~{\%}\fi}}% |
| 247 |
\catcode13=12 % |
| 248 |
\gdef\Url@percent{\@ifnextchar^^M{\@gobble}{\mathbin{\mathchar`\%}}}% |
| 249 |
\endgroup% |
| 250 |
|
| 251 |
% Edit macro #1 changing all appearances of pattern #2 to replacement #3. |
| 252 |
% The replacement is recursive, so don't put the search pattern into the |
| 253 |
% replacement text! |
| 254 |
|
| 255 |
{ \catcode`Q=3 |
| 256 |
|
| 257 |
\gdef\Url@Edit#1#2#3{% |
| 258 |
\begingroup % \tracingall |
| 259 |
\def\DOE@a{\endgroup\def#1}% Just so I can \expandafter it safely. |
| 260 |
\def\DOE@b##1#2##2Q##3{\@ifblank{##2}% if finished, |
| 261 |
{\DOE@c ##1Q}% then remove \@empty's and redefine macro |
| 262 |
{\DOE@b##1##3##2Q{##3}}% else, re-iterate |
| 263 |
}% the leading \@empty preserves braces, as does the trailing pattern: |
| 264 |
\expandafter\DOE@b\expandafter\@empty #1\@empty#2Q{#3}} |
| 265 |
\gdef\DOE@c#1\@empty Q{\expandafter\DOE@a\expandafter{#1}} |
| 266 |
% |
| 267 |
% \@ifblank (LaTeX syntax) --- checks if parameter is blank (Spaces |
| 268 |
% count as blank) use \@ifblank{#1}{true case}{false case} etc |
| 269 |
\long\gdef\@ifblank#1{\@Ifbl@nk#1QQ\@secondoftwo\@firstoftwo!}% |
| 270 |
\long\gdef\@Ifbl@nk#1#2Q#3#4#5!{#4} |
| 271 |
|
| 272 |
} % restore Q catcode |
| 273 |
|
| 274 |
|
| 275 |
%\ifx\urldebug\@undefined \def\urldebug{01}\fi |
| 276 |
|
| 277 |
\endinput |
| 278 |
% For documentation, please see accompanying url.tex (url.pdf) |
| 279 |
% Package Options: obeyspaces, hyphens, spaces, lowtilde |
| 280 |
% |
| 281 |
% Revision History: |
| 282 |
% ver 1.1 6-Feb-1996: |
| 283 |
% Fix hyphens that wouldn't break and ligatures that weren't suppressed. |
| 284 |
% ver 1.2 19-Oct-1996: |
| 285 |
% Package option for T1 encoding; Hooks: "\UrlLeft" and "\UrlRight". |
| 286 |
% ver 1.3 21-Jul-1997: |
| 287 |
% Prohibit spaces as delimiter characters; change ascii tilde in OT1. |
| 288 |
% ver 1.4 02-Mar-1999: |
| 289 |
% LaTeX license; moving-argument-error |
| 290 |
% ver 1.5 28-Mar-1999: |
| 291 |
% possibility of spacing around break characters; re-settable penalties |
| 292 |
% ver 1.6 20-Jun-2002: |
| 293 |
% un-double #, fix obeyed-spaces, ignore trailing %, hook for hyperref |
| 294 |
% (\Url@HyperHook), no macros in pre-processed url string (in \Url@String), |
| 295 |
% limit catcode change of ~. |
| 296 |
% ver 3.0 June 2003/Nov 2003: |
| 297 |
% \DeclareUrlCommand; make font encoding automatic (only a few inputenc characters |
| 298 |
% are supported yet - needs refactoring); reverse penalties. |
| 299 |
% ver 3.1 Mar 2004: |
| 300 |
% Remove spurious spaces in \url@XXstyle commands. |
| 301 |
% ver 3.2 June 2005: |
| 302 |
% Fix cmsy-symbols in tt bug (from 3.0); LY1 encoding bug; Enable plain |
| 303 |
% with miniltx (again); Define the \urldef for hyperref; Lower "sim" tilde |
| 304 |
% a little; fix \lowercase error in \UrlSpecials handling. |
| 305 |
% ver 3.3 April 2006: |
| 306 |
% Fix some encoding bugs and remove 8-bit characters. lowtilde option |
| 307 |
% ver 3.4 Sept 2013: |
| 308 |
% \@nomatherr->\@inmatherr. & is now another \UrlBreak character. |
| 309 |
% The End |
| 310 |
|
| 311 |
Test file integrity: ASCII 32-57, 58-126: !"#$%&'()*+,-./0123456789 |
| 312 |
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ |
| 313 |
|