
wenzelm@6619: % url.sty  ver 1.1    6-Feb-1996   Donald Arseneau   asnd@triumf.ca
wenzelm@6619: %
wenzelm@6619: % A form of \verb that allows linebreaks at certain characters or 
wenzelm@6619: % combinations of characters, accepts reconfiguration, and can usually
wenzelm@6619: % be used in the argument to another command.  It is intended for email
wenzelm@6619: % addresses, hypertext links, directories/paths, etc., which normally 
wenzelm@6619: % have no spaces.  The font may be selected using the \urlstyle command, 
wenzelm@6619: % and new url-like commands can be defined using \urldef.
wenzelm@6619: %
wenzelm@6619: % Usage:    Conditions:
wenzelm@6619: % \url{ }   If the argument contains any "%", "#", or "^^", or ends with
wenzelm@6619: %           "\", it can't be used in the argument to another command.  
wenzelm@6619: %           The argument must not contain unbalanced braces.
wenzelm@6619: % \url|  |  ...where "|" is any character not used in the argument and not 
wenzelm@6619: %           "{".  The same restrictions as above except that the argument
wenzelm@6619: %           may contain unbalanced braces.
wenzelm@6619: % \xyz      for "\xyz" a defined-url;  this can be used anywhere, no matter
wenzelm@6619: %           what characters it contains.
wenzelm@6619: % 
wenzelm@6619: % See further instructions after "\endinput"
wenzelm@6619: 
wenzelm@6619: \def\url@ttstyle{%
wenzelm@6619: \@ifundefined{selectfont}{\def\UrlFont{\tt}}{\def\UrlFont{\ttfamily}}% 
wenzelm@6619: \def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\%\do\;\do\>\do\]%
wenzelm@6619:  \do\)\do\,\do\?\do\'\do\+\do\=\do@url@hyp}%
wenzelm@6619: \def\UrlBigBreaks{\do\:}%
wenzelm@6619: \def\UrlNoBreaks{\do\(\do\[\do\{\do\<}% (unnecessary)
wenzelm@6619: \def\UrlSpecials{\do\ {\ }}%
wenzelm@6619: \def\UrlOrds{\do\*\do\-}% any ordinary characters that aren't usually
wenzelm@6619: }
wenzelm@6619: \def\url@rmstyle{%
wenzelm@6619: \@ifundefined{selectfont}{\def\UrlFont{\rm}}{\def\UrlFont{\rmfamily}}% 
wenzelm@6619: \def\UrlBreaks{\do\.\do\@\do\/\do\!\do\%\do\;\do\]\do\)\do\,\do\?\do@url@hyp
wenzelm@6619:   \do\+\do\=}%
wenzelm@6619: \def\UrlBigBreaks{\do\:}%
wenzelm@6619: \def\UrlNoBreaks{\do\(\do\[\do\{}% prevents breaks after *next* character
wenzelm@6619: \def\UrlSpecials{\do\<{\langle}\do\>{\rangle\penalty\relpenalty}\do\_{\_%
wenzelm@6619:  \penalty\@m}\do\|{\mid}\do\{{\lbrace}\do\}{\rbrace\penalty\relpenalty}\do
wenzelm@6619:  \\{\mathbin{\backslash}}\do\~{\mathord{{}^{\textstyle\sim}}}\do\ {\ }}%
wenzelm@6619: \def\UrlOrds{\do\'\do\"\do\-}%
wenzelm@6619: }
wenzelm@6619: \def\url@sfstyle{\url@rmstyle 
wenzelm@6619: \@ifundefined{selectfont}{\def\UrlFont{\sf}}{\def\UrlFont{\sffamily}}% 
wenzelm@6619: }
wenzelm@6619: \def\url@samestyle{\ifdim\fontdimen\thr@@\font=\z@ \url@ttstyle \else
wenzelm@6619:   \url@rmstyle \fi \def\UrlFont{}}
wenzelm@6619: 
wenzelm@6619: \def\do@url@hyp{}% by default, no breaks after hyphens
wenzelm@6619: 
wenzelm@6619: \@ifundefined{strip@prefix}{\def\strip@prefix#1>{}}{}
wenzelm@6619: \@ifundefined{verbatim@nolig@list}{\def\verbatim@nolig@list{\do\`}}{}
wenzelm@6619: 
wenzelm@6619: \def\Url{\relax\ifmmode\@nomatherr$\fi 
wenzelm@6619:  \UrlFont $\fam\z@ \textfont\z@\font 
wenzelm@6619:  \let\do\@makeother \dospecials % verbatim catcodes
wenzelm@6619:  \catcode`{\@ne \catcode`}\tw@ % except braces 
wenzelm@6619:  \medmuskip0mu \thickmuskip\medmuskip \thinmuskip\medmuskip
wenzelm@6619:  \@tempcnta\fam\multiply\@tempcnta\@cclvi 
wenzelm@6619:  \let\do\set@mathcode \UrlOrds % ordinary characters that were special
wenzelm@6619:  \advance\@tempcnta 8192 \UrlBreaks % bin
wenzelm@6619:  \advance\@tempcnta 4096 \UrlBigBreaks % rel
wenzelm@6619:  \advance\@tempcnta 4096 \UrlNoBreaks % open
wenzelm@6619:  \let\do\set@mathact \UrlSpecials % active
wenzelm@6619:  \let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures 
wenzelm@6619:  \@ifnextchar\bgroup\Url@z\Url@y}
wenzelm@6619: 
wenzelm@6619: \def\Url@y#1{\catcode`{11 \catcode`}11
wenzelm@6619:   \def\@tempa##1#1{\Url@z{##1}}\@tempa}
wenzelm@6619: \def\Url@z#1{\def\@tempa{#1}\expandafter\expandafter\expandafter\Url@use
wenzelm@6619:   \expandafter\strip@prefix\meaning\@tempa\, \relax\m@th$\endgroup}
wenzelm@6619: \let\Url@use\@empty
wenzelm@6619: 
wenzelm@6619: \def\set@mathcode#1{\count@`#1\advance\count@\@tempcnta\mathcode`#1\count@}
wenzelm@6619: \def\set@mathact#1#2{\mathcode`#132768 \lccode`\~`#1\lowercase{\def~{#2}}}
wenzelm@6619: \def\set@mathnolig#1{\ifnum\mathcode`#1<32768
wenzelm@6619:    \lccode`\~`#1\lowercase{\edef~{\mathchar\number\mathcode`#1_{\/}}}%
wenzelm@6619:    \mathcode`#132768 \fi}
wenzelm@6619: 
wenzelm@6619: \def\urldef#1#2{\begingroup \setbox\z@\hbox\bgroup
wenzelm@6619:   \def\Url@z{\Url@def{#1}{#2}}#2}
wenzelm@6619: \expandafter\ifx\csname DeclareRobustCommand\endcsname\relax
wenzelm@6619:   \def\Url@def#1#2#3{\m@th$\endgroup\egroup\endgroup
wenzelm@6619:     \def#1{#2{#3}}}
wenzelm@6619: \else
wenzelm@6619:   \def\Url@def#1#2#3{\m@th$\endgroup\egroup\endgroup
wenzelm@6619:     \DeclareRobustCommand{#1}{#2{#3}}}
wenzelm@6619: \fi
wenzelm@6619: 
wenzelm@6619: \def\urlstyle#1{\csname url@#1style\endcsname}
wenzelm@6619: 
wenzelm@6619: % Sample (and default) configuration:
wenzelm@6619: %
wenzelm@6619: \newcommand\url{\begingroup \Url}
wenzelm@6619: %
wenzelm@6619: \newcommand\path{\begingroup \urlstyle{tt}\Url}
wenzelm@6619: %
wenzelm@6619: % too many styles define \email like \address, so I will not define it.
wenzelm@6619: % \newcommand\email{\begingroup \urlstyle{rm}\Url}
wenzelm@6619: 
wenzelm@6619: % Process LaTeX \package options
wenzelm@6619: %
wenzelm@6619: \urlstyle{tt}
wenzelm@6619: \@ifundefined{ProvidesPackage}{}{
wenzelm@6619:   \ProvidesPackage{url}[1996/02/06 \space ver 1.1 \space 
wenzelm@6619:        Verb mode for urls, email addresses, and file names]
wenzelm@6619:   \DeclareOption{hyphens}{\def\do@url@hyp{\do\-}}% allow breaks after hyphens
wenzelm@6619:   \DeclareOption{obeyspaces}{\let\Url@use\relax}
wenzelm@6619:   \ProcessOptions
wenzelm@6619: \ifx\Url@use\relax \def\Url@use#1 #2{#1\ifx\relax#2\@empty\else
wenzelm@6619:   \penalty\relpenalty\ #2\expandafter\Url@use\fi}\fi
wenzelm@6619: }
wenzelm@6619: 
wenzelm@6619: \endinput
wenzelm@6619: %
wenzelm@6619: % url.sty  ver 1.1    6-Feb-1996   Donald Arseneau   asnd@reg.triumf.ca
wenzelm@6619: %
wenzelm@6619: % This package defines "\url", a form of "\verb" that allows linebreaks,
wenzelm@6619: % and can often be used in the argument to another command.  It can be
wenzelm@6619: % configured to print in different formats, and is particularly useful for 
wenzelm@6619: % hypertext links, email addresses, directories/paths, etc.  The font may 
wenzelm@6619: % be selected using the "\urlstyle" command and pre-defined text can be 
wenzelm@6619: % stored with the "\urldef" command. New url-like commands can be defined, 
wenzelm@6619: % and a "\path" command is provided this way. 
wenzelm@6619: %
wenzelm@6619: % Usage:    Conditions:
wenzelm@6619: % \url{ }   If the argument contains any "%", "#", or "^^", or ends with 
wenzelm@6619: %           "\", it can't be used in the argument to another command.  
wenzelm@6619: %           The argument must not contain unbalanced braces.
wenzelm@6619: % \url|  |  ...where "|" is any character not used in the argument and not 
wenzelm@6619: %           "{".  The same restrictions as above except that the argument
wenzelm@6619: %           may contain unbalanced braces.
wenzelm@6619: % \xyz      for "\xyz" a defined-url;  this can be used anywhere, no matter
wenzelm@6619: %           what characters it contains.
wenzelm@6619: % 
wenzelm@6619: % The "\url" command is fragile, and its argument is likely to be very
wenzelm@6619: % fragile, but a defined-url is robust.
wenzelm@6619: %
wenzelm@6619: % Package Option:  obeyspaces
wenzelm@6619: % Ordinarily, all spaces are ignored in the url-text.  The "[obeyspaces]" 
wenzelm@6619: % option allows spaces, but may introduce spurious spaces when a url
wenzelm@6619: % containing "\" characters is given in the argument to another command.  
wenzelm@6619: % So if you need to obey spaces should say "\usepackage[obeyspaces]{url}",
wenzelm@6619: % and if you need both spaces and backslashes, use a `defined-url' for 
wenzelm@6619: % anything with "\".
wenzelm@6619: %
wenzelm@6619: % Package Option:  hyphens
wenzelm@6619: % Ordinarily, breaks are not allowed after "-" characters because this 
wenzelm@6619: % leads to confusion. (Is the "-" part of the address or just a hyphen?)  
wenzelm@6619: % The package option "[hyphens]" allows breaks after explicit hyphen 
wenzelm@6619: % characters.  The "\url" command will *never ever* hyphenate words.
wenzelm@6619: % 
wenzelm@6619: % Defining a defined-url:
wenzelm@6619: % Take for example the email address "myself%node@gateway.net" which could
wenzelm@6619: % not be given (using "\url" or "\verb") in a caption or parbox due to the
wenzelm@6619: % percent sign.  This address can be predefined with 
wenzelm@6619: %    \urldef{\myself}\url{myself%node@gateway.net}   or
wenzelm@6619: %    \urldef{\myself}\url|myself%node@gateway.net|
wenzelm@6619: % and then you may use "\myself" instead of "\url{myself%node@gateway.net}"
wenzelm@6619: % in an argument, and even in a moving argument like a caption because a
wenzelm@6619: % defined-url is robust.
wenzelm@6619: %
wenzelm@6619: % Style: 
wenzelm@6619: % You can switch the style of printing using "\urlstyle{tt}", where "tt"
wenzelm@6619: % can be any defined style.  The pre-defined styles are "tt", "rm", "sf", 
wenzelm@6619: % and "same" which all allow the same linebreaks but different fonts -- 
wenzelm@6619: % the first three select a specific font and the "same" style uses the
wenzelm@6619: % current text font.  You can define your own styles with different fonts 
wenzelm@6619: % and/or line-breaking by following the explanations below.  The "\url" 
wenzelm@6619: % command follows whatever the currently-set style dictates.
wenzelm@6619: %
wenzelm@6619: % Alternate commands:
wenzelm@6619: % It may be desireable to have different things treated differently, each
wenzelm@6619: % in a predefined style; e.g., if you want directory paths to always be 
wenzelm@6619: % in tt and email addresses to be rm, then you would define new url-like
wenzelm@6619: % commands as follows:
wenzelm@6619: %
wenzelm@6619: %    \newcommand\email{\begingroup \urlstyle{rm}\Url}
wenzelm@6619: %    \newcommand\directory{\begingroup \urlstyle{tt}\Url}
wenzelm@6619: %
wenzelm@6619: % You must follow this format closely, and NOTE that the final command is 
wenzelm@6619: % "\Url", not "\url".  In fact, the "\directory" example is exactly the 
wenzelm@6619: % "\path" definition which is pre-defined in the package.  If you look 
wenzelm@6619: % above, you will see that "\url" is defined with
wenzelm@6619: %    \newcommand\url{\begingroup \Url}
wenzelm@6619: % I.e., using whatever url-style has been selected.
wenzelm@6619: %
wenzelm@6619: % You can make a defined-url for these other styles, using the usual 
wenzelm@6619: % "\urldef" command as in this example:
wenzelm@6619: %
wenzelm@6619: %    \urldef{\myself}{\email}{myself%node.domain@gateway.net}
wenzelm@6619: %
wenzelm@6619: % which makes "\myself" act like "\email{myself%node.domain@gateway.net}",
wenzelm@6619: % if the "\email" command is defined as above.  The "\myself" command is
wenzelm@6619: % robust.
wenzelm@6619: %
wenzelm@6619: % Defining styles:
wenzelm@6619: % Before describing how to customize the printing style, it is best to 
wenzelm@6619: % mention something about the unusual implementation of "\url".  Although
wenzelm@6619: % the material is textual in nature, and the font specification required
wenzelm@6619: % is a text-font command, the text is actually typeset in *math* mode.
wenzelm@6619: % This allows the context-sensitive linebreaking, but also accounts for
wenzelm@6619: % the default behavior of ignoring spaces.  Now on to defining styles.
wenzelm@6619: %
wenzelm@6619: % To change the font or the list of characters that allow linebreaks, you
wenzelm@6619: % could redefine the commands "\UrlFont", "\UrlBreaks", "\UrlSpecials" etc.
wenzelm@6619: % directly in the document, but it is better to define a new `url-style' 
wenzelm@6619: % (following the example of "\url@ttstyle" and "\url@rmstyle") which defines 
wenzelm@6619: % all of "\UrlBigbreaks", "\UrlNoBreaks", "\UrlBreaks", "\UrlSpecials", and 
wenzelm@6619: % "\UrlFont".
wenzelm@6619: %
wenzelm@6619: % Changing font:
wenzelm@6619: % The "\UrlFont" command selects the font.  The definition of "\UrlFont"
wenzelm@6619: % done by the pre-defined styles varies to cope with a variety of LaTeX
wenzelm@6619: % font selection schemes, but it could be as simple as "\def\UrlFont{\tt}".
wenzelm@6619: % In addition to setting "\UrlFont", some characters will probably need 
wenzelm@6619: % to be defined in the "\UrlSpecials" list because most fonts don't have 
wenzelm@6619: % all the standard input characters.  See the definition of "\url@rmstyle", 
wenzelm@6619: % which implements "\urlstyle{rm}".  Or even better, follow the definition
wenzelm@6619: % of "\url@sfstyle", which executes "\url@rmstyle" and then redefines
wenzelm@6619: % just "\UrlFont".  The nominal format for each special character "c" 
wenzelm@6619: % in the "\UrlSpecials" list is: "\do\c{<definition>}", but you can 
wenzelm@6619: % include other definitions too.
wenzelm@6619: %
wenzelm@6619: % Changing linebreaks:
wenzelm@6619: % The list of characters that allow line-breaks is given by "\UrlBreaks" 
wenzelm@6619: % and "\UrlBigBreaks", which have the format "\do\c" for character "c". 
wenzelm@6619: % The differences are that `BigBreaks' have a lower penalty and have 
wenzelm@6619: % different breakpoints when in sequence (as in "http://"): `BigBreaks' 
wenzelm@6619: % are treated as mathrels while `Breaks' are mathbins (see The TeXbook, 
wenzelm@6619: % p.170). In particular, a series of `BigBreak' characters will break at 
wenzelm@6619: % the end and only at the end; a series of `Break' characters will break 
wenzelm@6619: % after the first and after every following *pair*; there will be no 
wenzelm@6619: % break after a `Break' character if a `BigBreak' follows.  In the case 
wenzelm@6619: % of "http://" it doesn't matter whether ":" is a `Break' or `BigBreak' --
wenzelm@6619: % the breaks are the same in either case; but for DECnet nodes with "::"
wenzelm@6619: % it is important to prevent breaks *between* the colons, and that is why 
wenzelm@6619: % colons are `BigBreaks'.
wenzelm@6619: %
wenzelm@6619: % It is possible for characters to prevent breaks after the next following 
wenzelm@6619: % character (I use this for parentheses).  Specify these in "\UrlNoBreaks". 
wenzelm@6619: %
wenzelm@6619: % You can do arbitrarily complex things with characters by making them 
wenzelm@6619: % active in math mode (mathcode hex-8000) and specifying the definition(s)
wenzelm@6619: % in "\UrlSpecials".  This is used in the rm and sf styles to handle 
wenzelm@6619: % several characters that are not present in fonts.
wenzelm@6619: %
wenzelm@6619: % If all this sounds confusing ... well, it is!  But I hope you won't need 
wenzelm@6619: % to redefine breakpoints -- the default assignments seem to work well for 
wenzelm@6619: % a wide variety of applications.  If you do need to make changes, you can 
wenzelm@6619: % test for breakpoints using regular math mode and the characters "+=(a".
wenzelm@6619: %
wenzelm@6619: % Yet more flexibility:
wenzelm@6619: % You can also set up url.sty to do multiple things with the verbatim text
wenzelm@6619: % by defining "\Url@use", but the format of the definition is special:
wenzelm@6619: %
wenzelm@6619: %    \def\Url@use#1\,{ ... do things with #1 ... }
wenzelm@6619: %
wenzelm@6619: % Yes, that is "#1" followed by "\," then the definition.  For example, 
wenzelm@6619: % to put a hypertext link in the DVI file:
wenzelm@6619: %
wenzelm@6619: %    \def\Url@use#1\,{\special{html:<a href="#1">}#1\special{html:</a>}}
wenzelm@6619: %
wenzelm@6619: % The End
wenzelm@6619: % ver 1.1 6-Feb-1996:  
wenzelm@6619: % Fix hyphens that wouldn't break and ligatures that weren't suppressed.
wenzelm@6619: 
wenzelm@6619: Test file integrity:  ASCII 32-57, 58-126:  !"#$%&'()*+,-./0123456789
wenzelm@6619: :;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~




