%%
%% This is file `zref-xr.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% zref.dtx  (with options: `xr')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2006, 2007 by Heiko Oberdiek <oberdiek@uni-freiburg.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 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.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Heiko Oberdiek.
%% 
%% This work consists of the main source file zref.dtx
%% and the derived files
%%    zref.sty, zref.pdf, zref.ins, zref.drv,
%%    zref-base.sty, zref-abspage.sty, zref-counter.sty,
%%    zref-dotfill.sty, zref-hyperref.sty, zref-lastpage.sty,
%%    zref-perpage.sty, zref-savepos.sty, zref-titleref.sty,
%%    zref-totpages.sty, zref-user.sty, zref-xr.sty,
%%    zref-example.tex.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{zref-xr}%
  [2007/05/06 v2.0 Module xr for zref (HO)]%
\RequirePackage{zref-base}[2007/05/06]
\@ifundefined{ZREF@baseok}{\endinput}{}
\RequirePackage{keyval}
\zref@newprop{url}{}%
\providecommand*{\zref@xr@ext}{%
  \@ifundefined{XR@ext}{pdf}{\XR@ext}%
}%
\newif\ifZREF@xr@zreflabel
\newcommand*{\zexternaldocument}{%
  \begingroup
    \csname @safe@actives@true\endcsname
    \makeatletter
    \@ifstar{%
      \ZREF@xr@zreflabelfalse
      \@testopt\ZREF@xr@externaldocument{}%
    }{%
      \ZREF@xr@zreflabeltrue
      \@testopt\ZREF@xr@externaldocument{}%
    }%
}%
\def\ZREF@xr@externaldocument[#1]#2{%
    \def\ZREF@xr@prefix{#1}%
    \let\ZREF@xr@filelist\@empty
    \edef\ZREF@xr@file{#2.aux}%
    \filename@parse{#2}%
    \@testopt\ZREF@xr@graburl{#2.\zref@xr@ext}%
}%
\def\ZREF@xr@graburl[#1]{%
    \edef\ZREF@xr@url{#1}%
    \ZREF@xr@checkfile
  \endgroup
}%
\def\ZREF@xr@checkfile{%
  \openin\@inputcheck\ZREF@xr@file\relax
  \ifeof\@inputcheck
    \PackageWarning{zref/xr}{%
      File `\ZREF@xr@file' not found or empty,\MessageBreak
      labels not imported%
    }%
  \else
    \PackageInfo{zref/xr}{%
      Label \ifZREF@xr@zreflabel (zref) \fi import from `\ZREF@xr@file'%
    }%
    \def\ZREF@xr@found{0}%
    \def\ZREF@xr@ignored{0}%
    \ZREF@xr@processfile
    \closein\@inputcheck
    \begingroup
      \let\on@line\@empty
      \PackageInfo{zref/xr}{%
        Statistics for `\ZREF@xr@file': %
        \ZREF@xr@found\space found, %
        \ZREF@xr@ignored\space ignored%
      }%
    \endgroup
  \fi
  \ifx\ZREF@xr@filelist\@empty
  \else
    \edef\ZREF@xr@file{\expandafter\@car\ZREF@xr@filelist\@nil}%
    \edef\ZREF@xr@filelist{\expandafter\@cdr\ZREF@xr@filelist\@nil}%
    \expandafter\ZREF@xr@checkfile
  \fi
}%
\def\ZREF@xr@processfile{%
  \read\@inputcheck to\ZREF@xr@line
  \expandafter\ZREF@xr@processline\ZREF@xr@line..\ZREF@nil
  \ifeof\@inputcheck
  \else
    \expandafter\ZREF@xr@procesfile
  \fi
}%
\long\def\ZREF@xr@processline#1#2#3\ZREF@nil{%
  \def\x{#1}%
  \toks@{#2}%
  \ifZREF@xr@zreflabel
    \ifx\x\ZREF@xr@zref@newlabel
      \expandafter\ZREF@xr@process@zreflabel\ZREF@xr@line...\ZREF@nil
    \fi
  \else
    \ifx\x\ZREF@xr@newlabel
      \expandafter\ZREF@xr@process@label\ZREF@xr@line...[]\ZREF@nil
    \fi
  \fi
  \ifx\x\ZREF@xr@@input
    \edef\ZREF@xr@filelist{%
      \etex@unexpanded\expandafter{\ZREF@xr@filelist}%
      {\filename@area\the\toks@}%
    }%
  \fi
  \ifeof\@inputcheck
  \else
    \expandafter\ZREF@xr@processfile
  \fi
}%
\def\ZREF@xr@process@zreflabel\zref@newlabel#1#2#3\ZREF@nil{%
  \def\ZREF@xr@refname{Z@R@\ZREF@xr@prefix#1}%
  \edef\ZREF@xr@found{\the\numexpr\ZREF@xr@found+1\relax}%
  \def\x{#2}%
  \@ifundefined{\ZREF@xr@refname}{%
    \let\ZREF@xr@list\x
    \ifx\ZREF@xr@list\@empty
      \PackageWarningNoLine{zref/xr}{%
        Label `#1' without properties ignored\MessageBreak
        in file `\ZREF@xr@file'%
      }%
      \edef\ZREF@xr@ignored{\the\numexpr\ZREF@xr@ignored+1\relax}%
    \else
      \expandafter\ZREF@xr@checklist\x\ZREF@nil
      \expandafter\global\expandafter\let
          \csname \ZREF@xr@refname\endcsname\x
    \fi
    \ZREF@xr@urlcheck{\ZREF@xr@prefix#1}%
  }{%
    \ZREF@xr@ignorewarning{\ZREF@xr@prefix#1}%
  }%
}%
\def\ZREF@xr@process@label\newlabel#1#2#3[#4]#5\ZREF@nil{%
  \def\ZREF@xr@refname{Z@R@\ZREF@xr@prefix#1}%
  \edef\ZREF@xr@found{\the\numexpr\ZREF@xr@found+1\relax}%
  \def\x{#2}%
  \@ifundefined{\ZREF@xr@refname}{%
    \expandafter\ZREF@xr@scanparams
        \csname\ZREF@xr@refname\expandafter\endcsname
        \x{}{}{}{}{}\ZREF@nil
    \ifx\\#4\\%
    \else
      % ntheorem knows an optional argument at the end of \newlabel
      \zref@ifpropundefined{theotype}{%
        \zref@newprop{theotype}{}%
      }{}%
      \expandafter\g@addto@macro
          \csname\ZREF@xr@refname\endcsname{\theotype{#4}}%
    \fi
    \ZREF@xr@urlcheck{\ZREF@xr@prefix#1}%
  }{%
    \ZREF@xr@ignorewarning{\ZREF@xr@prefix#1}%
  }%
}
\def\ZREF@xr@zref@newlabel{\zref@newlabel}%
\def\ZREF@xr@newlabel{\newlabel}%
\def\ZREF@xr@@input{\@input}%
\def\ZREF@xr@ignorewarning#1{%
  \PackageWarningNoLine{zref/xr}{%
    Label `#1' is already in use\MessageBreak
    in file `\ZREF@xr@file'%
  }%
  \edef\ZREF@xr@ignored{\the\numexpr\ZREF@xr@ignored+1\relax}%
}%
\def\ZREF@xr@checklist#1#2#3\ZREF@nil{%
  \ifx\@undefined#1\relax
    \expandafter\ZREF@xr@checkkey\string#1\@nil
  \fi
  \ifx\\#3\\%
  \else
    \@ReturnAfterFi{%
      \ZREF@xr@checklist#3\ZREF@nil
    }%
  \fi
}%
\long\def\@ReturnAfterFi#1\fi{\fi#1}%
\def\ZREF@xr@checkkey#1#2\@nil{%
  \zref@ifpropundefined{#2}{%
    \zref@newprop{#2}{}%
  }{}%
}%
\def\ZREF@xr@scanparams#1#2#3#4#5#6#7\ZREF@nil{%
  \global\let#1\@empty
  \ZREF@foundfalse
  \ZREF@xr@scantitleref#1#2\TR@TitleReference{}{}\ZREF@nil
  \ifZREF@found
  \else
    \g@addto@macro#1{\default{#2}}%
  \fi
  % page
  \g@addto@macro#1{\page{#3}}%
  % nameref title
  \ifZREF@found
  \else
    \ifx\\#4\\%
    \else
      \zref@ifpropundefined{title}{%
        \zref@newprop{title}{}%
      }{}%
      \g@addto@macro#1{\title{#4}}%
    \fi
  \fi
  % anchor
  \ifx\\#5\\%
  \else
    \zref@ifpropundefined{anchor}{%
      \zref@newprop{anchor}{}%
    }{}%
    \g@addto@macro#1{\anchor{#5}}%
  \fi
  \ifx\\#6\\%
  \else
    \zref@ifpropundefined{url}{%
      \zref@newprop{url}{}%
    }{}%
    \g@addto@macro#1{\url{#6}}%
  \fi
}%
\def\ZREF@xr@scantitleref#1#2\TR@TitleReference#3#4#5\ZREF@nil{%
  \ifx\\#5\\%
  \else
    \g@addto@macro#1{%
      \default{#3}%
      \title{#4}%
    }%
    \ZREF@foundtrue
  \fi
}%
\def\ZREF@xr@urlcheck#1{%
  \zref@ifrefcontainsprop{#1}{anchor}{%
    \zref@ifrefcontainsprop{#1}{url}{%
    }{%
      \expandafter\g@addto@macro\csname Z@R@#1\expandafter\endcsname
      \expandafter{%
        \expandafter\url\expandafter{\ZREF@xr@url}%
      }%
    }%
  }{%
  }%
}%
\define@key{ZREF@XR}{ext}{%
  \def\zref@xr@ext{#1}%
}%
\newcommand*{\zxrsetup}{%
  \setkeys{ZREF@XR}%
}%
\endinput
%%
%% End of file `zref-xr.sty'.
