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