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