summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Master/texmf-dist/doc/latex/notes2bib/notes2bib.pdfbin204506 -> 234483 bytes
-rw-r--r--Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx2055
-rw-r--r--Master/texmf-dist/tex/latex/notes2bib/jawltxdoc.sty55
-rw-r--r--Master/texmf-dist/tex/latex/notes2bib/notes2bib.sty751
4 files changed, 1605 insertions, 1256 deletions
diff --git a/Master/texmf-dist/doc/latex/notes2bib/notes2bib.pdf b/Master/texmf-dist/doc/latex/notes2bib/notes2bib.pdf
index a3598219ac2..d99ab79d7c6 100644
--- a/Master/texmf-dist/doc/latex/notes2bib/notes2bib.pdf
+++ b/Master/texmf-dist/doc/latex/notes2bib/notes2bib.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx b/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx
index ca9e07bf674..185fa2f19ce 100644
--- a/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx
+++ b/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx
@@ -1,17 +1,17 @@
-% \iffalse meta-comment
+%\iffalse meta-comment
%
-% Copyright (C) 2007 by
+% Copyright (C) 2007-2008 by
% Joseph Wright <joseph.wright@morningstar2.co.uk>
%
% 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 1.3c 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 2003/12/01 or later.
+% and version 1.3c or later is part of all distributions of
+% LaTeX version 2005/12/01 or later.
%
-% This work has the LPPL maintenance status ``maintained.''
+% This work has the LPPL maintenance status `maintained'.
%
% The current maintainer of this work is Joseph Wright.
%
@@ -108,7 +108,7 @@
%</driver>
%\fi
%
-%\CheckSum{509}
+%\CheckSum{766}
%
%\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
@@ -138,43 +138,44 @@
%\changes{v1.2}{2007/10/26}{Altered implementation of \texttt{head}
% and \texttt{tail} options to allow moving of superscript
% citations}
-%
-%\DoNotIndex{\@fileswfalse,\@ifnextchar,\@ifpackageloaded}
-%\DoNotIndex{\@ifundefined,\@nameuse,\AtBeginDocument,\AtEndDocument}
-%\DoNotIndex{\begingroup,\bib@gadd,\bibliography,\blx@bibfiles,\cite}
-%\DoNotIndex{\closeout,\csname,\DeclareOption,\def,\edef,\else}
-%\DoNotIndex{\endcsname,\expandafter,\fi,\footnote,\footnotemark}
-%\DoNotIndex{\footnotetext,\gdef,\global,\if@filesw,\ifnum,\ifx}
-%\DoNotIndex{\immediate,\jobname,\let,\long,\MessageBreak}
+%\changes{v1.3}{2008/01/08}{Added \pkg{xkeyval} option interface}
+%\changes{v1.3}{2008/01/08}{All options now work anywhere in input}
+%\changes{v1.3}{2008/01/08}{Fixed serious errors with \opt{sort=head}
+% and \opt{sort=tail} implementation}
+%
+%\DoNotIndex{\@auxout,\@empty,\@fileswfalse,\@for,\@ifnextchar}
+%\DoNotIndex{\@ifpackageloaded,\@ifundefined,\@nameuse}
+%\DoNotIndex{\AtBeginDocument,\AtEndDocument,\AtEndPreamble}
+%\DoNotIndex{\AtNextCite,\begingroup,\closeout,\DeclareRobustCommand}
+%\DoNotIndex{\def,\define@boolkey,\define@choicekey,\define@cmdkeys}
+%\DoNotIndex{\do,\edef,\else,\endgroup,\endinput,\expandafter,\fi}
+%\DoNotIndex{\g@addto@macro,\gappto,\gdef,\if@filesw,\iffalse,\ifnum}
+%\DoNotIndex{\ifx,\immediate,\jobname,\let,\long,\MessageBreak}
%\DoNotIndex{\NeedsTeXFormat,\newcommand,\newcounter,\newif}
-%\DoNotIndex{\newrobustcmd,\newwrite,\nocite,\openout,\PackageError}
+%\DoNotIndex{\newwrite,\nocite,\noexpand,\openout,\PackageError}
%\DoNotIndex{\PackageInfo,\PackageWarning,\patchcmd}
-%\DoNotIndex{\printbibliography,\ProcessOptions,\protect}
-%\DoNotIndex{\ProvidesPackage,\relax,\renewcommand,\RequirePackage}
-%\DoNotIndex{\space,\stepcounter,\string,\thanks,\the,\theendnotes}
-%\DoNotIndex{\unexpanded,\value,\write,\xdef,\z@,\endinput,\endnote}
-%\DoNotIndex{\endnotemark,\endnotetext}
-%
-%
-%\DoNotIndex{\NeedsTeXFormat}
+%\DoNotIndex{\printbibliography,\ProcessOptionsX,\ProvidesPackage}
+%\DoNotIndex{\relax,\renewcommand,\RequirePackage,\setkeys,\space}
+%\DoNotIndex{\stepcounter,\string,\the,\typeout,\unexpanded,\value}
+%\DoNotIndex{\write,\xdef,\z@}
%
-%\title{\texttt{notes2bib} --- Integrating notes into the
-% bibliography%
+%\title{\currpkg\ --- Integrating notes into the
+% bibliography^^A
% \thanks{This file describes version \fileversion, last revised
% \filedate.}}
-%\author{Joseph Wright%
+%\author{Joseph Wright^^A
% \thanks{E-mail: joseph.wright@morningstar2.co.uk}}
%\date{Released \filedate}
%
%\maketitle
%
%\begin{abstract}
-% The |notes2bib| package defines a new type of note, |bibnote|,
+% The \currpkg package defines a new type of note, \cs{bibnote},
% which will always be added to the bibliography. The package allows
% footnotes and endnotes to be moved into the bibliography in the
-% same way. The package can be used with |natbib| and |biblatex| as
-% well as plain LaTeX citations. Both sorted and unsorted
-% bibliography styles are supported.
+% same way. The package can be used with \pkg{natbib} and
+% \pkg{biblatex} as well as plain \LaTeX\ citations. Both sorted and
+% unsorted bibliography styles are supported.
%\end{abstract}
%
%\begin{multicols}{2}
@@ -186,263 +187,238 @@
% separate entities. However, in some parts of the physical sciences
% (chemistry and physics) it is usual for references to the
% literature and notes to be given together in a ``References and
-% Notes'' section. By default, this requires that BibTeX users
+% Notes'' section. By default, this requires that \BibTeX\ users
% create a notes database for each document that they write.
%
-% The |endnotes| package allows the user to create endnotes rather
-% than footnotes. However, this does not place the notes in the
-% bibliography. The \textsc{aps} have developed the REVTeX document
-% class, which allows footnotes and endnotes to be added to the
-% bibliography. Notes can only be placed at the end of the
+%\newcommand*{\APS}{\textsc{aps}\xspace}
+%\newcommand*{\REVTeX}{REV\TeX\xspace}
+% The \pkg{endnotes} package allows the user to create endnotes
+% rather than footnotes. However, this does not place the notes in
+% the bibliography. The \APS have developed the \REVTeX
+% document class, which allows footnotes and endnotes to be added to
+% the bibliography. Notes can only be placed at the end of the
% bibliography using this system. Furthermore, the code to achieve
-% this effect is not available as a package separate from REVTeX.
+% this effect is not available as a package separate from \REVTeX.
%
-% The aim of the |notes2bib| package is to make integration of notes
-% into the bibliography easy. Notes can be written as normal in the
-% LaTeX source, and are automatically moved to the bibliography. The
-% package is compatible with sorted and unsorted bibliography styles.
-% The package has been designed for use with numerical citations,
-% although it will work with other systems.
+% The aim of the \currpkg package is to make integration of notes
+% into the bibliography easy. Notes can be written as normal in the
+% \LaTeX\ source, and are automatically moved to the bibliography.
+% The package is compatible with sorted and unsorted bibliography
+% styles. The package has been designed for use with numerical
+% citations, although it will work with other systems.
%
%\section{Basic use}
%\DescribeMacro{\bibnote}
% In the most basic form, the package can be used simply by loading
% it in the preamble as normal. This adds a new type of note to the
-% existing \cmd{\footnote} type: \cmd{\bibnote}. This can be used in
-% exactly the same way as a footnote, taking one mandatory argument
-% \marg{text}. The \meta{text} will be made available as to the
-% bibliography as a note (henceforth referred to as a bibnote).
+% existing \cs{footnote} type: \cs{bibnote}\marg{text}. This can be
+% used in exactly the same way as a footnote, taking one mandatory
+% argument \meta{text}. The \meta{text} will be made available as to
+% the bibliography as a note (henceforth referred to as a bibnote).
%\begin{LaTeXexample}
-% A very simple example of a bibliography note
-% \bibnote{Note for the first example}.
+% A very simple example of a bibliography note
+% \bibnote{Note for the first example}.
%\end{LaTeXexample}
-% By default, each bibnote is given an automatically-generated label
-% (see Section \ref{custom} for details of modifying the automatic
-% system). However, \cmd{\bibnote} accepts an optional argument
-% \oarg{label}, which can be used to over-ride this. This is
-% particularly useful when a note will be referenced several times
-% (The use of the \cmd{\citenote} command is covered in
+% By default, each bibnote is given an automatically-generated label.
+% However, \cs{bibnote} accepts an optional argument \meta{label},
+% which can be used to over-ride this. This is particularly useful
+% when a note will be referenced several times (The use of the
+% \cs{citenote} command is covered in
% Section~\ref{subsec:cross-ref}).
%\begin{LaTeXexample}
-% An example of a named note
-% \bibnote[labelled-note]{Note for the second example}.
-% The text can then continue and reference the
-% note again later \citenote{labelled-note}.
+% An example of a named note \bibnote[labelled-note]{Note for the
+% second example}. The text can then continue and reference the note
+% again later \citenote{labelled-note}.
%\end{LaTeXexample}
%
%\DescribeMacro{\bibnotemark}
%\DescribeMacro{\bibnotetext}
-% In common with \cmd{\footnote}, the basic \cmd{\bibnote} macro has
-% companion macros \cmd{\bibnotemark} and \cmd{\bibnotetext}. The
-% text provided for each not is not ``fragile,'' and so it should not
-% be necessary to use \cmd{\bibnotemark} directly. It is needed when
+% In common with \cs{footnote}, the basic \cs{bibnote} macro has
+% companion macros \cs{bibnotemark} and \cs{bibnotetext}. The text
+% provided for each not is not ``fragile,'' and so it should not be
+% necessary to use \cs{bibnotemark} directly. It is needed when
% replacing footnotes by bibnotes. Notice that there \emph{are}
% places where bibnotes will be problematic, for example in section
% headings which also appear in the Table of Contents. In these
-% contexts, use \cmd{\citenote} to reference the note, or use an
-% optional argument to the \cmd{\section}, \emph{etc.}
+% contexts, use \cs{citenote} to reference the note, or use an
+% optional argument to the \cs{section}, \etc
%\begin{LaTeXexample}
-% It is hard to write a good example for this \bibnotemark!
-% The text continues here \bibnotetext{Note for the
-% third example}.
+% It is hard to write a good example for this \bibnotemark! The text
+% continues here\bibnotetext{Note for the third example}.
%\end{LaTeXexample}
%
-%\subsection{Package options}
-% The |notes2bib| package currently accepts a number of options. The
-% |footnotes| option turns standard LaTeX footnotes into
-% bibnotes.\footnote{The \cs{thanks} macro used in making titles uses
-% the footnote mechanism. This is unaffected by loading
-% \texttt{notes2bib} even with the \texttt{footnote} option.} Thus,
-% with the |footnotes| option enables, footnotes appear in the
-% bibliography with no further user input. The \cmd{\footnotemark}
-% and \cmd{\footnotetext} macros are supported, and are aliased to
-% \cmd{\bibnotemark} and \cmd{\bibnotetext}, respectively.
-%
-% The |endnotes| option works in the same way as the |footnotes| one,
-% but in this case \cmd{\endnote} text is added to the bibliography.
-% The \cmd{\endnote} command is defined by the |endnotes| package,
-% but it is not necessary to load the |endnotes| package for this
-% function to work in |notes2bib|.
+%\subsection{Package control}
+%\DescribeMacro{\niibsetup}
+% The \currpkg package can be controlled using package options, and
+% also dynamically using the \cs{niibsetup} macro. In both cases the
+% same list of \pkg{keyval} options are recognised, in a similar
+% manner to the \pkg{graphicx} or \pkg{hyperref} packages. Several
+% of the package options are aimed at controlling the package
+% internally, but by providing a single macro to control this, use is
+% made easier.\footnote{Users upgrading from earlier versions of
+% \currpkg will note that the large number of control macros have all
+% been removed from v1.3.}
+%
+% Almost all of the package options take literal text; those which do
+% not are true/false switches.
+%\begin{itemize}
+% \item \opt{cite}: The csname of the macro used to cite bibnotes;
+% by default ``cite''.
+% \item \opt{endnotes}: Whether to convert endnotes into bibnotes;
+% takes a Boolean value.
+% \item \opt{field}: The \BibTeX\ database field name for notes.
+% \item \opt{footnotes}: Whether to convert footnotes into bibnotes;
+% takes a Boolean value, and does not affect the \cs{thanks}
+% macro.
+% \item \opt{keyhead}, \opt{keynone}, \opt{keytail}: Sorted \BibTeX\
+% styles can use the \texttt{key} field to sort citations; by
+% setting a prefix to the bibnote name, extra control over sorting
+% can be obtained.
+% \item \opt{log}: The amount of detail to add to the log; expects a
+% value from the list \opt{debug} (very detailed information),
+% \opt{verbose} (the same as \opt{debug}), \opt{normal},
+% \opt{errors} (errors only), \opt{none}.
+% \item \opt{name}: The name given to bibnote citations; by default,
+% this is followed by an automatically-generated number.
+% \item \opt{prefix}: The file-name prefix used for the \BibTeX\
+% database holding the notes.
+% \item \opt{presorthead}, \opt{presortnone}, \opt{presorttail}: For
+% \pkg{biblatex} users, the presort field can be used to control
+% sorting of the bibliography; these keys control the value used
+% depending on the setting of the \opt{sort} key.
+% \item \opt{record}: The name of the \BibTeX\ record type used to
+% store notes.
+% \item \opt{sort}: Controls the placement of notes relative to real
+% citations in the bibliography; expected a value \opt{none} (no
+% control of sorting, intended for unsorted bibliographies and
+% interspersed citations and notes), \opt{head} (notes appear
+% before real citations) and \opt{tail} (notes appear after real
+% citations).
+%\end{itemize}
+% The default options are:
+%\begin{LaTeXexample}[\typesetcodeonly]
+% \niibsetup{%
+% cite=cite,
+% endnotes=false,
+% field=note,
+% footnotes=false,
+% keyhead=aaa,
+% keynone={},
+% keytail=zzz,
+% log=normal,
+% name=Bibnote,
+% prefix=niib-,
+% presorthead=ml,
+% presortnone=mm,
+% presorttail=mn,
+% record=Misc,
+% sort=none}
+%\end{LaTeXexample}
%
-% The |head| and |tail| options affect the placement of notes
-% relative to ``real'' citations. By default, all bibliographic
-% citations are written in the order they appear in the source. Thus,
-% with an unsorted bibliography style, they will appear in the order
-% given. The |tail| option will force all notes to appear after real
-% citations, whereas the |head| option causes notes to come
-% first.\footnote{The \texttt{head} option is provided primarily for
-% consistency with the \texttt{tail} option. The system used to give
-% ``head'' notes is something of a hack, and is \emph{not} a core
-% part of the package.} This has been designed to work with both
-% sorted and unsorted bibliography styles.
+% The \opt{sort} option requires some comment. By default, \currpkg
+% places notes where cited into the \ext{aux} file, which means that
+% the order of citations and notes depends on the \ext{bst} file in
+% use. With an unsorted style, citations and notes will be mixed in
+% the order they appear in the \LaTeX\ source. The \opt{sort=head}
+% option will cause \currpkg to place notes before real citations.
+% This should work with sorted and unsorted \ext{bst} files, but
+% requires two \LaTeX\ runs \emph{before} a \BibTeX\ run in order to
+% work. The package warns if extra runs are needed. The
+% \opt{sort=tail} option places notes after citations; here, only one
+% \LaTeX\ run is needed.
+%
+% The options \opt{head} and \opt{tail} are provided as shortcuts for
+% \opt{sort=head} and \opt{sort=tail}, respectively. The \opt{debug}
+% option is a shortcut for \opt{log=debug}. As the \opt{endnotes}
+% and \opt{footnotes} options take Boolean values, giving the option
+% name alone is the same as giving \opt{\meta{option}=true}.
%
%\subsection{Output of notes}
% Bibnotes are only printed when a bibliography is created. This
-% means that at the very least a \cmd{\bibliographystyle} command
-% must appear in the source. Under most circumstances, the user will
-% be citing literature, and so will also include a
-% \cmd{\bibliography} command in their source. Bibliography notes are
-% automatically added to the citations to be printed.
+% means that at the very least a \cs{bibliographystyle} command must
+% appear in the source.\footnote{For \pkg{biblatex} users, the
+% package must be loaded!} Under most circumstances, the user will
+% be citing literature, and so will also include a \cs{bibliography}
+% command in their source. Bibliography notes are automatically added
+% to the citations to be printed.
%
%\DescribeMacro{\printbibnotes}
% If bibnotes are being used without any other citations, then the
-% user cannot place \cmd{\bibliography} in the source.\footnote{LaTeX
+% user cannot place \cs{bibliography} in the source.\footnote{\LaTeX\
% will complain if the user puts \cs{bibliography\{\}}.} The package
-% therefore provides the macro \cmd{\printbibnotes}, which will
-% output only the notes. If the |endnotes| package has been loaded,
-% the \cmd{\theendnotes} macro is redefined to achieve the same
-% effect.
+% therefore provides the macro \cs{printbibnotes}, which will output
+% only the notes. If the \pkg{endnotes} package has been loaded, the
+% \cs{theendnotes} macro is redefined to achieve the same effect.
%
%\subsection{Cross-referencing notes\label{subsec:cross-ref}}
%\DescribeMacro{\citenote}
% As explained above, each note is automatically assigned a label, or
% the user can provide one as an optional argument to the note. In
% either case, notes may then be cross-referenced. Notes are
-% available to be cited directly using the \cmd{\cite} command.
-% However, this can cause problems when using the |tail| option. The
-% \cmd{\citenote} command is therefore provided. This is aware of
-% the options, and will act correctly in all circumstances.
+% available to be cited directly using the \cs{cite} command.
+% However, this can cause problems when using the \opt{sort=tail}
+% option. The \cs{citenote} command is therefore provided. This is
+% aware of the options, and will act correctly in all circumstances.
%\begin{LaTeXexample}
-% Cross-references to the note labelled earlier
-% using \cite{labelled-note} and using
-% \citenote{labelled-note}.
+% Cross-references to the note labelled earlier
+% using \cite{labelled-note} and using
+% \citenote{labelled-note}.
%\end{LaTeXexample}
%
%\subsection{Interaction with other packages}
-% |notes2bib| is designed to work well with as many other packages as
+% \currpkg is designed to work well with as many other packages as
% possible. It tries to avoid changing anything which other packages
-% may rely on. That said, it is best to load |notes2bib|
-% \emph{after} other packages that affect citations, footnotes or
-% endnotes. As usual, the |notes2bib| package should be loaded
-% before |hyperref|.\footnote{It is usually the case that
-% \texttt{hyperref} should be the very last package loaded in the
-% preamble.}
-%
-% The |notes2bib| package is compatible with the current release of
-% |biblatex| (v0.6). As |biblatex| works very differently from other
-% citation systems, it must be loaded \emph{before} |notes2bib|.
-% This allows the package to adjust correctly for some important
-% differences in operation of the bibliography environment.
-%
-%\section{Customisation\label{custom}}
-% The |notes2bib| package provides a number of possibilities for
-% customisation. Some of these will be useful only in somewhat
-% unusual circumstances. These more low-level macros all begin
-% \cs{niib\dots}.
-%
-%\DescribeMacro{\bibnotename}
-%\DescribeMacro{\thebibnote}
-% Each note created by |notes2bib| is automatically given a label,
-% unless one has been specified by user as an optional argument. By
-% default, this is the text of \cmd{\bibnotename} (normally
-% \bibnotename), followed by the note number (counted automatically).
-% By redefining \cmd{\bibnotename} all notes can be given a new
-% label, still bearing the note number. More complex effects can
-% be achieved by altering \cmd{\thebibnote}. This is defined as
-% |\bibnotename\the\value{bibnote}| by default.
-%
-%\DescribeMacro{\niibcite}
-% The macro used to cite notes is set in \cmd{\niibcite}. By default
-% this is \cmd{\cite}, but can be altered, for example
-% |\renewcommand{\niibcite}{\citep}| if using |natbib|.
-%
-%\DescribeMacro{\niibprefix}
-% The temporary BibTeX database used to store the notes has the
-% default name |niib-\jobname.bib|. The prefix (``\niibprefix'') can
-% be altered by redefining \cmd{\niibprefix}.
-%
-%\DescribeMacro{\niibrecord}
-%\DescribeMacro{\niibfield}
-% When the notes database is written, each record is saved as type
-% \texttt{\niibrecord}, and the text is stored in a
-% \texttt{\niibfield} field. Both of these can be altered by
-% redefining \cmd{\niibrecord} and \cmd{\niibfield}. This could be
-% useful with a bibliography style that has an explicit ``Notes''
-% record type, for example.\footnote{The \texttt{rsc} and
-% \texttt{achemso} packages contain styles of this type.}
-%
-% |notes2bib| attempts to maintain the correct ordering of notes with
-% sorted bibliography styles. This is done by setting up suitable
-% information in the temporary database to ensure correct sorting.
-% The mechanism for this is available for modification.
-%
-%\DescribeMacro{\niibkeyhead}
-%\DescribeMacro{\niibkeynone}
-%\DescribeMacro{\niibkeytail}
-% For users of standard bibliography styles, this is achieved by
-% generating a |key| field in the database, containing the label used
-% for the note. When using the |head| or |tail| option, this is
-% prefixed by \texttt{\niibkeyhead} or \texttt{\niibkeytail},
-% respectively. The prefix can be altered by redefining
-% \cmd{\niibkeyhead} or \cmd{\niibkeytail}, for example when
-% numerical labels need to be taken into account. The package also
-% provides a \cmd{\niibkeynone} macro, which defaults to an empty
-% prefix.
-%
-%\DescribeMacro{\niibpresorthead}
-%\DescribeMacro{\niibpresortnone}
-%\DescribeMacro{\niibpresorttail}
-% When using |biblatex|, the |presort| field can be used to control
-% sorting of the citations. Again, three macros
-% \cmd{\niibpresorthead}, \cmd{\niibpresortnone} and
-% \cmd{\niibpresorttail} are provided, which are used in the correct
-% context. The default values of \texttt{\niibpresorthead},
-% \texttt{\niibpresortnone} and \texttt{\niibpresorttail},
-% respectively, are designed to achieve the desired effect while
-% allowing the user full control of sorting.
+% may rely on. That said, it is best to load \currpkg \emph{after}
+% other packages that affect citations, footnotes or endnotes. As
+% usual, the \currpkg package should be loaded before
+% \pkg{hyperref}.\footnote{It is usually the case that \pkg{hyperref}
+% should be the very last package loaded in the preamble.}
+%
+% The \currpkg package is compatible with the current release of
+% \pkg{biblatex} (v0.7). As \pkg{biblatex} works very differently
+% from other citation systems, it must be loaded \emph{before}
+% \currpkg. This allows the package to adjust correctly for some
+% important differences in operation of the bibliography environment.
+% Older versions of \pkg{biblatex} \emph{will not work}.
%
%\section{Special effects}
-%
-%\DescribeMacro{\flushcitestack}
-% When using the |head| or |tail| options, citations are added to a
-% stack as they are made. This stack is then flushed to the |.aux|
-% file at the end of the document. If references are given by
-% chapter (or other unit), this may not give the desired effect. The
-% \cmd{\flushcitestack} macro will cause all saved citations to be
+%\DescribeMacro{\flushnotestack}
+% When using the \opt{sort=tail} option, citations are added to a
+% stack as they are made. This stack is then flushed to the
+% \ext{aux} file at the end of the document. If references are given
+% by chapter (or other unit), this may not give the desired effect.
+% The \cs{flushnotestack} macro will cause all saved citations to be
% written at that point, and will reset the stack for continued use.
-% This can therefore be used to control when citation occurs.
-%
-%\DescribeMacro{\delaycite}
-% When using the |head| option, normal citations have to be saved to
-% the stack described above. This requires the modification of the
-% citation commands. By default, |notes2bib| modifies the
-% \cmd{\cite} command and most of the standard citation commands of
-% |natbib| and |biblatex|.\footnote{Notice that \bslash
-% \texttt{nocite} is not modified} However, if problems are
-% encountered with citation order, the user can use the
-% \cmd{\delaycite} macro to patch any arbitrary citation command.
-% This macro takes a single argument \marg{macro-name}, which is the
-% name of the citation command to modify \emph{minus} the leading
-% backslash. For example, the \cmd{\cite} command is patched using
-% |\delaycite{cite}|. The \cmd{\delaycite} macro checks that a
-% citation command is not already modified, and so may be used again
-% on the same command with no ill effects.
+% This can therefore be used to control when citation
+% occurs.\footnote{This macro was called \cs{flushcitestack} prior to
+% v1.3.}
%
+%\DescribeMacro{\thebibnote}
% If a sorted bibliography style is in use, and more than nine notes
% are created, the sort order will be incorrect. This is because by
-% default |notes2bib| does not pad the automatically-created labels
-% with zeros. To get the correct sort order, \cmd{\thebibnote}
-% should be redefined:
+% default \currpkg does not pad the automatically-created labels with
+% zeros. To get the correct sort order, \cs{thebibnote} should be
+% redefined.
%\begin{LaTeXexample}[\typesetcodeonly]
-% \renewcommand*{\thebibnote}{%
-% \bibnotename%
-% \ifnum\value{bibnote} < 9 0\fi%
-% \the\value{bibnote}%
-% }
+% \makeatletter
+% \renewcommand*{\thebibnote}{%
+% \niib@name%
+% \ifnum\value{bibnote} < 9 0\fi%
+% \the\value{bibnote}}
+% \makeatother
%\end{LaTeXexample}
%
%\section{Known issues}
-%
-% From v1.1, the method for writing notes to the BibTeX database has
+% From v1.1, the method for writing notes to the \BibTeX\ database has
% been modified. This means that bibnotes cannot contain verbatim
% text.\footnote{Actually, they can, but the spacing will go wrong.
-% LaTeX will only complain if a note ends with verbatim text.
+% \LaTeX\ will only complain if a note ends with verbatim text.
% However, verbatim text is not supported in bibnotes: don't do it!}
% This is the same as for normal footnotes, and so the usual
% work-arounds are applicable.
%\begin{LaTeXexample}
-% The next note contains some awkward text
-% \bibnote{Some \texttt{\textbackslash verb}-like output}.
+% The next note contains some awkward text
+% \bibnote{Some \texttt{\textbackslash verb}-like output}.
%\end{LaTeXexample}
%
%\bibliographystyle{unsrt}
@@ -454,66 +430,71 @@
% involved. Rather than expect interested users to read all of the
% code that follows, a condensed overview is given here. The
% thinking behind the system used is explained first, by considering
-% the |endnotes| package and REVTeX class. Both of these provided
-% inspiration for this package.
+% the \pkg{endnotes} package and \REVTeX class. Both of these
+% provided inspiration for this package.
%
%\subsection{The \texttt{endnotes} approach}
-% The |endnotes| package\footnote{%
+% The \pkg{endnotes} package\footnote{%
% \url{http://tug.ctan.org/macros/latex/contrib/misc/endnotes.sty}}
% allows the user to generate endnotes in the same way as footnotes.
-% In |endnotes|, the text of the note is written to a |.ent| file.
-% This is achieved in an unexpanded form using the \cmd{\meaning} TeX
-% primitive. To produce the list of endnotes, this file is read back
-% into LaTeX, with the extra information \cmd{\meaning} also writes
-% being stripped off in the process.
+% In \pkg{endnotes}, the text of the note is written to a \ext{ent}
+% file. This is achieved in an unexpanded form using the \cs{meaning}
+% \TeX\ primitive. To produce the list of endnotes, this file is
+% read back into \LaTeX, with the extra information \cs{meaning} also
+% writes being stripped off in the process.
%
% This method is relativity simple in concept, but obviously does
-% not integrate with BibTeX. The use of \cmd{\meaning} for unexpanded
+% not integrate with \BibTeX. The use of \cs{meaning} for unexpanded
% output also means that information requires further processing before
% it can be included in the bibliography.
%
-%\subsection{The REVTeX approach}
-% REVTeX takes a similar approach to creating endnotes, but also
+%\subsection{The \REVTeX approach}
+% \REVTeX takes a similar approach to creating endnotes, but also
% allows footnotes to be converted into endnotes. This results in a
% file containing all of the non-literature citations in a document
-% in a single external file (in this case a |.end| file). REVTeX
+% in a single external file (in this case a \ext{end} file). \REVTeX
% also uses a different method to achieve unexpanded output, meaning
% that several macros are not ``active'' in notes.
%
-% The second part of the REVTeX approach is to (optionally) read the
+% The second part of the \REVTeX approach is to (optionally) read the
% notes back into the document. This is achieved by modifying the
-% \cmd{\bibliography} environment to output each note in the
-% bibliography. This takes place \emph{en masse}, after the normal
+% \cs{bibliography} environment to output each note in the
+% bibliography. This takes place \latin{en masse}, after the normal
% citations.
%
-% REVTeX makes a number of modifications to LaTeX, and is dependent
-% on using |natbib|. The method used is also not compatible with
+% \REVTeX makes a number of modifications to \LaTeX, and is dependent
+% on using \pkg{natbib}. The method used is also not compatible with
% interspersing normal citations and notes.
%
%\subsection{The \texttt{notes2bib} approach}
%
-% In |notes2bib|, notes are again written to an external file.
-% However, in contrast to the methods those outlined above,
-% |notes2bib| writes its output in the well-known BibTeX database
-% format. All of the note text is written almost completely
-% unexpanded to the file, the only requirement being that the braces
-% match within the argument.\footnote{Writing to the file uses the
-% e-TeX \cs{unexpanded} primitive.}
-%
-% Each note results in a citation being placed by |notes2bib| in the
-% |.aux| file. The \cmd{\bibliography} command is also modified so
-% that the new database will be used by BibTeX. After the BibTeX run,
-% the note text will appear in the |.bbl| file, in the same way as
-% any other citation. Using an unsorted BibTeX style, this results
-% in notes interspaced with the normal citations. For sorted styles,
-% |notes2bib| allows various methods for controlling the placement of
-% notes, based on writing appropriate fields in the BibTeX database.
-%
-% The |head| and |tail| options use an additional technique. Both
-% delay writing of selected citations (either notes or real ones)
-% into the |.aux| file, to control citation position in unsorted
-% bibliographies. The delay is brought about by altering the
-% definition of |\if@filesw|, so that it is dependent on the context.
+% In \currpkg, notes are again written to an external file. However,
+% in contrast to the methods those outlined above, \currpkg writes
+% its output in the well-known \BibTeX\ database format. All of the
+% note text is written almost completely unexpanded to the file, the
+% only requirement being that the braces match within the
+% argument.\footnote{Writing to the file uses the \eTeX\
+% \cs{unexpanded} primitive.}
+%
+% Each note results in a citation being placed by \currpkg in the
+% \ext{aux} file. The \cs{bibliography} command is also modified so
+% that the new database will be used by \BibTeX. After the \BibTeX\
+% run, the note text will appear in the \ext{bbl} file, in the same
+% way as any other citation. Using an unsorted \BibTeX\ style, this
+% results in notes interspaced with the normal citations. For sorted
+% styles, \currpkg allows various methods for controlling the
+% placement of notes, based on writing appropriate fields in the
+% \BibTeX\ database.
+%
+%\DescribeMacro{niibheadcite}
+% The \opt{sort=head} option works by adding an additional macro to
+% the \ext{aux} file: \cs{niibheadcite}. On the next \LaTeX\ run,
+% this causes the relevant notes to be cited right at the beginning
+% of the document, before any real citations.\footnote{Thanks to
+% Michael Shell for the idea for this method.} For \opt{sort=tail},
+% the value of \cs{if@filesw} is temporarily altered to prevent
+% writing of a citation to the \ext{aux} file. The citation is added
+% to a stack, and is written at the end of the document.
%
%\iffalse
%<*package>
@@ -521,440 +502,641 @@
%\section{The package code}
%
%\subsection{Package setup code}
-%
% The package starts with the usual identification code.
-%\changes{v1.1}{2007/09/29}{Removed use of \texttt{xspace}}
+%\changes{v1.1}{2007/09/29}{Removed use of \pkg{xspace}}
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{notes2bib}
- [2007/10/31 v1.2a Integrating notes into the bibliography]
+ [2008/01/08 v1.3 Integrating notes into the bibliography]
% \end{macrocode}
-% The package requires e-TeX, so before going any further, this is
-% tested. This code is taken more-or-less verbatim from |biblatex|.
-%\changes{v1.1}{2007/09/29}{Require e-TeX extensions}
+% The package requires \eTeX, so before going any further, this is
+% tested. This code is taken more-or-less verbatim from
+% \pkg{biblatex}.
+%\changes{v1.1}{2007/09/29}{Require \eTeX extensions}
% \begin{macrocode}
-\@ifundefined{eTeXversion}
- {\PackageError{notes2bib}
- {Not running under e-TeX}
- {This package requires e-TeX. Try compiling the document
- with\MessageBreak `elatex' instead of `latex'. When using
- pdfTeX, try `pdfelatex'\MessageBreak instead of `pdflatex'}%
- \endinput}
- {}
+\begingroup
+ \@ifundefined{eTeXversion}
+ {\PackageError{notes2bib}
+ {Not running under e-TeX}
+ {This package requires e-TeX. Try compiling the document
+ with\MessageBreak `elatex' instead of `latex'. When using
+ pdfTeX, try `pdfelatex'\MessageBreak instead of `pdflatex'}
+ \endgroup\endinput}
+ {\endgroup}
% \end{macrocode}
-%\changes{v1.2}{2007/10/26}{Name change of support package from
-% \texttt{elatex} to \texttt{etoolbox}}
-% With that check out of the way, Philip Lehmann's |etoolbox| package
-% is loaded to extend various LaTeX commands.
+% The necessary support packages are loaded.
% \begin{macrocode}
-\RequirePackage{etoolbox}
+\RequirePackage{xkeyval,etoolbox}
% \end{macrocode}
-%
-% Option processing takes place. Redefining \cmd{\footnote} or
-% \cmd{\endnote} is delayed until the start of the document, to avoid
-% the danger of other packages being loaded and overwriting this.
-% \begin{macrocode}
-\newif\ifniib@fn\niib@fnfalse
-\DeclareOption{footnotes}{%
- \niib@fntrue
- \AtBeginDocument{%
- \let\footnote\bibnote%
- \PackageInfo{notes2bib}%
- {Converting footnotes to bibnotes}%
-}}
-\DeclareOption{endnotes}{%
- \AtBeginDocument{%
- \let\endnote\bibnote%
- \let\endnotemark\bibnotemark%
- \let\endnotetext\bibnotetext%
-% \end{macrocode}
-% If the user has used the |endnotes| package, they may still have
-% \cmd{\theendnotes} commands in their source. So this is defined to
-% print out all of the bibnotes.
-% \begin{macrocode}
- \@ifpackageloaded{endnotes}%
- {\let\theendnotes\printbibnotes}{}%
- \PackageInfo{notes2bib}%
- {Converting endnotes to bibnotes}%
-}}
-% \end{macrocode}
-% Stephen Dalton suggested an option for all notes to come after
-% ``real'' citations. This is done here, along with a mirror options
-% to have all for the citations come first.
-% \begin{macrocode}
-\newif\ifniib@tail\niib@tailfalse
-\newif\ifniib@head\niib@headfalse
-\DeclareOption{tail}{\niib@tailtrue}
-\DeclareOption{head}{\niib@headtrue}
-% \end{macrocode}
-% Finally, the options are put into effect.
-% \begin{macrocode}
-\ProcessOptions\relax
+%\begin{macro}{\niib@tempa}
+%\changes{v1.3}{2008/01/08}{New macro}
+%\begin{macro}{\niib@tempb}
+%\changes{v1.3}{2008/01/08}{New macro}
+% Some private temporary macros are declared.
+% \begin{macrocode}
+\newcommand*{\niib@tempa}{}
+\newcommand*{\niib@tempb}{}
% \end{macrocode}
+%\end{macro}
+%\end{macro}
%
-%\begin{macro}{\niib@fnmark}
-%\begin{macro}{\niib@fntext}
-%\begin{macro}{\niib@thanks}
-% If the |footnote| option is active, there is some work to do
-% because of the \cmd{\thanks} macro. This is all done using the
-% |etoolbox| package. Firstly, it is necessary to back up the original
-% definitions for \cmd{\footnotetext}, \cmd{\footnotetext} and
-% \cmd{\thanks}.
-% \begin{macrocode}
-\ifniib@fn
- \let\niib@fnmark\footnotemark
- \let\niib@fntext\footnotetext
- \let\niib@thanks\thanks
+%\subsection{Logging}
+%\begin{macro}{\ifniib@debug}
+%\begin{macro}{\ifniib@logmin}
+%\begin{macro}{\ifniib@lognone}
+% To control logging, some new switches are declared.
+% \begin{macrocode}
+\newif\ifniib@debug
+\newif\ifniib@logmin
+\newif\ifniib@lognone
% \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
-%\begin{macro}{\thanks}
-% Now the \cmd{\thanks} command is patched to use the saved
-% definitions. The patching is nested so that everything has to go
-% right before things are finalised.
-% \begin{macrocode}
- \patchcmd{\thanks}{\footnotemark}{\niib@fnmark}{%
- \patchcmd{\thanks}{\footnotetext}{\niib@fntext}{%
- \AtBeginDocument{%
- \let\footnotemark\bibnotemark
- \let\footnotetext\bibnotetext
- }%
- \PackageInfo{notes2bib}%
- {Modifying \protect\thanks\space macro}%
- }{%
-% \end{macrocode}
-% If the following is executed, then things have gone wrong in some
-% way. The \cmd{\patchcmd} macro shouldn't mess up the definition of
-% \cmd{\thanks}, but to be on the safe side the original version
-% is restored here.
-% \begin{macrocode}
- \let\thanks\niib@thanks%
- \PackageWarning{notes2bib}%
- {Could not patch \protect\thanks}}%
- }{%
- \let\thanks\niib@thanks%
- \PackageWarning{notes2bib}%
- {Could not patch \protect\thanks}}%
-\fi
+%\begin{macro}{\niib@log@err}
+%\begin{macro}{\niib@log@warn}
+%\begin{macro}{\niib@log@inf}
+% Some handy re-usable macros are defined here. These all take names
+% beginning These pop up in various places. First errors, warnings
+% and information are handled. Package options are used to control
+% how much output is given.
+% \begin{macrocode}
+\newcommand*{\niib@log@err}[2]{%
+ \ifniib@lognone\else
+ \ifniib@logmin
+ \PackageWarning{notes2bib}{#1}%
+ \else
+ \PackageError{notes2bib}{#1}{#2}%
+ \fi
+ \fi}
+\newcommand*{\niib@log@warn}[1]{%
+ \ifniib@lognone\else
+ \ifniib@logmin\else
+ \PackageWarning{notes2bib}{#1}%
+ \fi
+ \fi}
+\newcommand*{\niib@log@inf}[1]{%
+ \ifniib@lognone\else
+ \ifniib@logmin\else
+ \PackageInfo{notes2bib}{#1}%
+ \fi
+ \fi}
% \end{macrocode}
%\end{macro}
+%\begin{macro}{\niib@log@debug}
+% The debug macro only gives output if the appropriate package option
+% is set.
+% \begin{macrocode}
+\newcommand*{\niib@log@debug}[1]{%
+ \ifniib@lognone\else
+ \ifniib@debug
+ \PackageInfo{notes2bib}{#1}%
+ \fi
+ \fi}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
%
-%\changes{v1.2a}{2007/10/31}{Improved messages on loading package}
-% The |head| and |tail| options are mutually exclusive, so a check is
-% made that both have not been selected. If they have, the package
-% ignores both options after a suitable warning.
+%\subsection{Package options}
+%\begin{macro}{\niib@opt@boolkey}
+% To aid maintenance, some shortcuts are defined for generating keys.
+% These also allow the debugging messages to be added automatically
+% to every key.
% \begin{macrocode}
-\ifniib@head
- \ifniib@tail
- \PackageWarning{notes2bib}
- {You've given both ``head'' and ``tail'' as
- options\MessageBreak I'm ignoring both!\MessageBreak
- bibnotes will be interspersed with other citations}
- \niib@headfalse\niib@tailfalse
- \else
- \PackageInfo{notes2bib}%
- {bibnotes will head other citations}
- \fi
-\else
- \ifniib@tail
- \PackageInfo{notes2bib}%
- {bibnotes will tail other citations}
- \else
- \PackageInfo{notes2bib}%
- {bibnotes will be interspersed with other citations}
- \fi
-\fi
+\newcommand*{\niib@opt@boolkey}[2][]{%
+ \define@boolkey[niib]{opt}[niib@]{#2}[true]
+ {#1\niib@log@debug{Option #2 set to ##1}}}
% \end{macrocode}
-% For the |head| option, the normal citation commands are modified to
-% get the necessary delay in writing to the |.aux| file.
+%\end{macro}
+%\begin{macro}{\niib@opt@choicekey}
+% A ``fill in the blanks'' choice key. In all
+% cases, \cs{niib@tempa} is used to hold the value given to the key,
+% so that \cs{ifx} testing can occur.
% \begin{macrocode}
-\AtBeginDocument{%
- \ifniib@head
-% \end{macrocode}
-% The real \cmd{\delaycite} is activated. The \cmd{\cite} command is
-% always defined, so it can be redefined in all cases.
-% \begin{macrocode}
- \let\delaycite\niib@delaycite
- \delaycite{cite}%
-% \end{macrocode}
-% If |natbib| is loaded, there a several citation commands that will
-% definitely be defined. They are all run through \cmd{\delaycite}.
-% \begin{macrocode}
- \@ifpackageloaded{natbib}{%
- \delaycite{citet}%
- \delaycite{citep}%
- \delaycite{citenum}%
- \delaycite{citealt}%
- \delaycite{citealp}%
- \delaycite{citetext}%
- \delaycite{citeauthor}%
- \delaycite{citeyear}%
- \delaycite{citeyearpar}%
- \delaycite{Citet}%
- \delaycite{Citep}%
- \delaycite{Citealt}%
- \delaycite{Citealp}%
- \delaycite{Citeauthor}%
- }{}%
-% \end{macrocode}
-% For |biblatex|, some citation commands are always defined.
-% \begin{macrocode}
- \@ifpackageloaded{biblatex}{%
- \delaycite{Cite}%
- \delaycite{parencite}%
- \delaycite{Parencite}%
- \delaycite{footcite}%
- \delaycite{Footcite}%
- \delaycite{textcite}%
- \delaycite{Textcite}%
-% \end{macrocode}
-% Now there are some citation commands that may be defined or not.
-% \begin{macrocode}
- \@ifundefined{autocite}{}%
- {\delaycite{autocite}}%
- \@ifundefined{supercite}{}%
- {\delaycite{supercite}}%
- }{}%
- \fi%
-}
+\newcommand*{\niib@opt@choicekey}[5][]{%
+ \define@choicekey*+[niib]{opt}{#2}[\niib@tempa]{#3}[#1]
+ {#4\niib@log@debug{Option #2 set to ##1}}
+ {#5\niib@log@debug{Option #2 set to ##1}}}
% \end{macrocode}
-%
-%\subsection{User configuration macros}
-%
-% The |notes2bib| package makes quite a number of configuration
-% defaults available as macros. These are all set up here. Most of
-% these are of the form \cs{niib\dots}, as in the
-% main they are unlikely to be altered by most users.
-%
-%\begin{macro}{\bibnotename}
-% By default, all of the new citations take the prefix
-% ``\bibnotename.'' The default can be altered, and this is set up
-% here.
+%\end{macro}
+%\begin{macro}{\niib@opt@cmdkeys}
+% A shortcut for \pkg{xkeyval} command keys.
% \begin{macrocode}
-\newcommand*\bibnotename{Bibnote}
+\newcommand*{\niib@opt@cmdkeys}[1]{%
+ \define@cmdkeys[niib]{opt}[niib@]{#1}}
% \end{macrocode}
%\end{macro}
-%\begin{macro}{\thebibnote}
-% A counter is needed for the notes created. In analogy to other
-% counters in LaTeX, this is given a \cs{the\dots} name. The user
-% should not really need to use this macro, but convention dictate
-% that it has a user-space name.
+%\begin{macro}{\niibsetup}
+%\changes{v1.3}{2008/01/08}{New macro}
+% To allow modification of options at run time, a setup macro is
+% provided. The run of strange tests are to prevent problems in
+% arrays and the like.
% \begin{macrocode}
-\newcounter{bibnote}
-\renewcommand*{\thebibnote}{\bibnotename\the\value{bibnote}}
+\newcommand*{\niibsetup}[1]{%
+ \iffalse{\fi\ifnum0=`}\fi
+ \setkeys[niib]{opt}{#1}%
+ \ifnum0=`{\fi\iffalse}\fi}
% \end{macrocode}
%\end{macro}
-%\begin{macro}{\niibprefix}
-% The package works by creating a new BibTeX database file containing
-% the notes. By default, this fix is called
-% \texttt{\niibprefix}\cs{jobname.bib}, but the prefix may
-% be altered by redefining \cmd{\niibprefix}. The default follows
-% the pattern used by the |biblatex| package (which uses |blx-|).
+%\begin{macro}{\niib@opt@log}
+%\begin{macro}{\niib@tempa}
+%\begin{macro}{\niib@tempb}
+% The \pkg{xkeyval} package option for logging is declared. This is
+% then processed to set the switches correctly.
+% \begin{macrocode}
+\niib@opt@choicekey[normal]{log}{debug,verbose,normal,errors,none}
+% \end{macrocode}
+% A series of comparisons are made to assign the logging mode. The
+% \opt{normal} option is not tested, as executing the option sets the
+% switches appropriately.
+% \begin{macrocode}
+ {\niib@debugfalse
+ \niib@logminfalse
+ \niib@lognonefalse
+ \renewcommand*{\niib@tempb}{none}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@lognonetrue
+ \fi
+ \renewcommand*{\niib@tempb}{minimal}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@logmintrue
+ \fi
+ \renewcommand*{\niib@tempb}{debug}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@debugtrue
+ \fi
+ \renewcommand*{\niib@tempb}{verbose}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@debugtrue
+ \fi}
+% \end{macrocode}
+% The option has not been recognised: give a warning (if
+% appropriate).
+% \begin{macrocode}
+ {\niib@log@warn{Unrecognised value `#1' for option log}}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@opt@debug}
+% A quick method to set \opt{log=debug}.
% \begin{macrocode}
-\newcommand*\niibprefix{niib-}
+\niib@opt@boolkey{debug}
% \end{macrocode}
%\end{macro}
-%
-%\begin{macro}{\niibrecord}
-%\begin{macro}{\niibfield}
-% When creating the temporary database of notes, the BibTeX records
-% created are of record type \cmd{\niibrecord}, and the notes are
-% stored in the \cmd{\niibfield} field type. For some BibTeX styles,
-% a better choice than the defaults (\texttt{\niibrecord} and
-% \texttt{\niibfield}, respectively) may be available. Thus the
-% values used are definable.
+%\begin{macro}{\niib@opt@footnotes}
+%\begin{macro}{\niib@opt@ndnotes}
+%\begin{macro}{\ifniib@footnotes}
+%\begin{macro}{\ifniib@endnotes}
+% The \opt{footnote} and \opt{endnote} options are declared here.
% \begin{macrocode}
-\newcommand*\niibrecord{Misc}
-\newcommand*\niibfield{note}
+\niib@opt@boolkey[\niib@swapfoot]{footnotes}
+\niib@opt@boolkey[\niib@swapend]{endnotes}
% \end{macrocode}
%\end{macro}
%\end{macro}
-%\begin{macro}{\niibpresorthead}
-%\begin{macro}{\niibpresortnone}
-%\begin{macro}{\niibpresorttail}
-% When using |biblatex|, sorting can be controlled using the
-% |presort| field. Default values to be used are given here; these
-% are ``soft'' as |biblatex| allows much more definite pushing to the
-% top and bottom of the sorted list.
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\ifniib@head}
+%\begin{macro}{\ifniib@tail}
+% Switches are needed for placing notes before and after normal
+% citations.
% \begin{macrocode}
-\newcommand*\niibpresorthead{ml}
-\newcommand*\niibpresortnone{mm}
-\newcommand*\niibpresorttail{mn}
+\newif\ifniib@tail
+\newif\ifniib@head
% \end{macrocode}
%\end{macro}
%\end{macro}
+%\begin{macro}{\niib@opt@sort}
+%\begin{macro}{\niib@tempa}
+%\begin{macro}{\niib@tempb}
+% This option controls the position of notes \latin{versus} normal
+% citations. The \pkg{xkeyval} option replaces the earlier \opt{head}
+% and \opt{tail} options, which are retained for backward
+% compatibility.\footnote{This may change in a future release; the
+% options \opt{head} and \opt{tail} are ``depreciated.''}
+% \begin{macrocode}
+\niib@opt@choicekey[none]{sort}{none,head,tail}
+ {\niib@headfalse
+ \niib@tailfalse
+ \renewcommand*{\niib@tempb}{head}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@headtrue
+ \fi
+ \renewcommand*{\niib@tempb}{tail}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@tailtrue
+ \fi}
+ {\niib@log@warn{Unrecognised value `#1' for option sort}}
+% \end{macrocode}
%\end{macro}
-%\begin{macro}{\niibkeyhead}
-%\begin{macro}{\niibkeynone}
-%\begin{macro}{\niibkeytail}
-% For traditional BibTeX styles, the |key| field can be used to
-% influence the sort order. Default values to alter sorting are
-% given here, but may need to be altered for other languages and so
-% on.
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@opt@head}
+%\begin{macro}{\niib@opt@tail}
+% The back-compatibility code; unlike earlier versions, this will
+% take whatever the \opt{sort}-type key is given.
% \begin{macrocode}
-\newcommand*\niibkeyhead{aaa}
-\newcommand*\niibkeynone{}
-\newcommand*\niibkeytail{zzz}
+\niib@opt@boolkey[%
+ \ifniib@head
+ \ifniib@tail
+ \niib@tailfalse
+ \niib@log@inf{Option head cancels existing\MessageBreak
+ tail or sort=tail option}
+ \fi
+ \fi]{head}
+\niib@opt@boolkey[%
+ \ifniib@tail
+ \ifniib@head
+ \niib@headfalse
+ \niib@log@inf{Option tail cancels existing\MessageBreak
+ head or sort=head option}
+ \fi
+ \fi]{tail}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@opt@cite}
+%\begin{macro}{\niib@cite}
+%\begin{macro}{\niib@opt@name}
+%\begin{macro}{\niib@name}
+%\begin{macro}{\niib@opt@prefix}
+%\begin{macro}{\niib@prefix}
+%\begin{macro}{\niib@opt@record}
+%\begin{macro}{\niib@record}
+%\begin{macro}{\niib@opt@field}
+%\begin{macro}{\niib@field}
+%\begin{macro}{\niib@opt@presorthead}
+%\begin{macro}{\niib@presorthead}
+%\begin{macro}{\niib@opt@presortnone}
+%\begin{macro}{\niib@presortnone}
+%\begin{macro}{\niib@opt@presorttail}
+%\begin{macro}{\niib@presorttail}
+%\begin{macro}{\niib@opt@keyhead}
+%\begin{macro}{\niib@keyhead}
+%\begin{macro}{\niib@opt@keynone}
+%\begin{macro}{\niib@keynone}
+%\begin{macro}{\niib@opt@keytail}
+%\begin{macro}{\niib@keytail}
+% The various internal control values are set up as command keys.
+% \begin{macrocode}
+\niib@opt@cmdkeys{%
+ cite,
+ name,
+ prefix,
+ record,
+ field,
+ presorthead,
+ presortnone,
+ presorttail,
+ keyhead,
+ keynone,
+ keytail}
+\niibsetup{%
+ cite=cite,
+ name=Bibnote,
+ prefix=niib-,
+ record=Misc,
+ field=note,
+ presorthead=ml,
+ presortnone=mm,
+ presorttail=mn,
+ keyhead=aaa,
+ keynone={},
+ keytail=zzz}
% \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
%
-%\begin{macro}{\niibcite}
-% Bibliography notes are marked by citations, like any other
-% bibliography entry. The citation command use is controlled here.
+%\subsection{Footnote and endnote handling}
+%\begin{macro}{\niib@org@footnote}
+%\begin{macro}{\niib@org@footnotemark}
+%\begin{macro}{\niib@org@footnotetext}
+%\begin{macro}{\niib@org@thanks}
+% To allow dynamic handling of footnotes and endnotes, the original
+% definitions are backed up. This is done at the start of the
+% document, so that changes from any other packages are picked up.
+% \begin{macrocode}
+\AtBeginDocument{%
+ \let\niib@org@footnote\footnote
+ \let\niib@org@footnotemark\footnotemark
+ \let\niib@org@footnotetext\footnotetext
+ \let\niib@org@thanks\thanks
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@org@endnote}
+%\begin{macro}{\niib@org@endnotemark}
+%\begin{macro}{\niib@org@endnotetext}
+%\begin{macro}{\niib@org@theendnotes}
+% If \pkg{endnotes} is loaded, then \cs{endnote} and friends have to
+% be saved.
+% \begin{macrocode}
+ \@ifpackageloaded{endnotes}
+ {\let\niib@org@endnote\endnote
+ \let\niib@org@endnotemark\endnotemark
+ \let\niib@org@endnotetext\endnotetext
+ \let\niib@org@theendnotes\theendnotes}}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@thanks}
+% The first step of converting footnotes into bibnotes is to patch
+% the \cs{thanks} macro so that it uses the original definitions of
+% \cs{footnotemark} and \cs{footnotetext}. The necessary setup is
+% also put in place for on-the-fly swapping of footnotes and
+% bibnotes.
+% \begin{macrocode}
+\AtBeginDocument{%
+ \let\niib@thanks\thanks
+ \let\niib@footnotetext\footnotetext
+ \let\niib@footnotemark\footnotemark
+ \patchcmd{\niib@thanks}{\footnotetext}{\niib@org@footnotetext}
+ {\patchcmd{\niib@thanks}{\footnotemark}
+ {\niib@org@footnotemark}
+% \end{macrocode}
+%\begin{macro}{\thanks}
+%\begin{macro}{\niib@footnotetext}
+%\begin{macro}{\niib@footnotemark}
+% If the package gets here, then both replacements have worked. The
+% updated definition of \cs{thanks} is applied (it does not depend on
+% package options), and the definitions of \cs{footnotemark} and
+% \cs{footnotetext} that are needed are set up.
+% \begin{macrocode}
+ {\let\thanks\niib@thanks
+ \let\niib@footnotetext\bibnotetext
+ \let\niib@footnotemark\bibnotemark
+ \niib@log@debug{Successfully patched \noexpand\thanks}}
+% \end{macrocode}
+% This group deals with a failure of the second patch.
+% \begin{macrocode}
+ {\niib@log@warn{Failed to patch \noexpand\thanks\MessageBreak
+ \noexpand\footnotemark\space and
+ \noexpand\footnotetext\MessageBreak are unmodified}%
+ \niib@log@debug{Could not substitute
+ \noexpand\footnotemark\MessageBreak in \noexpand\thanks}}}
+% \end{macrocode}
+% If the first patch fails, then the error shows up here.
+% \begin{macrocode}
+ {\niib@log@warn{Failed to patch \noexpand\thanks\MessageBreak
+ \noexpand\footnotemark\space and
+ \noexpand\footnotetext\MessageBreak are unmodified}%
+ \niib@log@debug{Could not substitute
+ \noexpand\footnotetext\MessageBreak in \noexpand\thanks}}}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@swapfoot}
+%\begin{macro}{\footnote}
+%\begin{macro}{\footnotemark}
+%\begin{macro}{\footnotetext}
+% The swapping code can now be implemented.
% \begin{macrocode}
-\newcommand*\niibcite{\cite}
+\newcommand*{\niib@swapfoot}{}
+\AtBeginDocument{%
+ \renewcommand*{\niib@swapfoot}{%
+ \ifniib@footnotes
+ \let\footnote\bibnote
+ \let\footnotemark\niib@footnotemark
+ \let\footnotetext\niib@footnotetext
+ \niib@log@debug{Converting footnotes to bibnotes}%
+ \else
+ \let\footnote\niib@org@footnote
+ \let\footnotemark\niib@org@footnotemark
+ \let\footnotetext\niib@org@footnotetext
+ \niib@log@debug{Using kernel definition of footnotes}%
+ \fi}
+ \niib@swapfoot}
% \end{macrocode}
%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@swapend}
+%\begin{macro}{\endnote}
+%\begin{macro}{\endnotemark}
+%\begin{macro}{\endnotetext}
+%\begin{macro}{\theendnotes}
+% For endnotes, the code needed depends on whether the \pkg{endnotes}
+% package is available or not. If it is, then swapping the two
+% definitions is set up.
+% \begin{macrocode}
+\newcommand*{\niib@swapend}{}
+\AtBeginDocument{%
+ \@ifpackageloaded{endnotes}
+ {\renewcommand*{\niib@swapend}{%
+ \ifniib@endnotes
+ \let\endnote\bibnote
+ \let\endnotemark\bibnotemark
+ \let\endnotetext\bibnotetext
+ \let\theendnotes\printbibnotes
+ \niib@log@debug{Converting endnotes to bibnotes}%
+ \else
+ \let\endnote\niib@org@endnote
+ \let\endnotemark\niib@org@endnotemark
+ \let\endnotetext\niib@org@endnotetext
+ \let\theendnotes\niib@org@theendnotes
+ \niib@log@debug{Using endnotes package to handle endnotes}%
+ \fi}
+ \niib@swapend}
+% \end{macrocode}
+% \pkg{endnotes} is not loaded; once the \opt{endnotes} option has been
+% given, there is nothing to go back. Of course, if the user does not
+% give the \opt{endnotes} option, \cs{endnote} is not defined at all.
+% \begin{macrocode}
+ {\ifniib@endnotes
+ \let\endnote\bibnote
+ \let\endnotemark\bibnotemark
+ \let\endnotetext\bibnotetext
+ \let\theendnotes\printbibnotes
+ \niib@log@debug{Converting endnotes to bibnotes}%
+ \fi
+ \renewcommand*{\niib@swapend}{%
+ \ifniib@endnotes
+ \let\endnote\bibnote
+ \let\endnotemark\bibnotemark
+ \let\endnotetext\bibnotetext
+ \let\theendnotes\printbibnotes
+ \niib@log@debug{Converting endnotes to bibnotes}%
+ \else
+ \niib@log@inf{endnotes package not loaded\MessageBreak
+ endnotes=false ignored}%
+ \fi}}}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
%
%\subsection{User macros}
-%
+%\begin{macro}{\thebibnote}
+% A counter is needed for the notes created. In analogy to other
+% counters in \LaTeX, this is given a \cs{the\dots} name. The user
+% should not really need to use this macro, but convention dictate
+% that it has a user-space name. The \LaTeX\ \cs{newcounter} macro
+% is used (rather than the \TeX\ \cs{newcount}) as the automatic
+% system expects the numbers to be globally unique.
+% \begin{macrocode}
+\newcounter{bibnote}
+\renewcommand*{\thebibnote}{\niib@name\the\value{bibnote}}
+% \end{macrocode}
+%\end{macro}
%\begin{macro}{\bibnote}
%\changes{v1.1}{2007/09/29}{Macro made robust}
% Each new bibnote increments the note counter, then checks for an
% optional label, before handing off to the internal macro
-% \cmd{\niib@bibnote}.
+% \cs{niib@bibnote}.
% \begin{macrocode}
-\newrobustcmd*{\bibnote}{%
+\DeclareRobustCommand*{\bibnote}{%
\stepcounter{bibnote}%
- \@ifnextchar[%
- {\niib@bibnote}%
- {\niib@bibnote[\thebibnote]}%
-}
+ \@ifnextchar[%]
+ {\niib@bibnote}
+ {\niib@bibnote[\thebibnote]}}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\bibnotemark}
%\changes{v1.1}{2007/09/29}{Macro made robust}
-% The \cmd{\bibnotemark} macro works in the same way as
-% \cmd{\bibnote}, but calls \cmd{\niib@mark} rather than
-% \cmd{\niib@bibnote}.
+% The \cs{bibnotemark} macro works in the same way as \cs{bibnote},
+% but calls \cs{niib@mark} rather than \cs{niib@bibnote}.
% \begin{macrocode}
-\newrobustcmd*{\bibnotemark}{%
+\DeclareRobustCommand*{\bibnotemark}{%
\stepcounter{bibnote}%
- \@ifnextchar[%
- {\niib@mark}%
- {\niib@mark[\thebibnote]}%
-}
+ \@ifnextchar[%]
+ {\niib@mark}
+ {\niib@mark[\thebibnote]}}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\bibnotetext}
%\changes{v1.1}{2007/09/29}{Macro made robust}
-%\changes{v1.1}{2007/09/29}{Use \cs{newrobustcmd} rather than
-% \cs{@ifnextchar} for detecting optional argument}
% The text companion to the mark macro above, with no increment of
-% the counter.
+% the counter. There is nothing special to do, so the \LaTeX\ kernel
+% handling of optional arguments can be used.
% \begin{macrocode}
-\newrobustcmd*{\bibnotetext}[1][\thebibnote]{%
- \niib@text{#1}%
-}
+\DeclareRobustCommand*{\bibnotetext}[1][\thebibnote]{%
+ \niib@text{#1}}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\printbibnotes}
%\changes{v1.1}{2007/09/29}{Macro made robust}
% To allow for the possibility of there being no other notes, a
-% command to print only notes is given. In the |biblatex| case, the
-% best that can be done is to issue \cmd{\printbibliography}.
+% command to print only notes is given. In the \pkg{biblatex} case,
+% the best that can be done is to issue \cs{printbibliography}.
% \begin{macrocode}
-\@ifpackageloaded{biblatex}{%
- \let\printbibnotes\printbibliography%
-}{%
- \newrobustcmd*{\printbibnotes}{\niib@bib%
- {\niibprefix\jobname}}%
-}%
+\@ifpackageloaded{biblatex}
+ {\let\printbibnotes\printbibliography}
+ {\DeclareRobustCommand*{\printbibnotes}
+ {\niib@org@bib{\niib@prefix\jobname}}}
% \end{macrocode}
%\end{macro}
-%\begin{macro}{\flushcitestack}
+%\begin{macro}{\flushnotestack}
%\changes{v1.1}{2007/09/29}{Macro made robust}
+%\changes{v1.3}{2008/01/08}{Fixed bug with empty stack}
+%\changes{v1.3}{2008/01/08}{Renamed from \cs{flushcitestack}}
% In order to delay citations to the end of the bibliography (and
% thus force others to the start), a ``stack'' is created of
-% citations which need to be written to the |.aux| file. This
+% citations which need to be written to the \ext{aux} file. This
% is done here, and the stack is cleared so collection can begin
% again.
% \begin{macrocode}
-\newrobustcmd*{\flushcitestack}{%
- \ifx\niib@stack\relax\else%
+\DeclareRobustCommand*{\flushnotestack}{%
+ \ifx\@empty\niib@stack\@empty
+ \niib@log@debug{Citation stack empty: nothing for\MessageBreak
+ \noexpand\flushnotestack to do}%
+ \else%
+ \niib@log@debug{Flushing note citations to aux file}%
\expandafter\nocite\expandafter{\niib@stack}%
- \global\let\niib@stack\relax%
- \fi%
-}
+ \gdef\niib@stack{}%
+ \fi}
% \end{macrocode}
%\end{macro}
-%
-%\begin{macro}{\delaycite}
-%\changes{v1.1}{2007/09/29}{Initial definition prevents use in
-% preamble}
-% \begin{macrocode}
-\newrobustcmd*{\delaycite}[1]{%
- \PackageWarning{notes2bib}{%
- \@nameuse{delaycite}can only be used in the document
- body\MessageBreak Not modifying citation macro \@nameuse{#1}}
-}
-% \end{macrocode}
-%\end{macro}
-%
%\begin{macro}{\citenote}
%\changes{v1.0a}{2007/09/03}{New macro}
%\changes{v1.1}{2007/09/29}{Macro made robust}
-%\changes{v1.2}{2007/10/26}{\texttt{tail} version altered to work
-% with new delaying method}
-% A ``mode aware'' command for referencing notes is needed (problems
-% arise with \cmd{\cite} and the |tail| option. Rather than overload
-% \cmd{\cite} with all of the problems that can bring, a new command
-% is provided that can be guaranteed to work.
-% \begin{macrocode}
-\ifniib@tail
- \newrobustcmd*\citenote{%
- \niib@cnfalse%
- \niibcite%
- }%
-% \end{macrocode}
-% If |tail| is not active, then \cmd{\citenote} is simply an alias
-% for the citation command used by |notes2bib|.
-% \begin{macrocode}
-\else
- \newrobustcmd*\citenote{\niibcite}%
-\fi
+%\changes{v1.3}{2008/01/08}{Now a wrapper for \cs{niib@mark}}
+% Problems arise with \cs{cite} and the \opt{sort=tail} option. Rather
+% than overload \cs{cite} with all of the problems that can bring, a
+% new command is provided that can be guaranteed to work.
+% \begin{macrocode}
+\DeclareRobustCommand*{\citenote}[1]{\niib@mark[#1]}
% \end{macrocode}
%\end{macro}
%
-%\subsection{Internal setup macros}
-%
+%\subsection{Internal macros}
%\begin{macro}{\niib@keyname}
-% If |biblatex| is in use, the key field in the BibTeX database
+%\changes{v1.3}{2008/01/08}{Moved to \cs{AtBeginDocument}}
+% If \pkg{biblatex} is in use, the key field in the \BibTeX\ database
% should be called ``keysort,'' whereas otherwise it should be
% ``key.''
% \begin{macrocode}
-\@ifpackageloaded{biblatex}
- {\def\niib@keyname{keysort}}
- {\def\niib@keyname{key}}
+\AtBeginDocument{%
+ \@ifpackageloaded{biblatex}
+ {\niib@log@debug{Using field `keysort' for sorting key}%
+ \newcommand*\niib@keyname{keysort}}
+ {\niib@log@debug{Using field `key' for sorting key}%
+ \newcommand*\niib@keyname{key}}}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\niib@presort}
+%\changes{v1.3}{2008/01/08}{Dynamic rather than static definition}
%\begin{macro}{\niib@key}
-% The values taken by \cmd{\niib@presort} and \cmd{\niib@key} depend
+%\changes{v1.3}{2008/01/08}{Dynamic rather than static definition}
+% The values taken by \cs{niib@presort} and \cs{niib@key} depend
% on the desired positioning of notes in the bibliography.
% \begin{macrocode}
-\ifniib@head
- \def\niib@presort{\niibpresorthead}
- \def\niib@key{\niibkeyhead}
-\else
- \ifniib@tail
- \def\niib@presort{\niibpresorttail}
- \def\niib@key{\niibkeytail}
+\newcommand*{\niib@presort}{%
+ \ifniib@head
+ \niib@presorthead%
\else
- \def\niib@presort{\niibpresortnone}
- \def\niib@key{\niibkeynone}
- \fi
-\fi
+ \ifniib@tail
+ \niib@presorttail%
+ \else
+ \niib@presortnone%
+ \fi
+ \fi}
+\newcommand*{\niib@key}{%
+ \ifniib@head
+ \niib@keyhead%
+ \else
+ \ifniib@tail
+ \niib@keytail%
+ \else
+ \niib@keynone%
+ \fi
+ \fi}
% \end{macrocode}
%\end{macro}
%\end{macro}
-%
%\begin{macro}{\niib@msg}
-% To inform the user, the automatically-created BibTeX database needs
-% to carry suitable information on its source.
+% To inform the user, the automatically-created \BibTeX\ database
+% needs to carry suitable information on its source.
% \begin{macrocode}
\edef\niib@msg{%
This is an auxiliary file used by the `notes2bib' package.^^J%
@@ -962,276 +1144,145 @@
required.^^J}
% \end{macrocode}
%\end{macro}
-%
%\begin{macro}{\niib@stack}
% This macro is needed to store any citations at the end of the
-% bibliography. Initially, this expands to \cmd{\relax}.
+% bibliography. Initially, this is empty.
% \begin{macrocode}
-\let\niib@stack\relax
+\newcommand*{\niib@stack}{}
% \end{macrocode}
%\end{macro}
-%
-%\subsection{Internal macros}
-%
-% To alter citation ordering, tricks have to be played with writing
-% to the |.aux| file. First some switches are needed to track what
-% is going on. |\ifniib@cn| tracks is a note is being cited,
-% |ifniib@citing| is used to check for any citation, |\ifniib@filesw|
-% is used to substitute |\if@filesw|, and |\ifniib@orig@filesw|
-% records the original value of the file switch.
-% \begin{macrocode}
-\newif\ifniib@cn\niib@cnfalse%
-\newif\ifniib@citing\niib@citingfalse%
-\newif\ifniib@filesw\niib@fileswfalse%
-\newif\ifniib@orig@filesw
-% \end{macrocode}
-% The value of the file switch is backed up.
-% \begin{macrocode}
-\if@filesw
- \niib@orig@fileswtrue%
-\else
- \niib@orig@fileswfalse%
-\fi
-% \end{macrocode}
-%\begin{macro}{\niib@head@filesw}
-%\changes{v1.2}{2007/10/26}{New macro}
-% When in |head| mode, |\if@filesw| is modified using this macro.
-% \begin{macrocode}
-\def\niib@head@filesw{%
-% \end{macrocode}
-% First, the switching commands are altered.
-% \begin{macrocode}
- \let\@fileswtrue\niib@orig@fileswtrue%
- \let\@fileswfalse\niib@orig@fileswfalse%
-% \end{macrocode}
-% The switch is now redefined. First, the current value of the
-% original switch is transferred to the switch actually in use.
-% \begin{macrocode}
- \def\if@filesw{%
- \ifniib@orig@filesw
- \niib@fileswtrue%
- \else
- \niib@fileswfalse%
- \fi
-% \end{macrocode}
-% If a citation is being made, and it is not a note, then writing to
-% the |.aux| file is turned off.
+%\begin{macro}{\niib@addtostack}
+%\changes{v1.3}{2008/01/08}{Macro renamed from \cs{niib@stackup}}
+%\begin{macro}{\niib@tempa}
+% The various optional argument tricks above all use the same core
+% code, which adds the mandatory argument of the citation to the
+% stack. The stack is global (see also \cs{flushnotestack}).
% \begin{macrocode}
- \ifniib@citing
- \ifniib@cn\else
- \niib@fileswfalse%
- \fi
- \fi
+\newcommand*{\niib@addtostack}[1]{%
+ \niib@log@debug{Adding citation #1 to stack}%
+ \edef\niib@tempa{#1}%
+ \ifx\@empty\niib@stack\@empty
+ \xdef\niib@stack{\niib@tempa}%
+ \else
+ \xdef\niib@stack{\niib@stack,\niib@tempa}%
+ \fi}
% \end{macrocode}
-% The switches are reset, then the new switch is used to give the desired
-% behaviour.
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@bibnote}
+%\changes{v1.3}{2008/01/08}{Use \cs{niib@mark} for citation}
+% Two steps are needed here, writing the text of the note to file
+% (handled by \cs{niib@text}, and marking the citation (using
+% \cs{niib@cite}).
% \begin{macrocode}
- \global\niib@cnfalse%
- \global\niib@citingfalse%
- \ifniib@filesw%
- }
-}
+\long\def\niib@bibnote[#1]#2{%
+ \niib@text{#1}{#2}%
+ \niib@mark[#1]}
% \end{macrocode}
%\end{macro}
-% If |head| mode is on, then this is all activated.
+%\begin{macro}{\niib@headlist}
+% To inform the user that a re-run of \LaTeX\ is needed, tracking is
+% needed of any ``head'' citations.
% \begin{macrocode}
-\ifniib@head
- \niib@head@filesw%
-\fi
+\newcommand*{\niib@headlist}{}
% \end{macrocode}
-%\begin{macro}{\niib@tail@filesw}
-%\changes{v1.2}{2007/10/26}{New macro}
-% When in |tail| mode, a slightly different set of modifications is needed.
+%\end{macro}
+%\begin{macro}{\niib@mark}
+%\begin{macro}{\niib@tempa}
+% Adding a citation to the \LaTeX\ file is handled here. When using
+% the \opt{sort=head} option, the citation is written to the
+% \ext{aux} file for sorting control. The normal citation command is
+% then called.
% \begin{macrocode}
-\def\niib@tail@filesw{%
- \let\@fileswtrue\niib@orig@fileswtrue%
- \let\@fileswfalse\niib@orig@fileswfalse%
- \def\if@filesw{%
- \ifniib@orig@filesw
- \niib@fileswtrue%
+\def\niib@mark[#1]{%
+ \ifniib@head
+ \edef\niib@tempa{#1}%
+ \ifx\@empty\niib@headlist\@empty
+ \xdef\niib@headlist{\niib@tempa}%
\else
- \niib@fileswfalse%
+ \xdef\niib@headlist{\niib@headlist,\niib@tempa}%
\fi
-% \end{macrocode}
-% If a note is being cited, writing to the |.aux| file is disabled.
-% \begin{macrocode}
- \ifniib@cn
- \niib@fileswfalse%
+ \if@filesw
+ \niib@log@debug{Adding citation #1 to list for next run}%
+ \immediate\write\@auxout{\string\niibheadcite{#1}}%
\fi
-% \end{macrocode}
-% The switches are reset, then the new switch is used to give the desired
-% behaviour.
-% \begin{macrocode}
- \global\niib@cnfalse%
- \ifniib@filesw%
- }
-}
+ \fi
% \end{macrocode}
%\end{macro}
-% If |head| mode is on, then this is all activated.
+% When the \opt{sort=tail} option is active, citation is handled by
+% another macro, so a switch is needed.
% \begin{macrocode}
-\ifniib@tail
- \niib@tail@filesw%
-\fi
-% \end{macrocode}
-%\begin{macro}{\niib@delaycite}
-%\changes{v1.0a}{2007/09/03}{Fixed a flaw with checking for
-% existing redefinition}
-%\changes{v1.1}{2007/09/29}{Improved logging of function}
-%\changes{v1.1}{2007/09/29}{Added a sanity check on argument}
-%\changes{v1.1}{2007/09/29}{Made internal to prevent execution
-% in preamble}
-%\changes{v1.1}{2007/09/29}{Macro made robust}
-%\changes{v1.2}{2007/10/26}{Significantly altered to use new citation
-% delaying method}
-% The citation command has to be modified when in |head| mode. This
-% is done here.
-% \begin{macrocode}
-\newrobustcmd*\niib@delaycite[1]{%
- \@ifundefined{#1}{%
- \PackageWarning{notes2bib}
- {Citation macro \@nameuse{#1}undefined\MessageBreak
- \protect\delaycite\space cannot operate on this macro}
- }{%
- \@ifundefined{niib@orig@#1}{%
-% \end{macrocode}
-% If the citation is not already modified, the original definition is
-% backed up. It is then modified to ensure the correct behaviour of
-% the file switch, and to stack up citations if needed.
-% \begin{macrocode}
- \expandafter\expandafter\expandafter\let\expandafter%
- \csname niib@orig@#1\expandafter\endcsname\csname #1\endcsname%
-% \end{macrocode}
-% To ensure that the original citation command can see the next
-% argument, a bit of complexity is needed. Two different definitions
-% are used, depending on whether an optional argument is detected.
-% \begin{macrocode}
- \expandafter\renewcommand\csname #1\endcsname{%
- \niib@citingtrue%
- \@ifnextchar[%]
- {\@nameuse{niib@optarg@#1}}
- {\@nameuse{niib@noarg@#1}}
- }
-% \end{macrocode}
-% There could be two optional arguments when using |biblatex|. So
-% a second check is used.
-% \begin{macrocode}
- \expandafter\def\csname niib@optarg@#1\endcsname[##1]{%
- \@ifnextchar[%]
- {\@nameuse{niib@twoopt@#1}[##1]}
- {\@nameuse{niib@oneopt@#1}[##1]}
- }
- \expandafter\def\csname niib@oneopt@#1\endcsname[##1]##2{%
- \niib@stackup{##2}%
- \@nameuse{niib@orig@#1}[##1]{##2}%
- }
- \expandafter\def\csname niib@twoopt@#1\endcsname[##1][##2]##3{%
- \niib@stackup{##3}%
- \@nameuse{niib@orig@#1}[##1][##2]{##3}%
- }
-% \end{macrocode}
-% For no optional arguments, life is a bit easier!
-% \begin{macrocode}
- \expandafter\def\csname niib@noarg@#1\endcsname##1{%
- \niib@stackup{##1}%
- \@nameuse{niib@orig@#1}{##1}%
- }
- }{%
- \PackageInfo{notes2bib}%
- {Already delayed \@nameuse{#1}}%
- }
- }
-}
+ \ifniib@tail
+ \expandafter\niib@tailcite%
+ \else
+ \expandafter\niib@normcite%
+ \fi
+ {#1}}
% \end{macrocode}
%\end{macro}
-%\begin{macro}{\niib@stackup}
-%\changes{v1.2}{2007/10/26}{New macro}
-% The various optional argument tricks above all use the same core
-% code, which adds the mandatory argument of the citation to the
-% stack.
+%\begin{macro}{\ifniib@filesw}
+% A switch is used to back up \cs{if@filesw}.
% \begin{macrocode}
-\def\niib@stackup#1{%
- \ifniib@cn\else
- \edef\niib@temp{#1}%
- \ifx\niib@stack\relax%
- \xdef\niib@stack{\niib@temp}%
- \else
- \xdef\niib@stack{\niib@stack,\niib@temp}%
- \fi
- \fi
-}
+\newif\ifniib@filesw
% \end{macrocode}
%\end{macro}
-%
-%\begin{macro}{\niib@bibnote}
-% Two steps are needed here, writing the text of the note to file
-% (handled by \cmd{\niib@text}, and marking the citation (using
-% \cmd{\niib@cite}).
+%\begin{macro}{\niib@tailcite}
+% When using the \opt{sort=tail} option, bibnote citation need to be
+% stored for later. With \pkg{biblatex}, the \cs{AtEndCite} macro
+% is available to provide a hook for the necessary switch. In other
+% cases, the current value of \cs{if@filesw} is then saved, before
+% turning it off and setting up the restore system.
+%\end{macro}
% \begin{macrocode}
-\long\def\niib@bibnote[#1]#2{%
- \niib@text{#1}{#2}%
- \niib@cite{#1}%
-}
+\AtBeginDocument{%
+ \@ifpackageloaded{biblatex}
+ {\newcommand{\niib@tailcite}[1]{%
+ \niib@addtostack{#1}%
+ \AtNextCite{\@fileswfalse}%
+ \niib@normcite{#1}}}
+ {\newcommand{\niib@tailcite}[1]{%
+ \niib@addtostack{#1}%
+ \let\ifniib@filesw\if@filesw
+ \@fileswfalse
+ \let\niib@auxhook\niib@restorefilesw
+ \niib@tcite{#1}}}}
+% \end{macrocode}
+%\begin{macro}{\niib@restorefilesw}
+% Restoring the switch is set up here. The reference to
+% \cs{niib@auxhook} ensures that the mechanism is turned off for the
+% next real citation.
+% \begin{macrocode}
+\newcommand*{\niib@restorefilesw}{%
+ \let\if@filesw\ifniib@filesw
+ \let\niib@auxhook\relax}
% \end{macrocode}
%\end{macro}
-%\begin{macro}{\niib@mark}
-% If only a mark is asked for, this is simply converted into a
-% citation. This cannot be done directly as the optional has to be
-% processed correctly.
+%\begin{macro}{\niib@tcite}
+% Actually carrying out the citation, and restoring the value of
+% \cs{if@filesw} depends on whether \pkg{cite} is loaded.
% \begin{macrocode}
-\def\niib@mark[#1]{\niib@cite{#1}}
+\AtBeginDocument{%
+ \@ifpackageloaded{cite}
+ {\newcommand*{\niib@tcite}[1]{\niib@normcite{#1}}}
+ {\newcommand*{\niib@tcite}[1]{%
+ \niib@normcite{#1}%
+ \niib@restorefilesw}}}
% \end{macrocode}
%\end{macro}
-%
-%\begin{macro}{\niib@cite}
-%\changes{v1.1}{2007/09/29}{Name change from \cs{niib@citenote}}
-%\changes{v1.1}{2007/09/29}{Definition made option-specific}
-%\changes{v1.2}{2007/10/26}{Moved resetting of \texttt{niib@cn} flag}
-% The internal macro used to cite notes depends on the package
-% options in force. First, for |head| mode, the modified real
-% citation commands need to know that a note is being cited. So the
-% Boolean \cmd{\niib@cn} has to be set correctly before citation.
-% \begin{macrocode}
-\ifniib@head%
- \def\niib@cite#1{%
- \niib@cntrue%
- \niibcite{#1}%
- }%
-% \end{macrocode}
-% For |tail| mode, the citation has to be added to the stack for use
-% later. The citation is then made with writing to the |.aux| file
-% disabled.
-% \begin{macrocode}
-\else%
- \ifniib@tail%
- \def\niib@cite#1{%
- \ifx\niib@stack\relax%
- \xdef\niib@stack{#1}%
- \else%
- \xdef\niib@stack{\niib@stack,#1}%
- \fi%
- \niib@cntrue%
- \niibcite{#1}%
- }%
-% \end{macrocode}
-% Without the |head| or |tail| options, none of these tricks are
-% needed, and \cmd{\niib@cite} is simply an alias for
-% \cmd{\niibcite}. That in turn may well just be an alias for
-% \cmd{\cite}!
+%\begin{macro}{\niib@normcite}
+% The normal citation command.
% \begin{macrocode}
- \else%
- \def\niib@cite#1{\niibcite{#1}}%
- \fi%
-\fi%
+\newcommand*{\niib@normcite}{\@nameuse{\niib@cite}}
% \end{macrocode}
%\end{macro}
%\begin{macro}{\niib@text}
%\changes{v1.1}{2007/09/29}{Combined \cs{niib@text}
% and \cs{niib@@text}}
%\changes{v1.1}{2007/09/29}{Improved awareness of files switch}
-% The ``business end'' of writing the notes to file.
+% The ``business end'' of writing the notes to file. This is a
+% \cs{long} macro, so no star is used for \cs{newcommand}.
% \begin{macrocode}
-\long\def\niib@text#1#2{%
+\newcommand{\niib@text}[2]{%
% \end{macrocode}
%\begin{macro}{\niib@out}
%\begin{macro}{\niib@stream}
@@ -1239,72 +1290,250 @@
% otherwise it will already be open.
% \begin{macrocode}
\@ifundefined{niib@out}{%
- \if@filesw%
+ \if@filesw
\newwrite\niib@out%
- \gdef\niib@stream{\niibprefix\jobname.bib}%
- \immediate\openout\niib@out\niib@stream\relax%
+ \gdef\niib@stream{\niib@prefix\jobname.bib}%
+ \niib@log@debug{Creating BibTeX database file \MessageBreak
+ \niib@stream\space to contain bibnotes}%
+ \immediate\openout\niib@out\niib@stream\relax
% \end{macrocode}
% The new file starts with the message that it has been automatically
-% generated by |notes2bib|.
+% generated by \currpkg.
% \begin{macrocode}
\immediate\write\niib@out{\niib@msg}%
- \fi}%
- {}%
+ \fi}{}%
% \end{macrocode}
%\end{macro}
%\end{macro}
-% The new record is now written to file. The \cmd{\unexpanded} e-TeX
+% The new record is now written to file. The \cs{unexpanded} \eTeX\
% primitive is used to avoid expansion of macros in the note text.
% The only issue with this is the addition of spaces after command
% names; this is the reason verbatim text cannot be used in bibnotes.
% \begin{macrocode}
- \if@filesw%
+ \if@filesw
+ \niib@log@debug{Writing bibnote #1 contents
+ \MessageBreak---\MessageBreak#2\MessageBreak---\MessageBreak
+ to BibTeX database}%
\immediate\write\niib@out{%
- @\niibrecord\string{#1,^^J%
- presort = \string{\niib@presort\string},^^J%
- \niib@keyname\space= \string{\niib@key#1\string},^^J%
- \niibfield\space= \string{\unexpanded{#2}\string}^^J%
- \string}^^J}%
- \fi%
-}
+ @\niib@record\string{#1,^^J%
+ presort = \string{\niib@presort\string},^^J%
+ \niib@keyname\space= \string{\niib@key#1\string},^^J%
+ \niib@field\space= \string{\unexpanded{#2}\string}^^J%
+ \string}^^J}%
+ \fi}
% \end{macrocode}
%\end{macro}
-%
-% The \cmd{\bibliography} macro is patached to ensure that when it is
-% executed the note file is also processed. |biblatex| does things
-% very differently, but this actually makes it much easier to patch
-% for.
-%\changes{v1.2}{2007/10/26}{Fixed bug with \texttt{biblatex} support}
-% \begin{macrocode}
-\@ifpackageloaded{biblatex}{%
- \expandafter\bib@gadd\expandafter\blx@bibfiles\expandafter%
- {,\niibprefix\jobname}%
- }{%
-% \end{macrocode}
-%\begin{macro}{\niib@bib}
+%\begin{macro}{\niib@headcitelist}
+% To inform the user that a re-run of \LaTeX\ is needed, tracking is
+% needed of any citations that have been moved to the start of the
+% \ext{aux} file. This needs an initially-empty macro.
+% \begin{macrocode}
+\newcommand*{\niib@headcitelist}{}
+% \end{macrocode}
+%\end{macro}
+%\begin{macro}{\document}
+%\changes{v1.3}{2008/01/08}{Added hook after \ext{aux} files has been
+% read but before document begins}
+%\begin{macro}{\niib@dochook}
+%\begin{macro}{\niibheadcite}
+%\changes{v1.3}{2008/01/08}{New macro}
+%\begin{macro}{\niib@tempa}
+% When using the \opt{sort=head} option, bibnotes need to appear in
+% the \ext{aux} file before other citations. Other approaches cause
+% all sorts of problems, so the suggestion of Michael Shell is
+% implemented here. When \opt{head} is active, \cs{niibheadcite} is
+% added to the \ext{aux} file. At the next \LaTeX\ run, this will
+% add a citation to the beginning of the \ext{aux} file. To get the
+% \cs{nocite} to work, a hook has to be added to \cs{document}. The
+% reason is that \cs{AtBeginDocument} cannot be used here: it is not
+% available once the old \ext{aux} file has been read.
+% \begin{macrocode}
+\g@addto@macro{\document}{\niib@dochook}
+\newcommand*{\niibheadcite}[1]{%
+ \edef\niib@tempa{#1}%
+ \ifx\@empty\niib@headcitelist\@empty
+ \xdef\niib@headcitelist{\niib@tempa}%
+ \else
+ \xdef\niib@headcitelist{\niib@headcitelist,\niib@tempa}%
+ \fi
+ \if@filesw
+ \niib@log@debug{Adding citation #1 to start of .aux file}%
+ \fi
+ \g@addto@macro{\niib@dochook}{\nocite{#1}}}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\niib@auxhook}
+%\changes{v1.3}{2008/01/08}{New macro}
+%\begin{macro}{\niib@dochook}
+%\changes{v1.3}{2008/01/08}{New macro}
+%\begin{macro}{\@restore@auxhandle}
+% To allow the automatic punctuation-searching of \pkg{cite} to work,
+% some code has to be added to the hook available there. However, as
+% that is intended for \pkg{multibib}, care is needed to get the
+% desired result. \cs{niib@dochook} is defined here, even though it
+% is needed above, as the code here will always be executed.
+% \begin{macrocode}
+\newcommand*{\niib@dochook}{%
+ \@ifundefined{@restore@auxhandle}
+ {\newcommand*{\@restore@auxhandle}{\niib@auxhook}}
+ {\ifx\relax\@restore@auxhandle\relax
+ \newcommand*{\@restore@auxhandle}{\niib@auxhook}%
+ \else
+ \g@addto@macro{\@restore@auxhandle}{\niib@auxhook}%
+ \fi}}
+\newcommand*{\niib@auxhook}{}
+\let\niib@auxhook\relax
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%\end{macro}
+%\begin{macro}{\blx@bibfiles}
+%\changes{v1.2}{2007/10/26}{Fixed bug with \pkg{biblatex} support}
+%\changes{v1.3}{2008/01/08}{Modification now at beginning of
+% document}
+%\changes{v1.3}{2008/01/08}{Updated for \pkg{biblatex} v0.7: moved
+% to end of preamble, switch from \cs{bib@gadd} to \cs{gappto}}
+% The \cs{bibliography} macro is patched to ensure that when it is
+% executed the note file is also processed. \pkg{biblatex} does
+% things very differently, but this actually makes it much easier to
+% patch for.
+% \begin{macrocode}
+\AtEndPreamble{%
+ \@ifpackageloaded{biblatex}%
+ {\expandafter\gappto\expandafter\blx@bibfiles\expandafter%
+ {,\niib@prefix\jobname}
+ \niib@log@debug{Added bibnotes database to biblatex file list}}%
+% \end{macrocode}
+%\end{macro}
+%\begin{macro}{\niib@org@bib}
%\begin{macro}{\bibliography}
-% The bibliography command is patched so that it will run on the
-% automatically-generated BibTeX database.
+%\changes{v1.3}{2008/01/08}{Modification now at beginning of
+% document}
+% Without \pkg{biblatex}, the bibliography command is patched so that
+% it will run on the automatically-generated \BibTeX\ database. If
+% no notes have been added, then the macro doesn't actually do
+% anything.
+% \begin{macrocode}
+ {\let\niib@org@bib\bibliography
+ \renewcommand{\bibliography}[1]{%
+ \ifnum\the\value{bibnote} > \z@
+ \niib@org@bib{\niib@prefix\jobname,#1}%
+ \else
+ \niib@org@bib{#1}%
+ \fi}
+ \niib@log@debug{Added bibnote database to
+ \noexpand\bibliography}}}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
+%
+%\subsection{Finalisation}
+%\begin{macro}{\ifniib@rerun}
+% A switch is needed for the re-run test.
+% \begin{macrocode}
+\newif\ifniib@rerun
+% \end{macrocode}
+%\end{macro}
+%\begin{macro}{\niib@checkrerun}
+% Any ``head'' notes may mean a second \LaTeX\ run is needed.
+% \begin{macrocode}
+\newcommand*{\niib@checkrerun}{%
+ \niib@rerunfalse
+ \ifx\@empty\niib@headlist\@empty
+ \ifx\@empty\niib@headcitelist\@empty
+ \niib@log@debug{No `head' notes detected}%
+ \else
+ \niib@reruntrue
+ \niib@log@debug{No `head' notes found this run\MessageBreak
+ but .aux files contained the `head' requests:\MessageBreak
+ \niib@headcitelist}%
+ \fi
+ \else
+ \ifx\@empty\niib@headcitelist\@empty
+ \niib@reruntrue
+ \niib@log@debug{No `head' requests in .aux file\MessageBreak
+ but `head' notes in this run:\MessageBreak
+ \niib@headlist}%
+ \else
+% \end{macrocode}
+% If the package gets here, then there are some head notes and some head
+% requests in the aux file. The two lists are now compared.
% \begin{macrocode}
- \let\niib@bib\bibliography%
- \renewcommand{\bibliography}[1]{%
- \ifnum\the\value{bibnote} > \z@%
- \niib@bib{\niibprefix\jobname,#1}%
- \else%
- \niib@bib{#1}%
- \fi}}%
+ \niib@checklists%
+ \fi
+ \fi
+ \ifniib@rerun
+% \end{macrocode}
+% Both human-readable requests for new runs, and \pkg{biblatex}-style
+% automated requests are made. The package does not know if \BibTeX8
+% is in use, so just asks for \BibTeX.
+% \begin{macrocode}
+ \niib@log@warn{Rerun LaTeX to get correct `head' notes}%
+ \niib@log@warn{Please (re)run BibTeX on the file(s):
+ \MessageBreak\jobname.aux
+ \MessageBreak and rerun LaTeX afterwards.}%
+ \ifniib@lognone\else
+ \typeout{%
+ REQ:3:latex:REQ^^J%
+ REQ:2:bibtex:REQ^^J%
+ REQ:1:latex:REQ}%
+ \fi
+ \fi}
% \end{macrocode}
%\end{macro}
+%\begin{macro}{\niib@checklists}
+%\begin{macro}{\niib@tempa}
+%\begin{macro}{\niib@tempb}
+% The business end of comparing the two lists. Two sweeps are made,
+% to check that the lists match entirely.
+% \begin{macrocode}
+\newcommand*{\niib@checklists}{%
+ \@for\niib@tempa:=\niib@headlist\do{%
+ \niib@reruntrue
+ \@for\niib@tempb:=\niib@headcitelist\do{%
+ \ifx\niib@tempa\niib@tempb
+ \niib@rerunfalse
+ \fi}
+ \ifniib@rerun
+ \niib@log@debug{Note \niib@tempa is a `head' note
+ \MessageBreak but request not in .aux file}%
+ \fi}
+ \ifniib@rerun\else
+ \@for\niib@tempa:=\niib@headcitelist\do{%
+ \niib@reruntrue
+ \@for\niib@tempb:=\niib@headlist\do{%
+ \ifx\niib@tempa\niib@tempb
+ \niib@rerunfalse
+ \fi}
+ \ifniib@rerun
+ \niib@log@debug{Note \niib@tempa is set to `head' in
+ .aux\MessageBreak file but is not a `head' note}%
+ \fi}
+ \fi}
+% \end{macrocode}
+%\end{macro}
+%\end{macro}
%\end{macro}
-%%
% At the end of the document, any delayed citations are written to the
-% |.aux| file, and the database file is closed cleanly.
+% \ext{aux} file, and the database file is closed cleanly. A check is
+% also made for the need for an additional \LaTeX\ run for ``head''
+% notes.
% \begin{macrocode}
\AtEndDocument{%
- \flushcitestack%
- \@ifundefined{niib@out}{}%
- {\immediate\closeout\niib@out}%
-}
+ \flushnotestack%
+ \niib@checkrerun%
+ \@ifundefined{niib@out}{}
+ {\immediate\closeout\niib@out%
+ \niib@log@debug{Closed BibTeX database file\MessageBreak
+ \niib@stream}}}
+% \end{macrocode}
+% Options are processed at the end of the package, to avoid any odd
+% issues arising with definition of macros.
+% \begin{macrocode}
+\ProcessOptionsX[niib]<opt>
% \end{macrocode}
%
%\iffalse
@@ -1315,34 +1544,14 @@
% \Finale
%\iffalse
%<*jawltxdoc>
-% The following is convenient method for collecting together package
-% loading, formatting commands and new macros used to format |dtx|
-% files written by the current author. It is based on the similar
-% files provided by Will Robertson in his packages and Heiko Oberdiek
-% as a stand-alone package. Notice that it is not intended for other
-% users: there is no error checking! However, it is covered by the
-% LPPL in the same way as the rest of this package.
-%
-% \begin{macrocode}
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{jawltxdoc}
- [2007/10/23 v1.0 Formatting for .dtx files (JAW)]
-% \end{macrocode}
-% First of all, a number of support packages are loaded.
-% \begin{macrocode}
\usepackage[T1]{fontenc}
\usepackage[english,UKenglish]{babel}
\usepackage[scaled=0.95]{helvet}
\usepackage[version=3]{mhchem}
\usepackage[final]{microtype}
\usepackage[osf]{mathpazo}
-\usepackage{booktabs,array,url,graphicx,courier,unitsdef}
+\usepackage{booktabs,array,url,graphicx,courier,xspace}
\usepackage{upgreek,ifpdf,listings}
-% \end{macrocode}
-% If using PDFLaTeX, the source will be attached to the PDF. This is
-% basically the system used by Heiko Oberdiek, but with a check that
-% PDF mode is enabled.
-% \begin{macrocode}
\ifpdf
\usepackage{embedfile}
\embedfile[%
@@ -1351,20 +1560,15 @@
desc={LaTeX docstrip source archive for package `\jobname'}%
]{\jobname.dtx}
\fi
-\usepackage{\jobname}
+\IfFileExists{\jobname.sty}
+ {\usepackage{\jobname}}{}
\usepackage[numbered]{hypdoc}
-% \end{macrocode}
-% To typeset examples, a new environment is needed. The code below
-% is based on that in used by |listings|, but is modified to get
-% better formatting for this context. The formatting of the output
-% is basically that in Will Robertson's |dtx-style| file.
-% \begin{macrocode}
\newlength\LaTeXwidth
\newlength\LaTeXoutdent
\newlength\LaTeXgap
\setlength\LaTeXgap{1em}
\setlength\LaTeXoutdent{-0.15\textwidth}
-\def\typesetexampleandcode{%
+\newcommand*{\typesetexampleandcode}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin\LaTeXoutdent
@@ -1381,7 +1585,7 @@
\end{minipage}%
\end{list}
}
-\def\typesetcodeandexample{%
+\newcommand*{\typesetcodeandexample}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin{0pt}
@@ -1394,7 +1598,7 @@
\lst@sampleInput
\end{list}
}
-\def\typesetfloatexample{%
+\newcommand*{\typesetfloatexample}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin{0pt}
@@ -1407,7 +1611,7 @@
\end{minipage}%
\end{list}
}
-\def\typesetcodeonly{%
+\newcommand*{\typesetcodeonly}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin{0pt}
@@ -1426,27 +1630,19 @@
\let\typesetexample#1
\global\let\lst@intname\@empty
\setbox\lst@samplebox=\hbox\bgroup
- \setkeys{lst}{language=[LaTeX]{TeX},tabsize=4,gobble=2,%
+ \setkeys{lst}{language=[LaTeX]{TeX},tabsize=4,gobble=3,%
breakindent=0pt,basicstyle=\small\ttfamily,basewidth=0.51em,%
keywordstyle=\color{blue},%
-% \end{macrocode}
-% Notice that new keywords should be added here. The list is simply
-% macro names needed to typeset documentation of the package
-% author.
-% \begin{macrocode}
- morekeywords={bibnote,citenote,bibnotetext,bibnotemark,%
- thebibnote,bibnotename,includegraphics,schemeref,%
- floatcontentsleft,floatcontentsright,floatcontentscentre,%
- schemerefmarker,compound,schemerefformat,color,%
- startchemical,stopchemical,chemical,setupchemical,bottext,%
- listofschemes}}
+ morekeywords={% notes2bib
+ niibsetup,bibnote,bibnotetext,bibnotemark,thebibnote,%
+ flushnotestack,citenote,printbibnotes}}
\lst@BeginAlsoWriteFile{\LaTeXexamplefile}
}{%
\lst@EndWriteFile\egroup
\setlength\LaTeXwidth{\wd\lst@samplebox}
\typesetexample%
}
-\def\lst@sampleInput{%
+\newcommand*{\lst@sampleInput}{%
\MakePercentComment\catcode`\^^M=10\relax
\small%
{\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}%
@@ -1454,7 +1650,30 @@
\leavevmode \input{\LaTeXexamplefile}}%
\MakePercentIgnore%
}
-\hyphenation{PDF-LaTeX}
-% \end{macrocode}
+\newcommand*{\pkg}[1]{\textsf{#1}}
+\newcommand*{\currpkg}{\pkg{\jobname}\xspace}
+\newcommand*{\opt}[1]{\texttt{#1}}
+\newcommand*{\ext}[1]{\texttt{.#1}}
+\newcommand*{\latin}[1]{\emph{#1}}
+\newcommand*{\etc}{%
+ \@ifnextchar.
+ {\latin{etc}}
+ {\latin{etc.}}
+ \xspace}
+\newcommand*{\eg}{%
+ \@ifnextchar.
+ {\latin{e.g}}
+ {\latin{e.g.}}
+ \xspace}
+\newcommand*{\ie}{%
+ \@ifnextchar.
+ {\latin{i.e}}
+ {\latin{i.e.}}
+ \xspace}
+\newcommand*{\AMS}{{\protect\usefont{OMS}{cmsy}{m}{n}%
+ A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
+\providecommand*{\eTeX}{\ensuremath{\varepsilon}-\TeX}
+\newcommand*{\XeTeX}
+ {X\kern-.125em\lower.5ex\hbox{\reflectbox{E}}\kern-.1667em\TeX}
%</jawltxdoc>
%\fi
diff --git a/Master/texmf-dist/tex/latex/notes2bib/jawltxdoc.sty b/Master/texmf-dist/tex/latex/notes2bib/jawltxdoc.sty
index f568592299f..4b82f48aec4 100644
--- a/Master/texmf-dist/tex/latex/notes2bib/jawltxdoc.sty
+++ b/Master/texmf-dist/tex/latex/notes2bib/jawltxdoc.sty
@@ -13,16 +13,13 @@
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%%
-\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{jawltxdoc}
- [2007/10/23 v1.0 Formatting for .dtx files (JAW)]
\usepackage[T1]{fontenc}
\usepackage[english,UKenglish]{babel}
\usepackage[scaled=0.95]{helvet}
\usepackage[version=3]{mhchem}
\usepackage[final]{microtype}
\usepackage[osf]{mathpazo}
-\usepackage{booktabs,array,url,graphicx,courier,unitsdef}
+\usepackage{booktabs,array,url,graphicx,courier,xspace}
\usepackage{upgreek,ifpdf,listings}
\ifpdf
\usepackage{embedfile}
@@ -32,14 +29,15 @@
desc={LaTeX docstrip source archive for package `\jobname'}%
]{\jobname.dtx}
\fi
-\usepackage{\jobname}
+\IfFileExists{\jobname.sty}
+ {\usepackage{\jobname}}{}
\usepackage[numbered]{hypdoc}
\newlength\LaTeXwidth
\newlength\LaTeXoutdent
\newlength\LaTeXgap
\setlength\LaTeXgap{1em}
\setlength\LaTeXoutdent{-0.15\textwidth}
-\def\typesetexampleandcode{%
+\newcommand*{\typesetexampleandcode}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin\LaTeXoutdent
@@ -56,7 +54,7 @@
\end{minipage}%
\end{list}
}
-\def\typesetcodeandexample{%
+\newcommand*{\typesetcodeandexample}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin{0pt}
@@ -69,7 +67,7 @@
\lst@sampleInput
\end{list}
}
-\def\typesetfloatexample{%
+\newcommand*{\typesetfloatexample}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin{0pt}
@@ -82,7 +80,7 @@
\end{minipage}%
\end{list}
}
-\def\typesetcodeonly{%
+\newcommand*{\typesetcodeonly}{%
\begin{list}{}{%
\setlength\itemindent{0pt}
\setlength\leftmargin{0pt}
@@ -101,22 +99,19 @@
\let\typesetexample#1
\global\let\lst@intname\@empty
\setbox\lst@samplebox=\hbox\bgroup
- \setkeys{lst}{language=[LaTeX]{TeX},tabsize=4,gobble=2,%
+ \setkeys{lst}{language=[LaTeX]{TeX},tabsize=4,gobble=3,%
breakindent=0pt,basicstyle=\small\ttfamily,basewidth=0.51em,%
keywordstyle=\color{blue},%
- morekeywords={bibnote,citenote,bibnotetext,bibnotemark,%
- thebibnote,bibnotename,includegraphics,schemeref,%
- floatcontentsleft,floatcontentsright,floatcontentscentre,%
- schemerefmarker,compound,schemerefformat,color,%
- startchemical,stopchemical,chemical,setupchemical,bottext,%
- listofschemes}}
+ morekeywords={% notes2bib
+ niibsetup,bibnote,bibnotetext,bibnotemark,thebibnote,%
+ flushnotestack,citenote,printbibnotes}}
\lst@BeginAlsoWriteFile{\LaTeXexamplefile}
}{%
\lst@EndWriteFile\egroup
\setlength\LaTeXwidth{\wd\lst@samplebox}
\typesetexample%
}
-\def\lst@sampleInput{%
+\newcommand*{\lst@sampleInput}{%
\MakePercentComment\catcode`\^^M=10\relax
\small%
{\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}%
@@ -124,7 +119,31 @@
\leavevmode \input{\LaTeXexamplefile}}%
\MakePercentIgnore%
}
-\hyphenation{PDF-LaTeX}
+\newcommand*{\pkg}[1]{\textsf{#1}}
+\newcommand*{\currpkg}{\pkg{\jobname}\xspace}
+\newcommand*{\opt}[1]{\texttt{#1}}
+\newcommand*{\ext}[1]{\texttt{.#1}}
+\newcommand*{\latin}[1]{\emph{#1}}
+\newcommand*{\etc}{%
+ \@ifnextchar.
+ {\latin{etc}}
+ {\latin{etc.}}
+ \xspace}
+\newcommand*{\eg}{%
+ \@ifnextchar.
+ {\latin{e.g}}
+ {\latin{e.g.}}
+ \xspace}
+\newcommand*{\ie}{%
+ \@ifnextchar.
+ {\latin{i.e}}
+ {\latin{i.e.}}
+ \xspace}
+\newcommand*{\AMS}{{\protect\usefont{OMS}{cmsy}{m}{n}%
+ A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
+\providecommand*{\eTeX}{\ensuremath{\varepsilon}-\TeX}
+\newcommand*{\XeTeX}
+ {X\kern-.125em\lower.5ex\hbox{\reflectbox{E}}\kern-.1667em\TeX}
\endinput
%%
%% End of file `jawltxdoc.sty'.
diff --git a/Master/texmf-dist/tex/latex/notes2bib/notes2bib.sty b/Master/texmf-dist/tex/latex/notes2bib/notes2bib.sty
index e19a1ef31a5..d132e311795 100644
--- a/Master/texmf-dist/tex/latex/notes2bib/notes2bib.sty
+++ b/Master/texmf-dist/tex/latex/notes2bib/notes2bib.sty
@@ -15,346 +15,457 @@
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{notes2bib}
- [2007/10/31 v1.2a Integrating notes into the bibliography]
-\@ifundefined{eTeXversion}
- {\PackageError{notes2bib}
- {Not running under e-TeX}
- {This package requires e-TeX. Try compiling the document
- with\MessageBreak `elatex' instead of `latex'. When using
- pdfTeX, try `pdfelatex'\MessageBreak instead of `pdflatex'}%
- \endinput}
- {}
-\RequirePackage{etoolbox}
-\newif\ifniib@fn\niib@fnfalse
-\DeclareOption{footnotes}{%
- \niib@fntrue
- \AtBeginDocument{%
- \let\footnote\bibnote%
- \PackageInfo{notes2bib}%
- {Converting footnotes to bibnotes}%
-}}
-\DeclareOption{endnotes}{%
- \AtBeginDocument{%
- \let\endnote\bibnote%
- \let\endnotemark\bibnotemark%
- \let\endnotetext\bibnotetext%
- \@ifpackageloaded{endnotes}%
- {\let\theendnotes\printbibnotes}{}%
- \PackageInfo{notes2bib}%
- {Converting endnotes to bibnotes}%
-}}
-\newif\ifniib@tail\niib@tailfalse
-\newif\ifniib@head\niib@headfalse
-\DeclareOption{tail}{\niib@tailtrue}
-\DeclareOption{head}{\niib@headtrue}
-\ProcessOptions\relax
-\ifniib@fn
- \let\niib@fnmark\footnotemark
- \let\niib@fntext\footnotetext
- \let\niib@thanks\thanks
- \patchcmd{\thanks}{\footnotemark}{\niib@fnmark}{%
- \patchcmd{\thanks}{\footnotetext}{\niib@fntext}{%
- \AtBeginDocument{%
- \let\footnotemark\bibnotemark
- \let\footnotetext\bibnotetext
- }%
- \PackageInfo{notes2bib}%
- {Modifying \protect\thanks\space macro}%
- }{%
- \let\thanks\niib@thanks%
- \PackageWarning{notes2bib}%
- {Could not patch \protect\thanks}}%
- }{%
- \let\thanks\niib@thanks%
- \PackageWarning{notes2bib}%
- {Could not patch \protect\thanks}}%
-\fi
-\ifniib@head
- \ifniib@tail
- \PackageWarning{notes2bib}
- {You've given both ``head'' and ``tail'' as
- options\MessageBreak I'm ignoring both!\MessageBreak
- bibnotes will be interspersed with other citations}
- \niib@headfalse\niib@tailfalse
- \else
- \PackageInfo{notes2bib}%
- {bibnotes will head other citations}
- \fi
-\else
+ [2008/01/08 v1.3 Integrating notes into the bibliography]
+\begingroup
+ \@ifundefined{eTeXversion}
+ {\PackageError{notes2bib}
+ {Not running under e-TeX}
+ {This package requires e-TeX. Try compiling the document
+ with\MessageBreak `elatex' instead of `latex'. When using
+ pdfTeX, try `pdfelatex'\MessageBreak instead of `pdflatex'}
+ \endgroup\endinput}
+ {\endgroup}
+\RequirePackage{xkeyval,etoolbox}
+\newcommand*{\niib@tempa}{}
+\newcommand*{\niib@tempb}{}
+\newif\ifniib@debug
+\newif\ifniib@logmin
+\newif\ifniib@lognone
+\newcommand*{\niib@log@err}[2]{%
+ \ifniib@lognone\else
+ \ifniib@logmin
+ \PackageWarning{notes2bib}{#1}%
+ \else
+ \PackageError{notes2bib}{#1}{#2}%
+ \fi
+ \fi}
+\newcommand*{\niib@log@warn}[1]{%
+ \ifniib@lognone\else
+ \ifniib@logmin\else
+ \PackageWarning{notes2bib}{#1}%
+ \fi
+ \fi}
+\newcommand*{\niib@log@inf}[1]{%
+ \ifniib@lognone\else
+ \ifniib@logmin\else
+ \PackageInfo{notes2bib}{#1}%
+ \fi
+ \fi}
+\newcommand*{\niib@log@debug}[1]{%
+ \ifniib@lognone\else
+ \ifniib@debug
+ \PackageInfo{notes2bib}{#1}%
+ \fi
+ \fi}
+\newcommand*{\niib@opt@boolkey}[2][]{%
+ \define@boolkey[niib]{opt}[niib@]{#2}[true]
+ {#1\niib@log@debug{Option #2 set to ##1}}}
+\newcommand*{\niib@opt@choicekey}[5][]{%
+ \define@choicekey*+[niib]{opt}{#2}[\niib@tempa]{#3}[#1]
+ {#4\niib@log@debug{Option #2 set to ##1}}
+ {#5\niib@log@debug{Option #2 set to ##1}}}
+\newcommand*{\niib@opt@cmdkeys}[1]{%
+ \define@cmdkeys[niib]{opt}[niib@]{#1}}
+\newcommand*{\niibsetup}[1]{%
+ \iffalse{\fi\ifnum0=`}\fi
+ \setkeys[niib]{opt}{#1}%
+ \ifnum0=`{\fi\iffalse}\fi}
+\niib@opt@choicekey[normal]{log}{debug,verbose,normal,errors,none}
+ {\niib@debugfalse
+ \niib@logminfalse
+ \niib@lognonefalse
+ \renewcommand*{\niib@tempb}{none}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@lognonetrue
+ \fi
+ \renewcommand*{\niib@tempb}{minimal}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@logmintrue
+ \fi
+ \renewcommand*{\niib@tempb}{debug}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@debugtrue
+ \fi
+ \renewcommand*{\niib@tempb}{verbose}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@debugtrue
+ \fi}
+ {\niib@log@warn{Unrecognised value `#1' for option log}}
+\niib@opt@boolkey{debug}
+\niib@opt@boolkey[\niib@swapfoot]{footnotes}
+\niib@opt@boolkey[\niib@swapend]{endnotes}
+\newif\ifniib@tail
+\newif\ifniib@head
+\niib@opt@choicekey[none]{sort}{none,head,tail}
+ {\niib@headfalse
+ \niib@tailfalse
+ \renewcommand*{\niib@tempb}{head}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@headtrue
+ \fi
+ \renewcommand*{\niib@tempb}{tail}%
+ \ifx\niib@tempa\niib@tempb
+ \niib@tailtrue
+ \fi}
+ {\niib@log@warn{Unrecognised value `#1' for option sort}}
+\niib@opt@boolkey[%
+ \ifniib@head
+ \ifniib@tail
+ \niib@tailfalse
+ \niib@log@inf{Option head cancels existing\MessageBreak
+ tail or sort=tail option}
+ \fi
+ \fi]{head}
+\niib@opt@boolkey[%
\ifniib@tail
- \PackageInfo{notes2bib}%
- {bibnotes will tail other citations}
- \else
- \PackageInfo{notes2bib}%
- {bibnotes will be interspersed with other citations}
- \fi
-\fi
+ \ifniib@head
+ \niib@headfalse
+ \niib@log@inf{Option tail cancels existing\MessageBreak
+ head or sort=head option}
+ \fi
+ \fi]{tail}
+\niib@opt@cmdkeys{%
+ cite,
+ name,
+ prefix,
+ record,
+ field,
+ presorthead,
+ presortnone,
+ presorttail,
+ keyhead,
+ keynone,
+ keytail}
+\niibsetup{%
+ cite=cite,
+ name=Bibnote,
+ prefix=niib-,
+ record=Misc,
+ field=note,
+ presorthead=ml,
+ presortnone=mm,
+ presorttail=mn,
+ keyhead=aaa,
+ keynone={},
+ keytail=zzz}
\AtBeginDocument{%
- \ifniib@head
- \let\delaycite\niib@delaycite
- \delaycite{cite}%
- \@ifpackageloaded{natbib}{%
- \delaycite{citet}%
- \delaycite{citep}%
- \delaycite{citenum}%
- \delaycite{citealt}%
- \delaycite{citealp}%
- \delaycite{citetext}%
- \delaycite{citeauthor}%
- \delaycite{citeyear}%
- \delaycite{citeyearpar}%
- \delaycite{Citet}%
- \delaycite{Citep}%
- \delaycite{Citealt}%
- \delaycite{Citealp}%
- \delaycite{Citeauthor}%
- }{}%
- \@ifpackageloaded{biblatex}{%
- \delaycite{Cite}%
- \delaycite{parencite}%
- \delaycite{Parencite}%
- \delaycite{footcite}%
- \delaycite{Footcite}%
- \delaycite{textcite}%
- \delaycite{Textcite}%
- \@ifundefined{autocite}{}%
- {\delaycite{autocite}}%
- \@ifundefined{supercite}{}%
- {\delaycite{supercite}}%
- }{}%
- \fi%
-}
-\newcommand*\bibnotename{Bibnote}
+ \let\niib@org@footnote\footnote
+ \let\niib@org@footnotemark\footnotemark
+ \let\niib@org@footnotetext\footnotetext
+ \let\niib@org@thanks\thanks
+ \@ifpackageloaded{endnotes}
+ {\let\niib@org@endnote\endnote
+ \let\niib@org@endnotemark\endnotemark
+ \let\niib@org@endnotetext\endnotetext
+ \let\niib@org@theendnotes\theendnotes}}
+\AtBeginDocument{%
+ \let\niib@thanks\thanks
+ \let\niib@footnotetext\footnotetext
+ \let\niib@footnotemark\footnotemark
+ \patchcmd{\niib@thanks}{\footnotetext}{\niib@org@footnotetext}
+ {\patchcmd{\niib@thanks}{\footnotemark}
+ {\niib@org@footnotemark}
+ {\let\thanks\niib@thanks
+ \let\niib@footnotetext\bibnotetext
+ \let\niib@footnotemark\bibnotemark
+ \niib@log@debug{Successfully patched \noexpand\thanks}}
+ {\niib@log@warn{Failed to patch \noexpand\thanks\MessageBreak
+ \noexpand\footnotemark\space and
+ \noexpand\footnotetext\MessageBreak are unmodified}%
+ \niib@log@debug{Could not substitute
+ \noexpand\footnotemark\MessageBreak in \noexpand\thanks}}}
+ {\niib@log@warn{Failed to patch \noexpand\thanks\MessageBreak
+ \noexpand\footnotemark\space and
+ \noexpand\footnotetext\MessageBreak are unmodified}%
+ \niib@log@debug{Could not substitute
+ \noexpand\footnotetext\MessageBreak in \noexpand\thanks}}}
+\newcommand*{\niib@swapfoot}{}
+\AtBeginDocument{%
+ \renewcommand*{\niib@swapfoot}{%
+ \ifniib@footnotes
+ \let\footnote\bibnote
+ \let\footnotemark\niib@footnotemark
+ \let\footnotetext\niib@footnotetext
+ \niib@log@debug{Converting footnotes to bibnotes}%
+ \else
+ \let\footnote\niib@org@footnote
+ \let\footnotemark\niib@org@footnotemark
+ \let\footnotetext\niib@org@footnotetext
+ \niib@log@debug{Using kernel definition of footnotes}%
+ \fi}
+ \niib@swapfoot}
+\newcommand*{\niib@swapend}{}
+\AtBeginDocument{%
+ \@ifpackageloaded{endnotes}
+ {\renewcommand*{\niib@swapend}{%
+ \ifniib@endnotes
+ \let\endnote\bibnote
+ \let\endnotemark\bibnotemark
+ \let\endnotetext\bibnotetext
+ \let\theendnotes\printbibnotes
+ \niib@log@debug{Converting endnotes to bibnotes}%
+ \else
+ \let\endnote\niib@org@endnote
+ \let\endnotemark\niib@org@endnotemark
+ \let\endnotetext\niib@org@endnotetext
+ \let\theendnotes\niib@org@theendnotes
+ \niib@log@debug{Using endnotes package to handle endnotes}%
+ \fi}
+ \niib@swapend}
+ {\ifniib@endnotes
+ \let\endnote\bibnote
+ \let\endnotemark\bibnotemark
+ \let\endnotetext\bibnotetext
+ \let\theendnotes\printbibnotes
+ \niib@log@debug{Converting endnotes to bibnotes}%
+ \fi
+ \renewcommand*{\niib@swapend}{%
+ \ifniib@endnotes
+ \let\endnote\bibnote
+ \let\endnotemark\bibnotemark
+ \let\endnotetext\bibnotetext
+ \let\theendnotes\printbibnotes
+ \niib@log@debug{Converting endnotes to bibnotes}%
+ \else
+ \niib@log@inf{endnotes package not loaded\MessageBreak
+ endnotes=false ignored}%
+ \fi}}}
\newcounter{bibnote}
-\renewcommand*{\thebibnote}{\bibnotename\the\value{bibnote}}
-\newcommand*\niibprefix{niib-}
-\newcommand*\niibrecord{Misc}
-\newcommand*\niibfield{note}
-\newcommand*\niibpresorthead{ml}
-\newcommand*\niibpresortnone{mm}
-\newcommand*\niibpresorttail{mn}
-\newcommand*\niibkeyhead{aaa}
-\newcommand*\niibkeynone{}
-\newcommand*\niibkeytail{zzz}
-\newcommand*\niibcite{\cite}
-\newrobustcmd*{\bibnote}{%
+\renewcommand*{\thebibnote}{\niib@name\the\value{bibnote}}
+\DeclareRobustCommand*{\bibnote}{%
\stepcounter{bibnote}%
- \@ifnextchar[%
- {\niib@bibnote}%
- {\niib@bibnote[\thebibnote]}%
-}
-\newrobustcmd*{\bibnotemark}{%
+ \@ifnextchar[%]
+ {\niib@bibnote}
+ {\niib@bibnote[\thebibnote]}}
+\DeclareRobustCommand*{\bibnotemark}{%
\stepcounter{bibnote}%
- \@ifnextchar[%
- {\niib@mark}%
- {\niib@mark[\thebibnote]}%
-}
-\newrobustcmd*{\bibnotetext}[1][\thebibnote]{%
- \niib@text{#1}%
-}
-\@ifpackageloaded{biblatex}{%
- \let\printbibnotes\printbibliography%
-}{%
- \newrobustcmd*{\printbibnotes}{\niib@bib%
- {\niibprefix\jobname}}%
-}%
-\newrobustcmd*{\flushcitestack}{%
- \ifx\niib@stack\relax\else%
- \expandafter\nocite\expandafter{\niib@stack}%
- \global\let\niib@stack\relax%
- \fi%
-}
-\newrobustcmd*{\delaycite}[1]{%
- \PackageWarning{notes2bib}{%
- \@nameuse{delaycite}can only be used in the document
- body\MessageBreak Not modifying citation macro \@nameuse{#1}}
-}
-\ifniib@tail
- \newrobustcmd*\citenote{%
- \niib@cnfalse%
- \niibcite%
- }%
-\else
- \newrobustcmd*\citenote{\niibcite}%
-\fi
+ \@ifnextchar[%]
+ {\niib@mark}
+ {\niib@mark[\thebibnote]}}
+\DeclareRobustCommand*{\bibnotetext}[1][\thebibnote]{%
+ \niib@text{#1}}
\@ifpackageloaded{biblatex}
- {\def\niib@keyname{keysort}}
- {\def\niib@keyname{key}}
-\ifniib@head
- \def\niib@presort{\niibpresorthead}
- \def\niib@key{\niibkeyhead}
-\else
- \ifniib@tail
- \def\niib@presort{\niibpresorttail}
- \def\niib@key{\niibkeytail}
+ {\let\printbibnotes\printbibliography}
+ {\DeclareRobustCommand*{\printbibnotes}
+ {\niib@org@bib{\niib@prefix\jobname}}}
+\DeclareRobustCommand*{\flushnotestack}{%
+ \ifx\@empty\niib@stack\@empty
+ \niib@log@debug{Citation stack empty: nothing for\MessageBreak
+ \noexpand\flushnotestack to do}%
+ \else%
+ \niib@log@debug{Flushing note citations to aux file}%
+ \expandafter\nocite\expandafter{\niib@stack}%
+ \gdef\niib@stack{}%
+ \fi}
+\DeclareRobustCommand*{\citenote}[1]{\niib@mark[#1]}
+\AtBeginDocument{%
+ \@ifpackageloaded{biblatex}
+ {\niib@log@debug{Using field `keysort' for sorting key}%
+ \newcommand*\niib@keyname{keysort}}
+ {\niib@log@debug{Using field `key' for sorting key}%
+ \newcommand*\niib@keyname{key}}}
+\newcommand*{\niib@presort}{%
+ \ifniib@head
+ \niib@presorthead%
\else
- \def\niib@presort{\niibpresortnone}
- \def\niib@key{\niibkeynone}
- \fi
-\fi
+ \ifniib@tail
+ \niib@presorttail%
+ \else
+ \niib@presortnone%
+ \fi
+ \fi}
+\newcommand*{\niib@key}{%
+ \ifniib@head
+ \niib@keyhead%
+ \else
+ \ifniib@tail
+ \niib@keytail%
+ \else
+ \niib@keynone%
+ \fi
+ \fi}
\edef\niib@msg{%
This is an auxiliary file used by the `notes2bib' package.^^J%
This file may safely be deleted. It will be recreated as
required.^^J}
-\let\niib@stack\relax
-\newif\ifniib@cn\niib@cnfalse%
-\newif\ifniib@citing\niib@citingfalse%
-\newif\ifniib@filesw\niib@fileswfalse%
-\newif\ifniib@orig@filesw
-\if@filesw
- \niib@orig@fileswtrue%
-\else
- \niib@orig@fileswfalse%
-\fi
-\def\niib@head@filesw{%
- \let\@fileswtrue\niib@orig@fileswtrue%
- \let\@fileswfalse\niib@orig@fileswfalse%
- \def\if@filesw{%
- \ifniib@orig@filesw
- \niib@fileswtrue%
- \else
- \niib@fileswfalse%
- \fi
- \ifniib@citing
- \ifniib@cn\else
- \niib@fileswfalse%
- \fi
- \fi
- \global\niib@cnfalse%
- \global\niib@citingfalse%
- \ifniib@filesw%
- }
-}
-\ifniib@head
- \niib@head@filesw%
-\fi
-\def\niib@tail@filesw{%
- \let\@fileswtrue\niib@orig@fileswtrue%
- \let\@fileswfalse\niib@orig@fileswfalse%
- \def\if@filesw{%
- \ifniib@orig@filesw
- \niib@fileswtrue%
+\newcommand*{\niib@stack}{}
+\newcommand*{\niib@addtostack}[1]{%
+ \niib@log@debug{Adding citation #1 to stack}%
+ \edef\niib@tempa{#1}%
+ \ifx\@empty\niib@stack\@empty
+ \xdef\niib@stack{\niib@tempa}%
+ \else
+ \xdef\niib@stack{\niib@stack,\niib@tempa}%
+ \fi}
+\long\def\niib@bibnote[#1]#2{%
+ \niib@text{#1}{#2}%
+ \niib@mark[#1]}
+\newcommand*{\niib@headlist}{}
+\def\niib@mark[#1]{%
+ \ifniib@head
+ \edef\niib@tempa{#1}%
+ \ifx\@empty\niib@headlist\@empty
+ \xdef\niib@headlist{\niib@tempa}%
\else
- \niib@fileswfalse%
- \fi
- \ifniib@cn
- \niib@fileswfalse%
+ \xdef\niib@headlist{\niib@headlist,\niib@tempa}%
\fi
- \global\niib@cnfalse%
- \ifniib@filesw%
- }
-}
-\ifniib@tail
- \niib@tail@filesw%
-\fi
-\newrobustcmd*\niib@delaycite[1]{%
- \@ifundefined{#1}{%
- \PackageWarning{notes2bib}
- {Citation macro \@nameuse{#1}undefined\MessageBreak
- \protect\delaycite\space cannot operate on this macro}
- }{%
- \@ifundefined{niib@orig@#1}{%
- \expandafter\expandafter\expandafter\let\expandafter%
- \csname niib@orig@#1\expandafter\endcsname\csname #1\endcsname%
- \expandafter\renewcommand\csname #1\endcsname{%
- \niib@citingtrue%
- \@ifnextchar[%]
- {\@nameuse{niib@optarg@#1}}
- {\@nameuse{niib@noarg@#1}}
- }
- \expandafter\def\csname niib@optarg@#1\endcsname[##1]{%
- \@ifnextchar[%]
- {\@nameuse{niib@twoopt@#1}[##1]}
- {\@nameuse{niib@oneopt@#1}[##1]}
- }
- \expandafter\def\csname niib@oneopt@#1\endcsname[##1]##2{%
- \niib@stackup{##2}%
- \@nameuse{niib@orig@#1}[##1]{##2}%
- }
- \expandafter\def\csname niib@twoopt@#1\endcsname[##1][##2]##3{%
- \niib@stackup{##3}%
- \@nameuse{niib@orig@#1}[##1][##2]{##3}%
- }
- \expandafter\def\csname niib@noarg@#1\endcsname##1{%
- \niib@stackup{##1}%
- \@nameuse{niib@orig@#1}{##1}%
- }
- }{%
- \PackageInfo{notes2bib}%
- {Already delayed \@nameuse{#1}}%
- }
- }
-}
-\def\niib@stackup#1{%
- \ifniib@cn\else
- \edef\niib@temp{#1}%
- \ifx\niib@stack\relax%
- \xdef\niib@stack{\niib@temp}%
- \else
- \xdef\niib@stack{\niib@stack,\niib@temp}%
+ \if@filesw
+ \niib@log@debug{Adding citation #1 to list for next run}%
+ \immediate\write\@auxout{\string\niibheadcite{#1}}%
\fi
\fi
-}
-\long\def\niib@bibnote[#1]#2{%
- \niib@text{#1}{#2}%
- \niib@cite{#1}%
-}
-\def\niib@mark[#1]{\niib@cite{#1}}
-\ifniib@head%
- \def\niib@cite#1{%
- \niib@cntrue%
- \niibcite{#1}%
- }%
-\else%
- \ifniib@tail%
- \def\niib@cite#1{%
- \ifx\niib@stack\relax%
- \xdef\niib@stack{#1}%
- \else%
- \xdef\niib@stack{\niib@stack,#1}%
- \fi%
- \niib@cntrue%
- \niibcite{#1}%
- }%
- \else%
- \def\niib@cite#1{\niibcite{#1}}%
- \fi%
-\fi%
-\long\def\niib@text#1#2{%
+ \ifniib@tail
+ \expandafter\niib@tailcite%
+ \else
+ \expandafter\niib@normcite%
+ \fi
+ {#1}}
+\newif\ifniib@filesw
+\AtBeginDocument{%
+ \@ifpackageloaded{biblatex}
+ {\newcommand{\niib@tailcite}[1]{%
+ \niib@addtostack{#1}%
+ \AtNextCite{\@fileswfalse}%
+ \niib@normcite{#1}}}
+ {\newcommand{\niib@tailcite}[1]{%
+ \niib@addtostack{#1}%
+ \let\ifniib@filesw\if@filesw
+ \@fileswfalse
+ \let\niib@auxhook\niib@restorefilesw
+ \niib@tcite{#1}}}}
+\newcommand*{\niib@restorefilesw}{%
+ \let\if@filesw\ifniib@filesw
+ \let\niib@auxhook\relax}
+\AtBeginDocument{%
+ \@ifpackageloaded{cite}
+ {\newcommand*{\niib@tcite}[1]{\niib@normcite{#1}}}
+ {\newcommand*{\niib@tcite}[1]{%
+ \niib@normcite{#1}%
+ \niib@restorefilesw}}}
+\newcommand*{\niib@normcite}{\@nameuse{\niib@cite}}
+\newcommand{\niib@text}[2]{%
\@ifundefined{niib@out}{%
- \if@filesw%
+ \if@filesw
\newwrite\niib@out%
- \gdef\niib@stream{\niibprefix\jobname.bib}%
- \immediate\openout\niib@out\niib@stream\relax%
+ \gdef\niib@stream{\niib@prefix\jobname.bib}%
+ \niib@log@debug{Creating BibTeX database file \MessageBreak
+ \niib@stream\space to contain bibnotes}%
+ \immediate\openout\niib@out\niib@stream\relax
\immediate\write\niib@out{\niib@msg}%
- \fi}%
- {}%
- \if@filesw%
+ \fi}{}%
+ \if@filesw
+ \niib@log@debug{Writing bibnote #1 contents
+ \MessageBreak---\MessageBreak#2\MessageBreak---\MessageBreak
+ to BibTeX database}%
\immediate\write\niib@out{%
- @\niibrecord\string{#1,^^J%
- presort = \string{\niib@presort\string},^^J%
- \niib@keyname\space= \string{\niib@key#1\string},^^J%
- \niibfield\space= \string{\unexpanded{#2}\string}^^J%
- \string}^^J}%
- \fi%
-}
-\@ifpackageloaded{biblatex}{%
- \expandafter\bib@gadd\expandafter\blx@bibfiles\expandafter%
- {,\niibprefix\jobname}%
- }{%
- \let\niib@bib\bibliography%
- \renewcommand{\bibliography}[1]{%
- \ifnum\the\value{bibnote} > \z@%
- \niib@bib{\niibprefix\jobname,#1}%
- \else%
- \niib@bib{#1}%
- \fi}}%
-%%
+ @\niib@record\string{#1,^^J%
+ presort = \string{\niib@presort\string},^^J%
+ \niib@keyname\space= \string{\niib@key#1\string},^^J%
+ \niib@field\space= \string{\unexpanded{#2}\string}^^J%
+ \string}^^J}%
+ \fi}
+\newcommand*{\niib@headcitelist}{}
+\g@addto@macro{\document}{\niib@dochook}
+\newcommand*{\niibheadcite}[1]{%
+ \edef\niib@tempa{#1}%
+ \ifx\@empty\niib@headcitelist\@empty
+ \xdef\niib@headcitelist{\niib@tempa}%
+ \else
+ \xdef\niib@headcitelist{\niib@headcitelist,\niib@tempa}%
+ \fi
+ \if@filesw
+ \niib@log@debug{Adding citation #1 to start of .aux file}%
+ \fi
+ \g@addto@macro{\niib@dochook}{\nocite{#1}}}
+\newcommand*{\niib@dochook}{%
+ \@ifundefined{@restore@auxhandle}
+ {\newcommand*{\@restore@auxhandle}{\niib@auxhook}}
+ {\ifx\relax\@restore@auxhandle\relax
+ \newcommand*{\@restore@auxhandle}{\niib@auxhook}%
+ \else
+ \g@addto@macro{\@restore@auxhandle}{\niib@auxhook}%
+ \fi}}
+\newcommand*{\niib@auxhook}{}
+\let\niib@auxhook\relax
+\AtEndPreamble{%
+ \@ifpackageloaded{biblatex}%
+ {\expandafter\gappto\expandafter\blx@bibfiles\expandafter%
+ {,\niib@prefix\jobname}
+ \niib@log@debug{Added bibnotes database to biblatex file list}}%
+ {\let\niib@org@bib\bibliography
+ \renewcommand{\bibliography}[1]{%
+ \ifnum\the\value{bibnote} > \z@
+ \niib@org@bib{\niib@prefix\jobname,#1}%
+ \else
+ \niib@org@bib{#1}%
+ \fi}
+ \niib@log@debug{Added bibnote database to
+ \noexpand\bibliography}}}
+\newif\ifniib@rerun
+\newcommand*{\niib@checkrerun}{%
+ \niib@rerunfalse
+ \ifx\@empty\niib@headlist\@empty
+ \ifx\@empty\niib@headcitelist\@empty
+ \niib@log@debug{No `head' notes detected}%
+ \else
+ \niib@reruntrue
+ \niib@log@debug{No `head' notes found this run\MessageBreak
+ but .aux files contained the `head' requests:\MessageBreak
+ \niib@headcitelist}%
+ \fi
+ \else
+ \ifx\@empty\niib@headcitelist\@empty
+ \niib@reruntrue
+ \niib@log@debug{No `head' requests in .aux file\MessageBreak
+ but `head' notes in this run:\MessageBreak
+ \niib@headlist}%
+ \else
+ \niib@checklists%
+ \fi
+ \fi
+ \ifniib@rerun
+ \niib@log@warn{Rerun LaTeX to get correct `head' notes}%
+ \niib@log@warn{Please (re)run BibTeX on the file(s):
+ \MessageBreak\jobname.aux
+ \MessageBreak and rerun LaTeX afterwards.}%
+ \ifniib@lognone\else
+ \typeout{%
+ REQ:3:latex:REQ^^J%
+ REQ:2:bibtex:REQ^^J%
+ REQ:1:latex:REQ}%
+ \fi
+ \fi}
+\newcommand*{\niib@checklists}{%
+ \@for\niib@tempa:=\niib@headlist\do{%
+ \niib@reruntrue
+ \@for\niib@tempb:=\niib@headcitelist\do{%
+ \ifx\niib@tempa\niib@tempb
+ \niib@rerunfalse
+ \fi}
+ \ifniib@rerun
+ \niib@log@debug{Note \niib@tempa is a `head' note
+ \MessageBreak but request not in .aux file}%
+ \fi}
+ \ifniib@rerun\else
+ \@for\niib@tempa:=\niib@headcitelist\do{%
+ \niib@reruntrue
+ \@for\niib@tempb:=\niib@headlist\do{%
+ \ifx\niib@tempa\niib@tempb
+ \niib@rerunfalse
+ \fi}
+ \ifniib@rerun
+ \niib@log@debug{Note \niib@tempa is set to `head' in
+ .aux\MessageBreak file but is not a `head' note}%
+ \fi}
+ \fi}
\AtEndDocument{%
- \flushcitestack%
- \@ifundefined{niib@out}{}%
- {\immediate\closeout\niib@out}%
-}
+ \flushnotestack%
+ \niib@checkrerun%
+ \@ifundefined{niib@out}{}
+ {\immediate\closeout\niib@out%
+ \niib@log@debug{Closed BibTeX database file\MessageBreak
+ \niib@stream}}}
+\ProcessOptionsX[niib]<opt>
\endinput
%%
%% End of file `notes2bib.sty'.