% url.sty ver 0.4 10-Nov-1995 Donald Arseneau asnd@reg.triumf.ca % % A form of \verb that allows linebreaks at certain characters or % combinations of characters, accepts reconfiguration, and can often % be used in the argument to another command. It is intended for % email addresses, hypertext links, directories/paths, etc., which % normally have no spaces. The font may be selected using the \urlstyle % command, and new url-like commands can be defined using \urldef. % % Usage: Conditions: % \url{ } If the argument contains any "%", "#", or "^^", or ends with % "\", it can't be used in the argument to another command. % The argument must not contain unbalanced braces. % \url| | ...where "|" is any character not used in the argument and not % "{". The same restrictions as above except that the argument % may contain unbalanced braces. % \xyz for "\xyz" a defined-url; this can be used anywhere, no matter % what characters it contains. % % See further instructions after "\endinput" \def\url@ttstyle{% \def\UrlFont{\@ifundefined{mathtt}{\tt}{\mathtt\relax}}% \def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\%\do\;\do\>\do\]% \do\)\do\,\do\?\do\'\do\+\do\=}% \def\UrlBigBreaks{\do\:}% \def\UrlNoBreaks{\do\(\do\[\do\{\do\<}% (unnecessary) \def\UrlSpecials{\do\ {\ }}% \def\UrlOrds{\do\*\do@url@hyp}% any ordinary characters that aren't usually } \def\url@rmstyle{% \def\UrlFont{\fam\z@}% defs for roman font \def\UrlBreaks{\do\.\do\@\do\/\do\!\do\%\do\;\do\]\do\)\do\,\do\?\do+\do\=}% \def\UrlBigBreaks{\do\:}% \def\UrlNoBreaks{\do\(\do\[\do\{}% prevents breaks after *next* character \def\UrlSpecials{\do\<{\langle}\do\>{\rangle\penalty\relpenalty}\do\_{\_% \penalty\@m}\do\|{\mid}\do\{{\lbrace}\do\}{\rbrace\penalty\relpenalty}\do \\{\mathbin{\backslash}}\do\~{\mathord{\sim}}\do\ {\ }}% \def\UrlOrds{\do@url@hyp\do\'\do\"}% } \def\do@url@hyp{\do\-}% by default, no breaks after hyphens \def\url@sfstyle{\url@rmstyle \def\UrlFont{\@ifundefined{mathsf}{\sf}{\mathsf\relax}}}% % Alternative, if character status unknown: % \def\UrlOrds{% % \@tempcnta\fam \multiply\@tempcnta\@cclvi \count@\m@ne % \@whilenum \count@<\url@maxchar \do % set all characters as ordinary-tt % {\advance\count@\@ne \mathcode\count@\@tempcnta \advance\@tempcnta\@ne}% % } \@ifundefined{noboundary}{\chardef\url@maxchar127 }{\chardef\url@maxchar255 } \@ifundefined{strip@prefix}{\def\strip@prefix#1>{}}{} \@ifundefined{verbatim@nolig@list}{\def\verbatim@nolig@list{\do\`}}{} \def\Url{\relax\ifmmode\@nomatherr\else$\fi \let\math@bgroup\relax \let\math@egroup\relax % force no-argument mode! \UrlFont \ifnum\fam<\z@ \fam\z@ \textfont\z@\font \else \textfont\z@\textfont\fam\fi \let\do\@makeother \dospecials % verbatim catcodes \catcode`{\@ne \catcode`}\tw@ \catcode`\ 12 % except braces and spaces \medmuskip0mu \thickmuskip\medmuskip \thinmuskip\medmuskip \@tempcnta\fam\multiply\@tempcnta\@cclvi \let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures \let\do\set@mathcode \UrlOrds % ordinary characters that were special \advance\@tempcnta 8192 \UrlBreaks % bin \advance\@tempcnta 4096 \UrlBigBreaks % rel \advance\@tempcnta 4096 \UrlNoBreaks % open \let\do\set@mathact \UrlSpecials % active \@ifnextchar\bgroup\Url@z\Url@y} \def\Url@y#1{\catcode`{11 \catcode`}11 \def\@tempa##1#1{\Url@z{##1}}\@tempa} \def\Url@z#1{\def\@tempa{#1 }\let\@tempb\@empty \expandafter\expandafter\expandafter\Url@s \expandafter\strip@prefix\meaning\@tempa $ \m@th$\endgroup} \def\Url@s#1$ {#1} \def\Urldef#1#2{\begingroup \setbox\z@\hbox\bgroup \def\url@command{#2}\def\url@type{#1}% \let\Url@z\Url@def #1} \def\Url@def#1{\toks@\expandafter{\url@type{#1}}% \expandafter\xdef\url@command{\the\toks@}% \m@th$\endgroup\egroup\endgroup} \def\set@mathcode#1{\count@`#1\advance\count@\@tempcnta\mathcode`#1\count@} \def\set@mathact#1#2{\mathcode`#132768 \lccode`\~`#1\lowercase{\def~{#2}}} \def\set@mathnolig#1{\mathcode`#132768 \lccode`\~`#1\relax \count@`#1\advance\count@\@tempcnta \lowercase{\edef~{{\mathchar\number\count@\kern\z@}}}} \def\urlstyle#1{\csname url@#1style\endcsname} % Sample configuration: \newcommand\url{\begingroup \Url} \newcommand\urldef{\Urldef\url} % \newcommand\path{\begingroup \urlstyle{tt}\Url} \newcommand\pathdef{\Urldef\path} % \newcommand\email{\begingroup \urlstyle{rm}\Url} % Process LaTeX \package options \urlstyle{tt} \@ifundefined{ProvidesPackage}{}{ \ProvidesPackage{url}[1995/11/10 \space \space Verb mode for url and email addresses] \DeclareOption{hyphens}{\def\do@url@hyp{}}% allow breaks after hyphens \DeclareOption{obeyspaces}{\let\Url@s\relax} \ProcessOptions \ifx\Url@s\relax \def\Url@s#1 {\ifx$#1\@empty\else \@tempb\def\@tempb{\penalty\relpenalty\ }#1\expandafter\Url@s\fi}\fi } \endinput % % url.sty ver 0.4 10-Nov-1995 Donald Arseneau asnd@reg.triumf.ca % % This package defines "\url", a form of "\verb" that allows linebreaks, % and can often be used in the argument to another command. It can be % configured to print in different formats. It is particularly useful for hypertext % links, email addresses, directories/paths, etc. The font may be selected % using the "\urlstyle" command and pre-defined text can be stored with the % "\urldef" command. New url-like commands can be defined, and a "\path" % command is provided this way. % % Usage: Conditions: % \url{ } If the argument contains any "%", "#", or "^^", or ends with % "\", it can't be used in the argument to another command. % The argument must not contain unbalanced braces. % \url| | ...where "|" is any character not used in the argument and not % "{". The same restrictions as above except that the argument % may contain unbalanced braces. % \xyz for "\xyz" a defined-url; this can be used anywhere, no matter % what characters it contains. % % Package Option: obeyspaces % Ordinarily, all spaces are ignored in the url-text. The "[obeyspaces]" % option allows spaces, but may introduce spurious spaces if there are any % "\" in the text and the "\url" appears in the argument to another command. % So if you need to obey spaces and have no "\" characters, you should say % "\usepackage[obeyspaces]{url}". If you need both spaces and backslashes, % use a `defined-url' for anything with "\". % % Package Option: hyphens % Ordinarily, breaks are not allowed after "-" characters because this % leads to confusion. (Is the "-" part of the address or just a hyphen?") % The package option "[hyphens]" allows breaks after hyphen characters. % The "\url" command will *never ever* hyphenate words. % % Defining a defined-url: % Take for example the email address "myself%node@gateway.net" which could % not be given (using "\url" or "\verb") in a caption or parbox due to the % percent sign. However, this address can be predefined elsewhere in the % document with % \urldef{\myself}{myself%node@gateway.net} or % \urldef{\myself}|myself%node@gateway.net| % and then you may use the command "\myself" in a caption. % % Style: % You can switch the style of printing using "\urlstyle{tt}", where the % "tt" can be any defined style. The pre-defined styles are tt, rm, and % sf, which all allow the same linebreaks but different fonts. You can % define styles with different fonts and/or breakpoints by redefining % the commands "\UrlFont" and "\UrlBreaks" etc., either directly or in a % style-changing macro modelled on "\url@ttstyle" and "\url@rmstyle", and % the explanations below. The "\url" command follows whatever the % currently-set style dictates. % % Alternate commands: % It may be desireable to have different things treated differently, each % in a predefined style; e.g., if you want directory paths to always be % in tt and email addresses to be rm, then you would define new url-like % commands as follows: % % \newcommand\email{\begingroup \urlstyle{rm}\Url} % \newcommand\directory{\begingroup \urlstyle{tt}\Url} % % You must follow this format closely, and NOTE that the final command is % "\Url", not "\url". In fact, the "\directory" example is exactly the % "\path" definition which is pre-defined in the package. If you look % above, you will see that "\url" is defined with % \newcommand\url{\begingroup \Url} % I.e., using whatever style has been selected. % % In order to make a defined-url for these other styles, you would use the % capitalized "\Urldef" command as in this example: % % \Urldef{\email}{\myself}{myself%node.domain@gateway.net} % % which makes "\myself" act like "\email{myself%node.domain@gateway.net}", % if the "\email" command is defined as above. % To go with the "\path" command, this package defines "\pathdef" as % a shorthand for "\Urldef{\path}". % % Defining styles: % To change the font or the list of characters that allow linebreaks, you % should define a `url-style' (following the example of "\url@ttstyle" and % "\url@rmstyle") which defines all of "\UrlBigbreaks", "\UrlNoBreaks", % "\UrlBreaks", "\UrlSpecials", and "\UrlFont". % % Changing font: % The "\UrlFont" command selects the font; be aware that this is a % *math-mode* switch, not taking an argument. The default definition % of \UrlFont for tt type is complicated in order to handle various font % selection schemes and different versions of LaTeX. In addition to % setting "\UrlFont", some characters will probably need to be defined % in the "\UrlSpecials" list because most fonts don't have all standard % characters. See the definition of "\url@rmstyle", which implements % "\urlstyle{rm}". The nominal format for each special character "c" % is: "\do\c{}", but you can include other definitions. % % Changing linebreaks: % The list of characters that allow line-breaks is given by \UrlBreaks % and \UrlBigBreaks, which have the format "\do\c" for character "c". % The differences are that `BigBreaks' have a lower penalty and have % different breakpoints when in sequence (as in "http://"): `BigBreaks' % are treated as mathrels while `Breaks' are mathbins (see The TeXbook, % p.170). In particular, a series of `BigBreak' characters will break at % the end and only at the end; a series of `Break' characters will break % after the first and after every following *pair*; there will be no % break after a `Break' character if a `BigBreak' follows. In the case % of "http://" it doesn't matter whether ":" is a `Break' or `BigBreak' -- % the breaks are the same in either case; but for DECnet nodes with "::" % it is important to prevent breaks *between* the colons, and that is why % colons are `BigBreaks'. % % It is possible for characters to prevent breaks after the next following % character (I use this for parentheses). Specify these in "\UrlNoBreaks". % % You can do arbitrarily complex things with characters by making them % active in math mode (mathcode hex-8000) and specifying the definition(s) % in "\UrlSpecials". This is used in the rm and sf styles to handle % several characters that are not present in fonts. % % If all this sounds confusing ... well, it is! But I hope you won't need % to redefine breakpoints -- the default assignments seem to work well for % a wide variety of applications. If you do need to make changes, you can % test for breakpoints using regular math mode and the characters "+=(a".