%%
%% This is file `backref.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% backref.dtx  (with options: `package')
%% 
%% File: backref.dtx
%% Copyright (C) 1995-2000 David Carlisle, Sebastian Rahtz, Heiko Oberdiek
%%               2001-2012 Heiko Oberdiek
%%
%% This file is part of the `Hyperref Bundle'.
%% -------------------------------------------
%%
%% 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'.
%%
%% The Current Maintainer of this work is Heiko Oberdiek.
%%
%% The list of all files belonging to the `Hyperref Bundle' is
%% given in the file `manifest.txt'.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{backref}
  [2012/07/25 v1.38 Bibliographical back referencing]%
\RequirePackage{kvoptions}[2011/06/30]
\RequirePackage{kvsetkeys}[2009/07/30]
\RequirePackage{ltxcmds}[2009/12/12]
\SetupKeyvalOptions{%
  family=backref,%
  prefix=BR@,%
}
\newcommand*{\backrefsetup}{\kvsetkeys{backref}}
\DeclareBoolOption[%
  \ltx@ifundefined{ifHy@verbose}{%
    false%
  }{%
    \ifx\ifHy@verbose\iftrue true\else false\fi
  }%
]{verbose}
\long\def\page@backref#1#2#3{#1}
\long\def\section@backref#1#2#3{#2}
\long\def\hyper@section@backref#1#2#3{\hyperlink{#3}{#2}}
\long\def\hyper@page@backref#1#2#3{\hyperlink{page.#1}{#1}}
\DeclareVoidOption{pageref}{%
  \def\backref{\backrefpagesname\ }%
  \let\backrefxxx\page@backref
}
\DeclareVoidOption{ref}{%
  \def\backref{\backrefsectionsname\ }%
  \let\backrefxxx\section@backref
}
\DeclareVoidOption{hyperref}{%
  \def\backref{}\let\backrefxxx\hyper@section@backref
}
\DeclareVoidOption{hyperpageref}{%
  \def\backref{}\let\backrefxxx\hyper@page@backref
}
\DeclareBoolOption[true]{enable}
\DeclareComplementaryOption{disable}{enable}
\def\backrefenglish{%
  \def\backrefpagesname{pages}%
  \def\backrefsectionsname{sections}%
  \def\backrefsep{, }%
  \def\backreftwosep{ and~}%
  \def\backreflastsep{, and~}%
}
\def\backrefgerman{%
  \def\backrefpagesname{Seiten}%
  \def\backrefsectionsname{Abschnitte}%
  \def\backrefsep{, }%
  \def\backreftwosep{ und~}%
  \def\backreflastsep{ und~}%
}
\def\backreffrench{%
  \def\backrefpagesname{pages}%
  \def\backrefsectionsname{sections}%
  \def\backrefsep{, }%
  \def\backreftwosep{ et~}%
  \def\backreflastsep{ et~}%
}
\def\backrefspanish{%
  \def\backrefpagesname{p\'aginas}%
  \def\backrefsectionsname{secciones}%
  \def\backrefsep{, }%
  \def\backreftwosep{ y~}%
  \def\backreflastsep{ y~}%
}
\def\backrefbrazil{%
  \def\backrefpagesname{p\'aginas}%
  \def\backrefsectionsname{se\c c\~oes}%
  \def\backrefsep{, }%
  \def\backreftwosep{ e~}%
  \def\backreflastsep{ e~}%
}
\def\backrefafrikaans{%
  \def\backrefpagesname{bladsye}%
  \def\backrefsectionsname{afdelings}%
  \def\backrefsep{, }%
  \def\backreftwosep{ en~}%
  \def\backreflastsep{ en~}%
}%
\def\BR@addto#1#2{%
  #2%
  \@temptokena{#2}%
  \ifx#1\relax
    \let#1\@empty
  \fi
  \ifx#1\@undefined
     \edef#1{\the\@temptokena}%
  \else
     \toks@\expandafter{#1}%
     \edef#1{\the\toks@\the\@temptokena}%
  \fi
  \@temptokena{}\toks@\@temptokena
}
\def\BR@DeclareLang#1#2{%
  \begingroup
    \edef\x##1##2{%
      \noexpand\ifx##2\relax
        \errmessage{No definitions for language `#2' found!}%
      \noexpand\fi
      \endgroup
      \noexpand\DeclareVoidOption{#1}{%
        \noexpand\BR@addto{\noexpand##1}{\noexpand##2}%
      }%
    }%
  \expandafter\x\csname extras#1\expandafter\endcsname
                \csname backref#2\expandafter\endcsname
}
\BR@DeclareLang{english}{english}
\BR@DeclareLang{american}{english}
\BR@DeclareLang{australian}{english}
\BR@DeclareLang{british}{english}
\BR@DeclareLang{canadian}{english}
\BR@DeclareLang{newzealand}{english}
\BR@DeclareLang{UKenglish}{english}
\BR@DeclareLang{USenglish}{english}
\BR@DeclareLang{german}{german}
\BR@DeclareLang{ngerman}{german}
\BR@DeclareLang{austrian}{german}
\BR@DeclareLang{naustrian}{german}
\BR@DeclareLang{french}{french}
\BR@DeclareLang{acadian}{french}
\BR@DeclareLang{canadien}{french}
\BR@DeclareLang{frenchb}{french}
\BR@DeclareLang{francais}{french}
\BR@DeclareLang{spanish}{spanish}
\BR@DeclareLang{brazil}{brazil}
\BR@DeclareLang{brazilian}{brazil}
\BR@DeclareLang{afrikaans}{afrikaans}
\backrefenglish
\backrefsetup{pageref}
\ProcessKeyvalOptions*
\def\BR@DisableOption#1{%
  \DisableKeyvalOption[%
    action=warning,%
    package=backref,%
  ]{backref}{#1}%
}
\BR@DisableOption{ref}
\BR@DisableOption{pageref}
\BR@DisableOption{hyperref}
\BR@DisableOption{hyperpageref}
\newif\ifbackrefparscan
\backrefparscantrue
\newif\ifBR@BackrefAlt
\def\BR@bibitem{%
  \ifbackrefparscan
    \expandafter\@ifnextchar\expandafter[\expandafter
    \BR@@lbibitem\expandafter\BR@@bibitem
  \else
    \expandafter\@ifnextchar\expandafter[\expandafter
    \BR@@@lbibitem\expandafter\BR@@@bibitem
  \fi
}
\def\BR@@lbibitem[#1]#2#3\par{%
  \let\backrefprint\BR@backrefprint
  \BRorg@bibitem[{#1}]{#2}#3%
  \BR@backref{#2}%
}%
\def\BR@@bibitem#1#2\par{%
  \let\backrefprint\BR@backrefprint
  \BRorg@bibitem{#1}#2%
  \BR@backref{#1}%
}
\def\BR@@@lbibitem[#1]#2{%
  \def\backrefprint{\BR@backref{#2}}%
  \BRorg@bibitem[{#1}]{#2}%
}
\def\BR@@@bibitem#1{%
  \def\backrefprint{\BR@backref{#1}}%
  \BRorg@bibitem{#1}%
}
\def\BR@backrefprint{%
    \PackageError{backref}{%
      \string\backrefprint\space is only available after \string\bibitem
      \MessageBreak
      with setting \string\backrefparscanfalse
    }\@ehc
}
\let\backrefprint\BR@backrefprint
\def\BR@backref#1{%
  \newblock
  \begingroup
    \csname @safe@activestrue\endcsname
    \expandafter\providecommand\csname brc@#1\endcsname{0}%
    \expandafter\providecommand\csname brcd@#1\endcsname{0}%
    \csname @safe@activesfalse\expandafter\endcsname
    \ifBR@BackrefAlt
      \ifx\backrefentrycount\BR@BackrefEntryCountUnused
      \else
        \BR@PopulateEntryCount{#1}%
      \fi
      \expandafter\backrefalt\csname brc@#1\expandafter\endcsname
                           \csname brl@#1\expandafter\endcsname
                           \csname brcd@#1\expandafter\endcsname
                           \csname brld@#1\endcsname
    \else
      \expandafter\backref\csname br@#1\expandafter\endcsname
    \fi
  \endgroup
  \par
}
\@ifundefined{newblock}{\def\newblock{\par}}{}
\let\BR@Unused\@empty
\def\BR@BackrefAltUnused#1#2#3#4{\BR@Unused}
\@ifundefined{backrefalt}{%
  \let\backrefalt\BR@BackrefAltUnused
}{}
\def\BR@BackrefEntryCountUnused#1#2{\BR@Unused#1}
\@ifundefined{backrefentrycount}{%
  \let\backrefentrycount\BR@BackrefEntryCountUnused
}{}
\def\backcite#1#2{%
  \@for\x:=#1\do{%
    \begingroup
      \csname @safe@activestrue\endcsname
      \edef\x{\endgroup
        \def\noexpand\x{\expandafter\@firstofone\x\@empty}%
      }%
    \x
    \expandafter\ifx\csname br@\x\endcsname\relax
      \expandafter\protected@xdef\csname br@\x\endcsname{%
        \protect\backrefxxx#2%
      }%
      \ifBR@BackrefAlt
        \global\expandafter\let\csname brl@\x\expandafter\endcsname
                        \csname br@\x\endcsname
        \global\expandafter\let\csname brld@\x\expandafter\endcsname
                        \csname br@\x\endcsname
        \expandafter\gdef\csname brc@\x\endcsname{1}%
        \expandafter\gdef\csname brcd@\x\endcsname{1}%
      \fi
    \else
      \begingroup
        \@ifundefined{backrefxxxdupe}{}{\let\backrefxxx\backrefxxxdupe}%
        \expandafter\def\expandafter\reserved@a\expandafter{%
          \backrefxxx#2%
        }%
        \let\BRorg@backrefxxx\backrefxxx
        \global\let\BR@found=N%
        \long\def\backrefxxx##1##2##3{%
          \expandafter\def\expandafter\reserved@b\expandafter{%
            \BRorg@backrefxxx{##1}{##2}{##3}%
          }%
          \ifx\reserved@a\reserved@b
            \global\let\BR@found=Y%
          \fi
        }%
        \setbox\@tempboxa\hbox{\csname br@\x\endcsname}%
      \endgroup
      \let\backrefsep\relax
      \def\backreftwosep{\backrefsep}%
      \def\backreflastsep{\backrefsep}%
      \if N\BR@found
        \expandafter\protected@xdef\csname br@\x\endcsname{%
          \csname br@\x\endcsname, %
          \protect\backrefxxx#2%
        }%
        \ifBR@BackrefAlt
          \expandafter\protected@xdef\csname brl@\x\endcsname{%
            \csname brl@\x\endcsname
            \ifnum\@nameuse{brc@\x}=1 %
              \noexpand\backreftwosep
            \else
              \noexpand\backreflastsep
            \fi
            \protect\backrefxxx#2%
          }%
          \count@=\@nameuse{brc@\x}\relax
          \advance\count@ by 1 %
          \expandafter\xdef\csname brc@\x\endcsname{\the\count@}%
        \fi
      \fi
      \ifBR@BackrefAlt
        \expandafter\protected@xdef\csname brld@\x\endcsname{%
          \csname brld@\x\endcsname
          \ifnum\@nameuse{brcd@\x}=1 %
            \noexpand\backreftwosep
          \else
            \noexpand\backreflastsep
          \fi
          \protect\backrefxxx#2%
        }%
        \count@=\@nameuse{brcd@\x}\relax
        \advance\count@ by 1 %
        \expandafter\xdef\csname brcd@\x\endcsname{\the\count@}%
      \fi
    \fi
  }%
}
\def\BR@PopulateEntryCount#1{%
  \begingroup
    \toks@{}%
    \def\backrefsep{%
      \toks@\expandafter{\the\toks@\backrefsep}%
    }%
    \def\backreftwosep{%
      \toks@\expandafter{\the\toks@\backreftwosep}%
    }%
    \def\backreflastsep{%
      \toks@\expandafter{\the\toks@\backreflastsep}%
    }%
    \def\protect{}%
    \let\BR@backrefxxx\backrefxxx
    \let\backrefxxx\BR@PopulateBackrefxxx
    \def\BR@name{#1}%
    \csname brl@#1\endcsname
    \expandafter\xdef\csname brl@#1\endcsname{\the\toks@}%
  \endgroup
}
\def\BR@PopulateBackrefxxx#1#2#3{%
  \expandafter\def\expandafter\BR@tempa\expandafter{%
    \BR@backrefxxx{#1}{#2}{#3}%
  }%
  \begingroup
    \count@=\z@
    \def\backrefsep{}%
    \def\backreftwosep{}%
    \def\backreflastsep{}%
    \let\backrefxxx\BR@@PopulateBackrefxxx
    \csname brld@\BR@name\endcsname
    \toks\tw@={\backrefxxx{#1}{#2}{#3}}%
    \edef\x{\endgroup
      \toks@{%
        \the\toks@
        \noexpand\backrefentrycount{%
          \the\toks\tw@
        }{\the\count@}%
      }%
    }%
  \x
}
\def\BR@@PopulateBackrefxxx#1#2#3{%
  \expandafter\def\expandafter\BR@tempb\expandafter{%
    \BR@backrefxxx{#1}{#2}{#3}%
  }%
  \ifx\BR@tempa\BR@tempb
    \advance\count@\@ne
  \fi
}
\def\@currentHref{}
\AtBeginDocument{%
  \let\BRorg@bibitem\bibitem
  \let\bibitem\BR@bibitem
  \let\BRorg@thebibliography\thebibliography
  \def\thebibliography{%
    \BR@starttoc
    \BRorg@thebibliography
  }%
  \@ifundefined{NAT@parse}{%
    \global\let\BRorg@citex\@citex
    \global\let\@citex\BR@citex
  }{%
    \@ifpackageloaded{hyperref}{}{%
      \def\hyper@natlinkstart#1{\Hy@backout{#1}}%
    }%
    \PackageInfo{backref}{** backref set up for natbib **}%
  }%
}
\def\BR@starttoc{%
  \ifx\backrefalt\BR@BackrefAltUnused
    \global\BR@BackrefAltfalse
  \else
    \global\BR@BackrefAlttrue
  \fi
  \begingroup
    \makeatletter
    \@input{\jobname.brf}%
    \if@filesw
      \@ifundefined{tf@brf}{%
        \expandafter\newwrite\csname tf@brf\endcsname
      }{}%
      \@ifundefined{tf@brf@open}{%
        \BR@RerunFileCheck
        \immediate\openout\csname tf@brf\endcsname\jobname.brf\relax
        \gdef\tf@brf@open{}%
      }{}%
    \fi
    \@nobreakfalse
  \endgroup
}
\def\BR@citex[#1]#2{%
  \BRorg@citex[{#1}]{#2}%
  \Hy@backout{#2}%
}
\@ifpackageloaded{chicago}{%
  \let\BRorg@citedatax\@citedatax
  \def\@citedatax[#1]#2{%
    \BRorg@citedatax[{#1}]{#2}%
    \Hy@backout{#2}%
  }%
}{}
\def\Hy@backout#1{%
  \@bsphack
  \ifBR@enable
    \ifBR@verbose
      \PackageInfo{backref}{Back cite \string`#1\string'}%
    \fi
    \ifx\@empty\@currentlabel
      \protected@write\@auxout{}{%
        \string\@writefile{brf}{%
          \string\backcite{#1}{{\thepage}{(document)}{Doc-Start}}%
        }%
      }%
    \else
     \protected@write\@auxout{}{%
       \string\@writefile{brf}{%
         \string\backcite{#1}{{\thepage}{\@currentlabel}{\@currentHref}}%
       }%
     }%
    \fi
  \else
    \ifBR@verbose
      \PackageInfo{backref}{Disabled back cite \string`#1\string'}%
    \fi
  \fi
  \@esphack
}
\RequirePackage{rerunfilecheck}[2009/12/10]
\def\BR@RerunFileCheck{%
  \RerunFileCheck{\jobname.brf}{%
    \@ifundefined{tf@brf@open}{%
    }{%
      \immediate\closeout\tf@brf
    }%
  }{%
    Rerun to get bibliographical references right%
  }%
}
\endinput
%%
%% End of file `backref.sty'.
