Annotation of embedaddon/bird/doc/tex/url.sty, revision 1.1.1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>