| 1 |
% url.sty ver 1.4 02-Mar-1999 Donald Arseneau asnd@triumf.ca |
| 2 |
% Copyright 1996-1999 Donald Arseneau, Vancouver, Canada. |
| 3 |
% This program can be used, distributed, and modified under the terms |
| 4 |
% of the LaTeX Project Public License. |
| 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 |
% \xyz for "\xyz" a defined-url; this can be used anywhere, no matter |
| 21 |
% what characters it contains. |
| 22 |
% |
| 23 |
% See further instructions after "\endinput" |
| 24 |
% |
| 25 |
\def\Url@ttdo{% style assignments for tt fonts or T1 encoding |
| 26 |
\def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\%\do\;\do\>\do\]% |
| 27 |
\do\)\do\,\do\?\do\'\do\+\do\=}% |
| 28 |
\def\UrlBigBreaks{\do\:\do@url@hyp}% |
| 29 |
\def\UrlNoBreaks{\do\(\do\[\do\{\do\<}% (unnecessary) |
| 30 |
\def\UrlSpecials{\do\ {\ }}% |
| 31 |
\def\UrlOrds{\do\*\do\-\do\~}% any ordinary characters that aren't usually |
| 32 |
} |
| 33 |
\def\Url@do{% style assignments for OT1 fonts except tt |
| 34 |
\def\UrlBreaks{\do\.\do\@\do\/\do\!\do\%\do\;\do\]\do\)\do\,\do\?\do\+\do\=}% |
| 35 |
\def\UrlBigBreaks{\do\:\do@url@hyp}% |
| 36 |
\def\UrlNoBreaks{\do\(\do\[\do\{}% prevents breaks after *next* character |
| 37 |
\def\UrlSpecials{\do\<{\langle}\do\>{\mathbin{\rangle}}\do\_{\_% |
| 38 |
\penalty\@m}\do\|{\mid}\do\{{\lbrace}\do\}{\mathbin{\rbrace}}\do |
| 39 |
\\{\mathbin{\backslash}}\do\~{\raise.6ex\hbox{\m@th$\scriptstyle\sim$}}\do |
| 40 |
\ {\ }}% |
| 41 |
\def\UrlOrds{\do\'\do\"\do\-}% |
| 42 |
} |
| 43 |
\def\url@ttstyle{% |
| 44 |
\@ifundefined{selectfont}{\def\UrlFont{\tt}}{\def\UrlFont{\ttfamily}}\Url@ttdo |
| 45 |
} |
| 46 |
\def\url@rmstyle{% |
| 47 |
\@ifundefined{selectfont}{\def\UrlFont{\rm}}{\def\UrlFont{\rmfamily}}\Url@do |
| 48 |
} |
| 49 |
\def\url@sfstyle{% |
| 50 |
\@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\sffamily}}\Url@do |
| 51 |
} |
| 52 |
\def\url@samestyle{\ifdim\fontdimen\thr@@\font=\z@ \url@ttstyle \else |
| 53 |
\url@rmstyle \fi \def\UrlFont{}} |
| 54 |
|
| 55 |
\@ifundefined{strip@prefix}{\def\strip@prefix#1>{}}{} |
| 56 |
\@ifundefined{verbatim@nolig@list}{\def\verbatim@nolig@list{\do\`}}{} |
| 57 |
|
| 58 |
\def\Url{% |
| 59 |
\begingroup \let\url@moving\relax\relax \endgroup |
| 60 |
\ifmmode\@nomatherr$\fi |
| 61 |
\UrlFont $\fam\z@ \textfont\z@\font |
| 62 |
\let\do\@makeother \dospecials % verbatim catcodes |
| 63 |
\catcode`{\@ne \catcode`}\tw@ \catcode`\ 10 % except braces and spaces |
| 64 |
\medmuskip0mu \thickmuskip\medmuskip \thinmuskip\medmuskip |
| 65 |
\@tempcnta\fam\multiply\@tempcnta\@cclvi |
| 66 |
\let\do\set@mathcode \UrlOrds % ordinary characters that were special |
| 67 |
\advance\@tempcnta 8192 \UrlBreaks % bin |
| 68 |
\advance\@tempcnta 4096 \UrlBigBreaks % rel |
| 69 |
\advance\@tempcnta 4096 \UrlNoBreaks % open |
| 70 |
\let\do\set@mathact \UrlSpecials % active |
| 71 |
\let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures |
| 72 |
\@ifnextchar\bgroup\Url@z\Url@y} |
| 73 |
|
| 74 |
\def\Url@y#1{\catcode`{11 \catcode`}11 |
| 75 |
\def\@tempa##1#1{\Url@z{##1}}\@tempa} |
| 76 |
\def\Url@z#1{\def\@tempa{#1}\expandafter\expandafter\expandafter\Url@Hook |
| 77 |
\expandafter\strip@prefix\meaning\@tempa\UrlRight\m@th$\endgroup} |
| 78 |
\def\Url@Hook{\UrlLeft} |
| 79 |
\let\UrlRight\@empty |
| 80 |
\let\UrlLeft\@empty |
| 81 |
|
| 82 |
\def\set@mathcode#1{\count@`#1\advance\count@\@tempcnta\mathcode`#1\count@} |
| 83 |
\def\set@mathact#1#2{\mathcode`#132768 \lccode`\~`#1\lowercase{\def~{#2}}} |
| 84 |
\def\set@mathnolig#1{\ifnum\mathcode`#1<32768 |
| 85 |
\lccode`\~`#1\lowercase{\edef~{\mathchar\number\mathcode`#1_{\/}}}% |
| 86 |
\mathcode`#132768 \fi} |
| 87 |
|
| 88 |
\def\urldef#1#2{\begingroup \setbox\z@\hbox\bgroup |
| 89 |
\def\Url@z{\Url@def{#1}{#2}}#2} |
| 90 |
\expandafter\ifx\csname DeclareRobustCommand\endcsname\relax |
| 91 |
\def\Url@def#1#2#3{\m@th$\endgroup\egroup\endgroup |
| 92 |
\def#1{#2{#3}}} |
| 93 |
\else |
| 94 |
\def\Url@def#1#2#3{\m@th$\endgroup\egroup\endgroup |
| 95 |
\DeclareRobustCommand{#1}{#2{#3}}} |
| 96 |
\fi |
| 97 |
|
| 98 |
\def\urlstyle#1{\csname url@#1style\endcsname} |
| 99 |
|
| 100 |
% Sample (and default) configuration: |
| 101 |
% |
| 102 |
\newcommand\url{\begingroup \Url} |
| 103 |
% |
| 104 |
% picTeX defines \path, so declare it optionally: |
| 105 |
\@ifundefined{path}{\newcommand\path{\begingroup \urlstyle{tt}\Url}}{} |
| 106 |
% |
| 107 |
% too many styles define \email like \address, so I will not define it. |
| 108 |
% \newcommand\email{\begingroup \urlstyle{rm}\Url} |
| 109 |
|
| 110 |
% Process LaTeX \package options |
| 111 |
% |
| 112 |
\urlstyle{tt} |
| 113 |
\let\Url@sppen\@M |
| 114 |
\def\do@url@hyp{}% by default, no breaks after hyphens |
| 115 |
|
| 116 |
\@ifundefined{ProvidesPackage}{}{ |
| 117 |
\ProvidesPackage{url}[1999/03/02 \space ver 1.4 \space |
| 118 |
Verb mode for urls, email addresses, and file names] |
| 119 |
\DeclareOption{hyphens}{\def\do@url@hyp{\do\-}}% allow breaks after hyphens |
| 120 |
\DeclareOption{obeyspaces}{\let\Url@Hook\relax}% a flag for later |
| 121 |
\DeclareOption{spaces}{\let\Url@sppen\relpenalty} |
| 122 |
\DeclareOption{T1}{\let\Url@do\Url@ttdo} |
| 123 |
\ProcessOptions |
| 124 |
\ifx\Url@Hook\relax % [obeyspaces] was declared |
| 125 |
\def\Url@Hook#1\UrlRight\m@th{\edef\@tempa{\noexpand\UrlLeft |
| 126 |
\Url@retain#1\Url@nosp\, }\@tempa\UrlRight\m@th} |
| 127 |
\def\Url@retain#1 {#1\penalty\Url@sppen\ \Url@retain} |
| 128 |
\def\Url@nosp\,#1\Url@retain{} |
| 129 |
\fi |
| 130 |
} |
| 131 |
|
| 132 |
\edef\url@moving{\csname Url Error\endcsname} |
| 133 |
\expandafter\edef\url@moving |
| 134 |
{\csname url used in a moving argument.\endcsname} |
| 135 |
\expandafter\expandafter\expandafter \let \url@moving\undefined |
| 136 |
|
| 137 |
\endinput |
| 138 |
% |
| 139 |
% url.sty ver 1.4 02-Mar-1999 Donald Arseneau asnd@reg.triumf.ca |
| 140 |
% |
| 141 |
% This package defines "\url", a form of "\verb" that allows linebreaks, |
| 142 |
% and can often be used in the argument to another command. It can be |
| 143 |
% configured to print in different formats, and is particularly useful for |
| 144 |
% hypertext links, email addresses, directories/paths, etc. The font may |
| 145 |
% be selected using the "\urlstyle" command and pre-defined text can be |
| 146 |
% stored with the "\urldef" command. New url-like commands can be defined, |
| 147 |
% and a "\path" command is provided this way. |
| 148 |
% |
| 149 |
% Usage: Conditions: |
| 150 |
% \url{ } If the argument contains any "%", "#", or "^^", or ends with |
| 151 |
% "\", it can't be used in the argument to another command. |
| 152 |
% The argument must not contain unbalanced braces. |
| 153 |
% \url| | ...where "|" is any character not used in the argument and not |
| 154 |
% "{" or a space. The same restrictions as above except that the |
| 155 |
% argument may contain unbalanced braces. |
| 156 |
% \xyz for "\xyz" a defined-url; this can be used anywhere, no matter |
| 157 |
% what characters it contains. |
| 158 |
% |
| 159 |
% The "\url" command is fragile, and its argument is likely to be very |
| 160 |
% fragile, but a defined-url is robust. |
| 161 |
% |
| 162 |
% Package Option: obeyspaces |
| 163 |
% Ordinarily, all spaces are ignored in the url-text. The "[obeyspaces]" |
| 164 |
% option allows spaces, but may introduce spurious spaces when a url |
| 165 |
% containing "\" characters is given in the argument to another command. |
| 166 |
% So if you need to obey spaces you can say "\usepackage[obeyspaces]{url}", |
| 167 |
% and if you need both spaces and backslashes, use a `defined-url' for |
| 168 |
% anything with "\". |
| 169 |
% |
| 170 |
% Package Option: hyphens |
| 171 |
% Ordinarily, breaks are not allowed after "-" characters because this |
| 172 |
% leads to confusion. (Is the "-" part of the address or just a hyphen?) |
| 173 |
% The package option "[hyphens]" allows breaks after explicit hyphen |
| 174 |
% characters. The "\url" command will *never ever* hyphenate words. |
| 175 |
% |
| 176 |
% Package Option: spaces |
| 177 |
% Likewise, breaks are not usually allowed after spaces under the |
| 178 |
% "[obeyspaces]" option, but giving the options "[obeyspaces,spaces]" |
| 179 |
% will allow breaks at those spaces. |
| 180 |
% |
| 181 |
% Package Option: T1 |
| 182 |
% This signifies that you will be using T1-encoded fonts which contain |
| 183 |
% some characters missing from most older (OT1) encoded TeX fonts. This |
| 184 |
% changes the default definition for "\urlstyle{rm}". |
| 185 |
% |
| 186 |
% Defining a defined-url: |
| 187 |
% Take for example the email address "myself%node@gateway.net" which could |
| 188 |
% not be given (using "\url" or "\verb") in a caption or parbox due to the |
| 189 |
% percent sign. This address can be predefined with |
| 190 |
% \urldef{\myself}\url{myself%node@gateway.net} or |
| 191 |
% \urldef{\myself}\url|myself%node@gateway.net| |
| 192 |
% and then you may use "\myself" instead of "\url{myself%node@gateway.net}" |
| 193 |
% in an argument, and even in a moving argument like a caption because a |
| 194 |
% defined-url is robust. |
| 195 |
% |
| 196 |
% Style: |
| 197 |
% You can switch the style of printing using "\urlstyle{tt}", where "tt" |
| 198 |
% can be any defined style. The pre-defined styles are "tt", "rm", "sf", |
| 199 |
% and "same" which all allow the same linebreaks but different fonts -- |
| 200 |
% the first three select a specific font and the "same" style uses the |
| 201 |
% current text font. You can define your own styles with different fonts |
| 202 |
% and/or line-breaking by following the explanations below. The "\url" |
| 203 |
% command follows whatever the currently-set style dictates. |
| 204 |
% |
| 205 |
% Alternate commands: |
| 206 |
% It may be desireable to have different things treated differently, each |
| 207 |
% in a predefined style; e.g., if you want directory paths to always be |
| 208 |
% in tt and email addresses to be rm, then you would define new url-like |
| 209 |
% commands as follows: |
| 210 |
% |
| 211 |
% \newcommand\email{\begingroup \urlstyle{rm}\Url} |
| 212 |
% \newcommand\directory{\begingroup \urlstyle{tt}\Url} |
| 213 |
% |
| 214 |
% You must follow this format closely, and NOTE that the final command is |
| 215 |
% "\Url", not "\url". In fact, the "\directory" example is exactly the |
| 216 |
% "\path" definition which is pre-defined in the package. If you look |
| 217 |
% above, you will see that "\url" is defined with |
| 218 |
% \newcommand\url{\begingroup \Url} |
| 219 |
% I.e., using whatever url-style has been selected. |
| 220 |
% |
| 221 |
% You can make a defined-url for these other styles, using the usual |
| 222 |
% "\urldef" command as in this example: |
| 223 |
% |
| 224 |
% \urldef{\myself}{\email}{myself%node.domain@gateway.net} |
| 225 |
% |
| 226 |
% which makes "\myself" act like "\email{myself%node.domain@gateway.net}", |
| 227 |
% if the "\email" command is defined as above. The "\myself" command |
| 228 |
% would then be robust. |
| 229 |
% |
| 230 |
% Defining styles: |
| 231 |
% Before describing how to customize the printing style, it is best to |
| 232 |
% mention something about the unusual implementation of "\url". Although |
| 233 |
% the material is textual in nature, and the font specification required |
| 234 |
% is a text-font command, the text is actually typeset in *math* mode. |
| 235 |
% This allows the context-sensitive linebreaking, but also accounts for |
| 236 |
% the default behavior of ignoring spaces. Now on to defining styles. |
| 237 |
% |
| 238 |
% To change the font or the list of characters that allow linebreaks, you |
| 239 |
% could redefine the commands "\UrlFont", "\UrlBreaks", "\UrlSpecials" etc. |
| 240 |
% directly in the document, but it is better to define a new `url-style' |
| 241 |
% (following the example of "\url@ttstyle" and "\url@rmstyle") which defines |
| 242 |
% all of "\UrlBigbreaks", "\UrlNoBreaks", "\UrlBreaks", "\UrlSpecials", and |
| 243 |
% "\UrlFont". |
| 244 |
% |
| 245 |
% Changing font: |
| 246 |
% The "\UrlFont" command selects the font. The definition of "\UrlFont" |
| 247 |
% done by the pre-defined styles varies to cope with a variety of LaTeX |
| 248 |
% font selection schemes, but it could be as simple as "\def\UrlFont{\tt}". |
| 249 |
% Depending on the font selected, some characters may need to be defined |
| 250 |
% in the "\UrlSpecials" list because many fonts don't contain all the |
| 251 |
% standard input characters. |
| 252 |
% |
| 253 |
% Changing linebreaks: |
| 254 |
% The list of characters that allow line-breaks is given by "\UrlBreaks" |
| 255 |
% and "\UrlBigBreaks", which have the format "\do\c" for character "c". |
| 256 |
% The differences are that `BigBreaks' have a lower penalty and have |
| 257 |
% different breakpoints when in sequence (as in "http://"): `BigBreaks' |
| 258 |
% are treated as mathrels while `Breaks' are mathbins (see The TeXbook, |
| 259 |
% p.170). In particular, a series of `BigBreak' characters will break at |
| 260 |
% the end and only at the end; a series of `Break' characters will break |
| 261 |
% after the first and after every following *pair*; there will be no |
| 262 |
% break after a `Break' character if a `BigBreak' follows. In the case |
| 263 |
% of "http://" it doesn't matter whether ":" is a `Break' or `BigBreak' -- |
| 264 |
% the breaks are the same in either case; but for DECnet nodes with "::" |
| 265 |
% it is important to prevent breaks *between* the colons, and that is why |
| 266 |
% colons are `BigBreaks'. |
| 267 |
% |
| 268 |
% It is possible for characters to prevent breaks after the next following |
| 269 |
% character (I use this for parentheses). Specify these in "\UrlNoBreaks". |
| 270 |
% |
| 271 |
% You can do arbitrarily complex things with characters by making them |
| 272 |
% active in math mode (mathcode hex-8000) and specifying the definition(s) |
| 273 |
% in "\UrlSpecials". This is used in the rm and sf styles for OT1 font |
| 274 |
% encoding to handle several characters that are not present in those |
| 275 |
% computer-modern style fonts. See the definition of "\Url@do", which |
| 276 |
% is used by both "\url@rmstyle" and "\url@sfstyle"; it handles missing |
| 277 |
% characters via "\UrlSpecials". The nominal format for setting each |
| 278 |
% special character "c" is: "\do\c{<definition>}", but you can include |
| 279 |
% other definitions too. |
| 280 |
% |
| 281 |
% |
| 282 |
% If all this sounds confusing ... well, it is! But I hope you won't need |
| 283 |
% to redefine breakpoints -- the default assignments seem to work well for |
| 284 |
% a wide variety of applications. If you do need to make changes, you can |
| 285 |
% test for breakpoints using regular math mode and the characters "+=(a". |
| 286 |
% |
| 287 |
% Yet more flexibility: |
| 288 |
% You can also customize the verbatim text by defining "\UrlRight" and/or |
| 289 |
% "\UrlLeft", e.g., for ISO formatting of urls surrounded by "< >", define |
| 290 |
% |
| 291 |
% \renewcommand\url{\begingroup \def\UrlLeft{<url: }\def\UrlRight{>}% |
| 292 |
% \urlstyle{tt}\Url} |
| 293 |
% |
| 294 |
% The meanings of "\UrlLeft" and "\UrlRight" are *not* reproduced verbatim. |
| 295 |
% This lets you use formatting commands there, but you must be careful not |
| 296 |
% to use TeX's special characters ("\^_%~#$&{}" etc.) improperly. |
| 297 |
% You can also define "\UrlLeft" to reprocess the verbatim text, but the |
| 298 |
% format of the definition is special: |
| 299 |
% |
| 300 |
% \def\UrlLeft#1\UrlRight{ ... do things with #1 ... } |
| 301 |
% |
| 302 |
% Yes, that is "#1" followed by "\UrlRight" then the definition. For |
| 303 |
% example, to put a hyperTeX hypertext link in the DVI file: |
| 304 |
% |
| 305 |
% \def\UrlLeft#1\UrlRight{\special{html:<a href="#1">}#1\special{html:</a>}} |
| 306 |
% |
| 307 |
% Using this technique, url.sty can provide a convenient interface for |
| 308 |
% performing various operations on verbatim text. You don't even need |
| 309 |
% to print out the argument! For greatest efficiency in such obscure |
| 310 |
% applications, you can define a null url-style where all the lists like |
| 311 |
% "\UrlBreaks" are empty. |
| 312 |
% |
| 313 |
% Revision History: |
| 314 |
% ver 1.1 6-Feb-1996: |
| 315 |
% Fix hyphens that wouldn't break and ligatures that weren't suppressed. |
| 316 |
% ver 1.2 19-Oct-1996: |
| 317 |
% Package option for T1 encoding; Hooks: "\UrlLeft" and "\UrlRight". |
| 318 |
% ver 1.3 21-Jul-1997: |
| 319 |
% Prohibit spaces as delimiter characters; change ascii tilde in OT1. |
| 320 |
% ver 1.4 02-Mar-1999 |
| 321 |
% LaTeX license; moving-argument-error |
| 322 |
% The End |
| 323 |
|
| 324 |
Test file integrity: ASCII 32-57, 58-126: !"#$%&'()*+,-./0123456789 |
| 325 |
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ |