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