% \iffalse
% $Id: multibibliography.dtx,v 1.10 2013-05-30 02:22:26 boris Exp $
%
%% Copyright 2013, Michael Cohen <mcohen@u-aizu.ac.jp>
%% and Yannis Haralambous, <yannis.haralambous@telecom-bretagne.eu>
%% 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 the license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2003/06/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Michael Cohen
%%
%% This work consists of the file multibibliography.dtx, the
%% derived file multibibliography.sty, and the files
%% chronological.bst and multibibliography.pl
%%
%<*gobble> 
% \fi
% \CheckSum{193}
%
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~} 
%
%\iffalse
%    \begin{macrocode}
\documentclass{ltxdoc}
\usepackage[breaklinks,colorlinks,linkcolor=black,citecolor=black,
            pagecolor=black,urlcolor=black]{hyperref}
\usepackage{multibibliography}
\PageIndex
\CodelineIndex
\RecordChanges
\EnableCrossrefs
\begin{document}
  \DocInput{multibibliography.dtx}
\end{document}
%    \end{macrocode}
%</gobble> 
% \fi
% \MakeShortVerb{|}
% \GetFileInfo{multibibliography.sty}
% 
% \changes{v1.03}{2013/05/29}{Rewrote multibibliography.pl: no more
% temp files} 
% 
% \title{The Multibibliography Package\thanks{\copyright 2013 Michael
% Cohen and Yannis Haralambous}} 
% \author{Michael Cohen\thanks{mcohen@u-aizu.ac.jp} \and 
%   Yannis Haralambous\thanks{yannis.haralambous@telecom-bretagne.eu}
%   \and Boris Veytsman \thanks{borisv@lk.net}}
% \date{\filedate, \fileversion}
% \maketitle
%
% \begin{abstract}
%   Conventional standards for bibliography styles entail a forced
%   choice between index and name/year citations and corresponding
%   references.  We reject this false dichotomy, and describe a
%   multibibliography, comprising alphabetic, sequenced, and even
%   chronological orderings of references.  An extended inline
%   citation format is also proposed to integrate such heterogeneous
%   styles, and is usable and useful even without separate
%   bibliographies.
% \end{abstract}
% \changes{v1.02}{2013/03/26}{Fixed the bug in multibibliography.pl
% that prevented correct handling of accents} 
%
% \tableofcontents
%
% \clearpage
%
%\section{Introduction}
%\label{sec:intro}
%
%  This package illustrates our novel system for a multibibliography, which
%  combines alphabetic, sequenced, and chronological ordering of
%  references.  The rationale for the system is provided in the
%  enclosed TUG paper.  This package provides the code for the
%  system.  
%
%\section{User Interface}
%\label{sec:interface}
%
% The installation of the class follows the usual
% practice~\cite{TeXFAQ} for \LaTeX{} packages:
% \begin{enumerate}
% \item Run \textsf{latex} on |multibibliography.ins|.  This will produce the file
% |multibibliography.sty|.
% \item Put the file |multibibliography.sty| to
% the place where \LaTeX{} can find it (see
% \cite{TeXFAQ} or the documentation for your \TeX{}
% system).\label{item:install}
% \item Put the file |chronological.bst| to the place where Bib\TeX\
% can find it (see
% \cite{TeXFAQ} or the documentation for your \TeX{}
% system).
% \item Put the file |multibibliography.pl| into the place where
% binaries are stored on your system.
% \item Update the database of file names.  Again, see \cite{TeXFAQ}
% or the documentation for your \TeX{} system for the system-specific
% details.\label{item:update}
% \item The files |multibibliography.pdf| and |tug-paper.pdf| provide
%   the documentation for the package
% \end{enumerate}
% As an alternative to items~\ref{item:install} and~\ref{item:update}
% you can just put the files in the working directory where your
% |.tex| file is.
% 
% 
%
% To use this package, add to the preamble of your document
% the line |\usepackage{multibibliography}|.  After |latex|'ing the
% file, instead of running
% \begin{verbatim}
% bibtex FILE
% \end{verbatim}
% run
% \begin{verbatim}
% multibibliography.pl FILE.tex
% \end{verbatim}
% Then proceed in the usual way (run |latex| until the labels converge).
% 
% \DescribeMacro{\bibliographysequence}
% \DescribeMacro{\bibliographytimeline}
% The file defines two new commands:
% \cmd{\bibliographysequence}\marg{bib-files} and
% \cmd{\bibliographytimeline}\marg{bib-files} which are similar to the
% standard |\bibliography| command, but produce the reference lists
% ordered according to the sequence of citations or chronologically.
% They use |unsrt.bst| and |chronological.bst| styles
% correspondingly.  An example of usage can be found in the file
% |tug-paper.tex|:
% \begin{verbatim}
% \renewcommand\refname{References sorted by name}
% \bibliographystyle{apalike}
% \bibliography{multibibliography}
%
% \renewcommand\refname{References sorted by appearance}
% \bibliographysequence{multibibliography}
%
% \renewcommand\refname{References sorted by year}
% \bibliographytimeline{multibibliography}
%
% \end{verbatim}
% 
%
%\StopEventually{\clearpage
% \bibliography{multibibliography}
% \bibliographystyle{unsrt}}
%
% \clearpage
% 
% \section{Implementation}
% \label{sec:implementation}
% 
%
%\subsection{Declarations}
%\label{sec:decl}
% 
%  We start with declaration, who we are:
%
%
%    \begin{macrocode}
%<style>\NeedsTeXFormat{LaTeX2e}
%<*gobble>
\ProvidesFile{multibibliography.dtx}
%</gobble>
%<style>\ProvidesPackage{multibibliography}
%<*style>
[2013/05/29 v1.03 Multibibliography support for LaTeX]
%    \end{macrocode}
%
%
%
%\subsection{Hyperref Patching}
%\label{sec:hyperref}
%
% \begin{macro}{\NAT@parse}
% \changes{v1.01}{2013/02/28}{Introduced the command} 
%   Hyperref redefines a lot of bibliography related commands.
%   Fortunately, there is a mechanism in hyperref to prevent this: if
%   hyperref sees natbib, it defers to it.  Well, we can dupe hyperref
%   into thinking natbib is loaded:
%    \begin{macrocode}
\providecommand\NAT@parse[1]{}
%    \end{macrocode}   
% \end{macro}
% 
% \begin{macro}{\@extra@binfo}
% \changes{v1.01}{2013/02/28}{Introduced the command} 
%   This is a hook defined by natbib.  We preserve it just in case:
%    \begin{macrocode}
\providecommand*\@extra@binfo{}
%    \end{macrocode}
%   
% \end{macro}
%
% \begin{macro}{\@extra@b@citeb}
% \changes{v1.01}{2013/02/28}{Introduced the command} 
%   Another natbib hook:
%    \begin{macrocode}
\providecommand*\@extra@b@citeb{}
%    \end{macrocode}
%   
% \end{macro}
%
% \begin{macro}{\@BIBLABEL}
% \changes{v1.01}{2013/02/28}{Introduced the command} 
%   This is a hyperref hook
%    \begin{macrocode}
\providecommand*{\@BIBLABEL}{\@biblabel}
%    \end{macrocode}
%   
% \end{macro}
%
%
%   In case hyperref is not loaded, we provide some noops
%    \begin{macrocode}
\AtBeginDocument{
  \ifx\hyper@@link\@undefined
  \providecommand\@skiphyperreftrue{}%
  \providecommand\@skiphyperreffalse{}%
  \let\H@item\item
  \providecommand\Hy@raisedlink[1]{#1}%
  \let\hyper@anchorstart\@gobble
  \providecommand\hyper@@link[4][]{#4}%
  \providecommand{\hyper@anchorend}{}%
  \providecommand{\@currentHref}{}%
  \fi}
%    \end{macrocode}
%   
%
%\subsection{Checking for backref}
%\label{sec:backref}
%
% \begin{macro}{\if@BR@tocstarted}
% \changes{v1.02}{2013/03/26}{Added macro} 
%   Backref rewrites |.brf| file with each iteration.  So we need to
%   make sure we call |\BR@starttoc| no more than once
%    \begin{macrocode}
\newif\if@BR@tocstarted
\@BR@tocstartedfalse
%    \end{macrocode}
%   
% \end{macro}
%
%
% \begin{macro}{\if@backref@loaded}
% \changes{v1.02}{2013/03/26}{Added macro} 
%   We need to check whether backref is loaded:
%    \begin{macrocode}
\newif\if@backref@loaded
\AtBeginDocument{%
  \@ifpackageloaded{backref}{\@backref@loadedtrue    
    \let\BR@starttoc@orig\BR@starttoc
    \def\BR@starttoc{\if@BR@tocstarted\else
      \BR@starttoc@orig\@BR@tocstartedtrue\fi}
}{\@backref@loadedfalse}}
%    \end{macrocode}
%   
% \end{macro}
%
%\subsection{Creating Bibliography Labels}
%\label{sec:MBbibcite}
%
% \begin{macro}{\MBbibcite}
% \changes{v1.01}{2013/02/28}{Introduced the command} 
% \changes{v1.02}{2013/03/26}{Added backref code} 
%   The standard |\bibcite| command has two arguments:  the label and
%   the typeset represenation.  Our command has four arguments:
%   sequence number, name, date, label.  We also write |\backcite| to
%   the aux file if backref is called.
%    \begin{macrocode}
\def\MBbibcite#1#2#3#4{%
  \@newl@bel{b}{#1\@extra@binfo}{%
    \hyper@@link[cite]{}{cite.#1\@extra@b@citeb}{#3},
    \hyper@@link[cite]{}{cite.#1\@extra@b@citeb-timeline}{#4}:
    \hyper@@link[cite]{}{cite.#1\@extra@b@citeb-sequence}{#2}%    
    \if@filesw
    \if@backref@loaded\phantomsection
    \immediate\write\@mainaux{%
      \string\backcite{#1}{{\thepage}{\@currentlabel}{\@currentHref}}}\fi\fi
  }%
}%
%    \end{macrocode}
%   
% \end{macro}
%
%\subsection{Bibliography Commands}
%\label{sec:default}
%
% The default command is defined for references sorted by
% name---it is invoked by |\bibliography|.
%
% \begin{macro}{\@lbibitem}
% \changes{v1.01}{2013/02/28}{Redefined} 
% \changes{v1.02}{2013/03/26}{Added interlinks} 
%   By default |\@lbibitem| typesets the optional argument, creates a
%   hyperanchor and writes a command into the aux file.  The following
%   uses hyperref code:
%    \begin{macrocode}
  \def\@lbibitem[#1]#2{%
    \gdef\MB@sequence{}%
    \gdef\MB@name{}%
    \gdef\MB@name{}%
    \def\MBlabel##1##2##3{##2, 
      \hyper@@link[cite]{}{cite.#2\@extra@b@citeb-timeline}{##3}: 
      \hyper@@link[cite]{}{cite.#2\@extra@b@citeb-sequence}{##1}%
      \gdef\MB@sequence{##1}%
      \gdef\MB@name{##2}%
      \gdef\MB@date{##3}%
    }%
    \@skiphyperreftrue
    \H@item[%
      \ifx\Hy@raisedlink\@empty
        \hyper@anchorstart{cite.#2\@extra@b@citeb}%
          \@BIBLABEL{#1}%
        \hyper@anchorend
      \else
        \Hy@raisedlink{%
          \hyper@anchorstart{cite.#2\@extra@b@citeb}\hyper@anchorend
        }%
        \@BIBLABEL{#1}%
      \fi
      \hfill
    ]%
    \@skiphyperreffalse
    \if@filesw
      \begingroup
        \let\protect\noexpand
        \immediate\write\@auxout{%
          \string\MBbibcite{#2}{\MB@sequence}{\MB@name}{\MB@date}%
        }%
      \endgroup
    \fi
    \ignorespaces
  }
%    \end{macrocode}
%   
% \end{macro}
%
%
%
% \begin{macro}{\bibliographysequence}
% \changes{v1.01}{2013/02/28}{Added hyperref-compatible code} 
% \changes{v1.02}{2013/03/26}{Added interlinks} 
%   When we order by sequence, we do not write anything to the aux
%   file
%    \begin{macrocode}
\def\bibliographysequence#1{%
  \def\@lbibitem[##1]##2{%
    \def\MBlabel####1####2####3{####1: 
      \hyper@@link[cite]{}{cite.##2\@extra@b@citeb}{####2}, 
      \hyper@@link[cite]{}{cite.##2\@extra@b@citeb-timeline}{####3}}%
    \@skiphyperreftrue
    \H@item[%
      \ifx\Hy@raisedlink\@empty
        \hyper@anchorstart{cite.##2\@extra@b@citeb-sequence}%
          \@BIBLABEL{##1}%
        \hyper@anchorend
      \else
        \Hy@raisedlink{%
          \hyper@anchorstart{cite.##2\@extra@b@citeb-sequence}\hyper@anchorend
        }%
        \@BIBLABEL{##1}%
      \fi
      \hfill
    ]%
    \@skiphyperreffalse
    \ignorespaces
  }
  \@input@{\jobname-sequence.bbl}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\bibliographytimeline}
% \changes{v1.01}{2013/02/28}{Added hyperref-compatible code} 
% \changes{v1.02}{2013/03/26}{Added interlinks} 
%   This is the ordering by timeline:
%    \begin{macrocode}
\def\bibliographytimeline#1{%
  \def\@lbibitem[##1]##2{%
    \def\MBlabel####1####2####3{%
      \hyper@@link[cite]{}{cite.##2\@extra@b@citeb}{####2}, 
      ####3:       
      \hyper@@link[cite]{}{cite.##2\@extra@b@citeb-sequence}{####1}}%
    \@skiphyperreftrue
    \H@item[%
      \ifx\Hy@raisedlink\@empty
        \hyper@anchorstart{cite.##2\@extra@b@citeb-timeline}%
          \@BIBLABEL{##1}%
        \hyper@anchorend
      \else
        \Hy@raisedlink{%
          \hyper@anchorstart{cite.##2\@extra@b@citeb-timeline}\hyper@anchorend
        }%
        \@BIBLABEL{##1}%
      \fi
      \hfill
    ]%
    \@skiphyperreffalse
    \ignorespaces
  }
  \@input@{\jobname-timeline.bbl}}
%    \end{macrocode}
%   
% \end{macro}
%
%\subsection{Ending the Style}
%\label{sec:end}
%
%
%
%    \begin{macrocode}
%</style>
%    \end{macrocode}
%\Finale
%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
%
\endinput
