%%
%% This is file `breakurl.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% breakurl.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2005 by Vilar Camara Neto.
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.2 of this license or (at your option) any later
%% version.  The latest version of this license is in:
%% 
%%     http://www.latex-project.org/lppl.txt
%% 
%% and version 1.2 or later is part of all distributions of
%% LaTeX version 1999/12/01 or later.
%% 
%% Currently this work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Vilar Camara Neto.
%% 
%% This work consists of the files breakurl.dtx and
%% breakurl.ins and the derived file breakurl.sty.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{breakurl}
    [2008/04/05 v1.22 Breakable hyperref URLs]


\RequirePackage{xkeyval}
\RequirePackage{ifpdf}

\ifpdf
  % Dummy package options
  \DeclareOptionX{preserveurlmacro}{}
  \DeclareOptionX{hyphenbreaks}{}
  \DeclareOptionX{vertfit}{}
  \ProcessOptionsX\relax

  \PackageWarning{breakurl}{%
  You are using breakurl while processing via pdflatex.\MessageBreak
  \string\burl\space will be just a synonym of \string\url.\MessageBreak}
  \DeclareRobustCommand{\burl}{\url}
  \DeclareRobustCommand*{\burlalt}{\hyper@normalise\burl@alt}
  \def\burl@alt#1#2{\hyper@linkurl{\Hurl{#1}}{#2}}
  \expandafter\endinput
\fi

\@ifpackageloaded{hyperref}{}{%
  \PackageError{breakurl}{The breakurl depends on hyperref package}%
  {I can't do anything. Please type X <return>, edit the source file%
  \MessageBreak
  and add \string\usepackage\string{hyperref\string} before
  \string\usepackage\string{breakurl\string}.}
  \endinput
}

\newif\if@preserveurlmacro\@preserveurlmacrofalse
\newif\if@burl@fitstrut\@burl@fitstrutfalse
\newif\if@burl@fitglobal\@burl@fitglobalfalse

\newtoks\burl@toks

\def\burl@charlist{}
\def\burl@addtocharlist#1{%
  \expandafter\gdef\expandafter\burl@charlist\expandafter{%
    \burl@charlist #1}%
}

\bgroup
\catcode`\&=12\relax
\hyper@normalise\burl@addtocharlist{:/.?#&_,;!}
\egroup

\def\burl@growmif#1{%
  \expandafter\def\expandafter\burl@mif\expandafter{%
    \burl@mif\def\burl@ttt{#1}\ifx\burl@ttt\@nextchar\@burl@breakabletrue\else
  }%
}
\def\burl@growmfi{%
  \expandafter\def\expandafter\burl@mfi\expandafter{\burl@mfi\fi}%
}
\def\burl@melse{%
  \if@burl@breakable\burl@flush\linebreak[0]\@burl@breakablefalse\fi
  \expandafter\expandafter\expandafter\burl@toks
    \expandafter\expandafter\expandafter{%
    \expandafter\the\expandafter\burl@toks\@nextchar}%
}
\def\burl@defifstructure{%
  \def\burl@mif{}%
  \def\burl@mfi{}%
  \expandafter\@tfor\expandafter\@nextchar\expandafter:\expandafter=%
    \burl@charlist\do{%
    \expandafter\burl@growmif\@nextchar
    \burl@growmfi
  }%
}

\AtEndOfPackage{\burl@defifstructure}

\def\burl@setvertfit#1{%
  \lowercase{\def\burl@temp{#1}}%
  \def\burl@opt{local}\ifx\burl@temp\burl@opt
    \@burl@fitstrutfalse\@burl@fitglobalfalse
  \else\def\burl@opt{strut}\ifx\burl@temp\burl@opt
    \@burl@fitstruttrue\@burl@fitglobalfalse
  \else\def\burl@opt{global}\ifx\burl@temp\burl@opt
    \@burl@fitstrutfalse\@burl@fitglobaltrue
  \else
    \PackageWarning{breakurl}{Unrecognized vertfit option `\burl@temp'.%
    \MessageBreak
    Adopting default `local'}
    \@burl@fitstrutfalse\@burl@fitglobalfalse
  \fi\fi\fi
}

\DeclareOptionX{preserveurlmacro}{\@preserveurlmacrotrue}
\DeclareOptionX{hyphenbreaks}{\bgroup
  \catcode`\&=12\relax\hyper@normalise\burl@addtocharlist{-}%
  \egroup}
\DeclareOptionX{vertfit}[local]{\burl@setvertfit{#1}}

\ProcessOptionsX\relax

\def\burl@hyper@linkurl#1#2{%
  \begingroup
    \hyper@chars
    \burl@condpdflink{#1}%
  \endgroup
}

\def\burl@condpdflink#1{%
  \if@burl@fitstrut
    \sbox\pdf@box{#1\strut}%
  \else\if@burl@fitglobal
    \sbox\pdf@box{\burl@url}%
  \else
    \sbox\pdf@box{#1}%
  \fi\fi
  \dimen@\ht\pdf@box\dimen@ii\dp\pdf@box
  \sbox\pdf@box{#1}%
  \ifdim\dimen@ii=\z@
    \literalps@out{BU.SS}%
  \else
    \lower\dimen@ii\hbox{\literalps@out{BU.SS}}%
  \fi
  \ifHy@breaklinks\unhbox\else\box\fi\pdf@box
  \ifdim\dimen@=\z@
    \literalps@out{BU.SE}%
  \else
    \raise\dimen@\hbox{\literalps@out{BU.SE}}%
  \fi
  \pdf@addtoksx{H.B}%
}

\DeclareRobustCommand*{\burl}{%
  \leavevmode
  \begingroup
  \let\hyper@linkurl=\burl@hyper@linkurl
  \catcode`\&=12\relax
  \hyper@normalise\burl@
}

\DeclareRobustCommand*{\burlalt}{%
  \begingroup
  \let\hyper@linkurl=\burl@hyper@linkurl
  \catcode`\&=12\relax
  \hyper@normalise\burl@alt
}

\newif\if@burl@breakable

\bgroup
\catcode`\&=12\relax
\gdef\burl@#1{%
  \def\burl@url{#1}%
  \def\burl@urltext{#1}%
  \burl@doit
}

\gdef\burl@alt#1{%
  \def\burl@url{#1}%
  \hyper@normalise\burl@@alt
}
\gdef\burl@@alt#1{%
  \def\burl@urltext{#1}%
  \burl@doit
}

\gdef\burl@doit{%
  \burl@toks{}%
  \let\burl@UrlRight=\UrlRight
  \let\UrlRight=\empty
  \@ifundefined{@urlcolor}{\Hy@colorlink\@linkcolor}{\Hy@colorlink\@urlcolor}%
  \@burl@breakablefalse
  \expandafter\@tfor\expandafter\@nextchar\expandafter:\expandafter=%
    \burl@urltext\do{%
    \expandafter\burl@mif\expandafter\burl@melse\burl@mfi
    \if@burl@breakable
      \expandafter\expandafter\expandafter\burl@toks
        \expandafter\expandafter\expandafter{%
        \expandafter\the\expandafter\burl@toks\@nextchar}%
    \fi
  }%
  \let\UrlRight=\burl@UrlRight
  \burl@flush
  \literalps@out{BU.E}%
  \Hy@endcolorlink
  \endgroup
}
\egroup

\def\the@burl@toks{\the\burl@toks}

\def\burl@flush{%
  \expandafter\def\expandafter\burl@toks@def\expandafter{\the\burl@toks}%
  \literalps@out{/BU.L (\burl@url) def}%
  \hyper@linkurl{\expandafter\Hurl\expandafter{\burl@toks@def}}{\burl@url}%
  \global\burl@toks{}%
  \let\UrlLeft=\empty
}%

\if@preserveurlmacro\else\let\url\burl\let\urlalt\burlalt\fi

\AtBeginDvi{%
  \headerps@out{%
    /burl@stx null def
    /BU.S {
      /burl@stx null def
    } def
    /BU.SS {
      currentpoint
      /burl@lly exch def
      /burl@llx exch def
      burl@stx null ne {burl@endx burl@llx ne {BU.FL BU.S} if} if
      burl@stx null eq {
        burl@llx dup /burl@stx exch def /burl@endx exch def
        burl@lly dup /burl@boty exch def /burl@topy exch def
      } if
      burl@lly burl@boty gt {/burl@boty burl@lly def} if
    } def
    /BU.SE {
      currentpoint
      /burl@ury exch def
      dup /burl@urx exch def /burl@endx exch def
      burl@ury burl@topy lt {/burl@topy burl@ury def} if
    } def
    /BU.E {
      BU.FL
    } def
    /BU.FL {
      burl@stx null ne {BU.DF} if
    } def
    /BU.DF {
      BU.BB
      [ /H /I /Border [\@pdfborder] /Color [\@urlbordercolor]
      /Action << /Subtype /URI /URI BU.L >> /Subtype /Link BU.B /ANN pdfmark
      /burl@stx null def
    } def
    /BU.BB {
      burl@stx HyperBorder sub /burl@stx exch def
      burl@endx HyperBorder add /burl@endx exch def
      burl@boty HyperBorder add /burl@boty exch def
      burl@topy HyperBorder sub /burl@topy exch def
    } def
    /BU.B {
      /Rect[burl@stx burl@boty burl@endx burl@topy]
    } def
    /eop where {
      begin
      /@ldeopburl /eop load def
      /eop { SDict begin BU.FL end @ldeopburl } def
      end
    } {
      /eop { SDict begin BU.FL end } def
    } ifelse
  }%
}
\endinput
%%
%% End of file `breakurl.sty'.
