diff options
author | Karl Berry <karl@freefriends.org> | 2009-09-29 00:06:35 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-09-29 00:06:35 +0000 |
commit | 65e993b3adaf9d89a85926bb68e1b62df91769fb (patch) | |
tree | a170bf3cebda605bd425a43da81c6a1268ca435a /Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx | |
parent | 90f79e4b239311b4bfef31778404320880ca3aaf (diff) |
notes2bib 2 (28sep09)
git-svn-id: svn://tug.org/texlive/trunk@15542 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx | 3319 |
1 files changed, 1617 insertions, 1702 deletions
diff --git a/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx b/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx index 9f4f9dd5646..c5683bb2ab8 100644 --- a/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx +++ b/Master/texmf-dist/source/latex/notes2bib/notes2bib.dtx @@ -1,881 +1,1078 @@ -%\iffalse meta-comment -% -% 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.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.3c or later is part of all distributions of -% LaTeX version 2005/12/01 or later. -% -% This work has the LPPL maintenance status `maintained'. -% -% The current maintainer of this work is Joseph Wright. -% -% This work consists of the file notes2bib.dtx -% xnotes2bib.dtx -% and the derived files notes2bib.pdf, -% notes2bib.sty, -% notes2bib.ins, -% xnotes2bib.pdf, -% xnotes2bib.sty and -% xnotes2bib.ins. -% -% TDS-ready files: -% The compressed file notes2bib.tds.zip contains an unpacked -% version of all of the files included here, and pre-compiled -% documentation in PDF format. Simply decompress -% notes2bib.tds.dtx in your local TeX directory, run your hash -% program (texhash, initexmf --update-fndb, etc.) and everything -% will be ready to go. The user documentation for the package is -% called notes2bib-manual.pdf; the file notes2bib.pdf includes the -% user manual and the fully-indexed source code. -% -% Unpacking: -% (a) If notes2bib.ins is present: -% tex notes2bib.ins -% (b) Without notes2bib.ins: -% tex notes2bib.dtx -% (c) If you use LaTeX to generate files: -% latex \let\install=y\input{notes2bib.dtx} -% -% Documentation: -% (a) Without write18 enabled: -% pdflatex notes2bib.dtx -% bibtex8 --wolfgang notes2bib -% makeindex -s gind.ist notes2bib.idx -% makeindex -s gglo.ist -o notes2bib.gls notes2bib.glo -% pdflatex notes2bib.dtx -% pdflatex notes2bib.dtx -% (b) With write18 enabled: -% pdflatex notes2bib.dtx -% bibtex8 --wolfgang notes2bib -% pdflatex notes2bib.dtx -% pdflatex notes2bib.dtx -% -% Installation: -% Copy notes2bib.sty to a location searched by TeX, and if -% required by your TeX installation, run the appropriate command -% to build a hash of files (texhash, initexmf --update-fndb, -% etc.) -% -% Note: -% The jawltxdoc.sty file is not needed for installation, -% only for building the documentation; it may be deleted -% after producing the documentation (if necessary). -% -%<*ignore> -% This is all taken verbatim from Heiko Oberdiek's packages -\begingroup - \def\x{LaTeX2e}% -\expandafter\endgroup -\ifcase 0\ifx\install y1\fi\expandafter - \ifx\csname processbatchFile\endcsname\relax\else1\fi - \ifx\fmtname\x\else 1\fi\relax -\else\csname fi\endcsname -%</ignore> +% \iffalse meta-comment +% !TeX program = pdflatex +%<*internal> +\iffalse +%</internal> +%<*readme> +--------------------------------------------------------------- +notes2bib --- Integrating notes into the bibliography +Maintained by Joseph Wright +E-mail: joseph.wright@morningstar2.co.uk +Released under the LaTeX Project Public License v1.3c or later +See http://www.latex-project.org/lppl.txt +--------------------------------------------------------------- + +The notes2bib package defines a new type of note, 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. + +notes2bib is written internally using LaTeX3 syntax. It +therefore requires the expl3 and xpackages packages. The e-TeX +extensions are also required. +%</readme> +%<*internal> +\fi +\def\nameofplainTeX{plain} +\ifx\fmtname\nameofplainTeX\else + \expandafter\begingroup +\fi +%</internal> %<*install> \input docstrip.tex \keepsilent \askforoverwritefalse \preamble - ---------------------------------------------------------------- - note2bib --- Integrating notes into the bibliography - Maintained by Joseph Wright - E-mail: joseph.wright@morningstar2.co.uk - Released under the LaTeX Project Public License v1.3 or later - See http://www.latex-project.org/lppl.txt - ---------------------------------------------------------------- +--------------------------------------------------------------- +notes2bib --- Integrating notes into the bibliography +Maintained by Joseph Wright +E-mail: joseph.wright@morningstar2.co.uk +Released under the LaTeX Project Public License v1.3c or later +See http://www.latex-project.org/lppl.txt +--------------------------------------------------------------- \endpreamble -\Msg{Generating notes2bib files:} -\generate{\file{jawltxdoc.sty}{\from{\jobname.dtx}{jawltxdoc}} -} +\postamble + +Copyright (C) 2007-2009 by + Joseph Wright <joseph.wright@morningstar2.co.uk> + +It may be distributed and/or modified under the conditions of +the LaTeX Project Public License (LPPL), either version 1.3c of +this license or (at your option) any later version. The latest +version of this license is in the file: + + http://www.latex-project.org/lppl.txt + +This work is "maintained" (as per LPPL maintenance status) by + Joseph Wright. + +This work consists of the file notes2bib.dtx + and the derived files notes2bib.ins, + notes2bib.pdf and + notes2bib.sty. + +\endpostamble \usedir{tex/latex/notes2bib} -\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}} +\generate{ + \file{\jobname.sty}{\from{\jobname.dtx}{package}} } +%</install> +%<install>\endbatchfile +%<*internal> \usedir{source/latex/notes2bib} -\generate{\file{\jobname.ins}{\from{\jobname.dtx}{install}} +\generate{ + \file{\jobname.ins}{\from{\jobname.dtx}{install}} } \nopreamble\nopostamble \usedir{doc/latex/notes2bib} -\generate{\file{README.txt}{\from{\jobname.dtx}{readme}} +\generate{ + \file{README.txt}{\from{\jobname.dtx}{readme}} } -\endbatchfile -%</install> -%<*readme> ----------------------------------------------------------------- -The notes2bib package --- Integrating notes into the - bibliography -Maintained by Joseph Wright -E-mail: joseph.wright@morningstar2.co.uk -Released under the LaTeX Project Public License v1.3c or later -See http://www.latex-project.org/lppl.txt ----------------------------------------------------------------- - -The notes2bib package defines a new type of note, 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. -%</readme> -%<*ignore> +\ifx\fmtname\nameofplainTeX + \expandafter\endbatchfile +\else + \expandafter\endgroup \fi -% Will Robertson's trick -\immediate\write18{bibtex8 --wolfgang \jobname} -\immediate\write18{makeindex -s gind.ist -o \jobname.ind \jobname.idx} -\immediate\write18{makeindex -s gglo.ist -o \jobname.gls \jobname.glo} -%</ignore> +%</internal> +%<*driver|package> +\RequirePackage{xparse} +%</driver|package> %<*driver> -\PassOptionsToClass{a4paper}{article} -\documentclass[german,english,UKenglish]{ltxdoc} -\EnableCrossrefs -\CodelineIndex -\RecordChanges -\OnlyDescription -\usepackage{jawltxdoc} +\documentclass[full]{l3doc} +\usepackage{csquotes,helvet,notes2bib} +\usepackage[final]{listings} +\usepackage[osf]{mathpazo} \begin{document} \DocInput{\jobname.dtx} \end{document} %</driver> -%\fi -% -%\CheckSum{881} -% -%\CharacterTable -% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z -% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z -% Digits \0\1\2\3\4\5\6\7\8\9 -% Exclamation \! Double quote \" Hash (number) \# -% Dollar \$ Percent \% Ampersand \& -% Acute accent \' Left paren \( Right paren \) -% Asterisk \* Plus \+ Comma \, -% Minus \- Point \. Solidus \/ -% Colon \: Semicolon \; Less than \< -% Equals \= Greater than \> Question mark \? -% Commercial at \@ Left bracket \[ Backslash \\ -% Right bracket \] Circumflex \^ Underscore \_ -% Grave accent \` Left brace \{ Vertical bar \| -% Right brace \} Tilde \~} -% -%\GetFileInfo{\jobname.sty} -% +% \fi +% +%\makeatletter +% +%^^A For creating examples with nice highlighting of code, and so +%^^A on; based on the system used in the listings source (lstsample). +%\lst@RequireAspects{writefile} +%\newsavebox{\LaTeXdemo@box} +%\lstnewenvironment{LaTeXdemo}[1][code and example]{^^A +% \global\let\lst@intname\@empty +% \expandafter\let\expandafter\LaTeXdemo@end +% \csname LaTeXdemo@#1@end\endcsname +% \@nameuse{LaTeXdemo@#1}^^A +%}{^^A +% \LaTeXdemo@end +%} +%\newcommand*\LaTeXdemo@new[3]{^^A +% \expandafter\newcommand\expandafter*\expandafter +% {\csname LaTeXdemo@#1\endcsname}{#2}^^A +% \expandafter\newcommand\expandafter*\expandafter +% {\csname LaTeXdemo@#1@end\endcsname}{#3}^^A +%} +%\newcommand*\LaTeXdemo@common{^^A +% \setkeys{lst}{ +% basicstyle = \small\ttfamily, +% basewidth = 0.51em, +% gobble = 3, +% keywordstyle = \color{blue}, +% language = [LaTeX]{TeX}, +% moretexcs = { +% bibnote , +% bibnotemark , +% bibnotesetup , +% bibnotetext , +% printbibnotes +% } +% }^^A +%} +%\newcommand*\LaTeXdemo@input{^^A +% \MakePercentComment +% \catcode`\^^M=10\relax +% \small +% \begingroup +% \setkeys{lst}{ +% SelectCharTable=\lst@ReplaceInput{\^\^I}{\lst@ProcessTabulator} +% }^^A +% \leavevmode +% \input{\jobname.tmp}^^A +% \endgroup +% \MakePercentIgnore +%} +%\LaTeXdemo@new{code and example}{^^A +% \setbox\LaTeXdemo@box=\hbox\bgroup +% \lst@BeginAlsoWriteFile{\jobname.tmp}^^A +% \LaTeXdemo@common +%}{^^A +% \lst@EndWriteFile +% \egroup +% \begin{center} +% \ifdim\wd\LaTeXdemo@box>0.48\linewidth\relax +% \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A +% \begin{minipage}{\linewidth} +% \LaTeXdemo@input +% \end{minipage} +% \else +% \begin{minipage}{0.48\linewidth} +% \LaTeXdemo@input +% \end{minipage} +% \hfill +% \begin{minipage}{0.48\linewidth} +% \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A +% \end{minipage} +% \fi +% \end{center} +%} +%\LaTeXdemo@new{code only}{^^A +% \LaTeXdemo@common +%}{^^A +%} +% +%\providecommand*\opt[1]{\texttt{#1}} +% +%\makeatother +% +%\GetFileInfo{\jobname.sty} +% %\changes{v1.0}{2007/08/30}{Initial public release} -%\changes{v1.1}{2007/09/29}{License changed from GPL to LPPL} -%\changes{v1.1}{2007/09/29}{\cs{Percent} macro removed} -%\changes{v1.1}{2007/09/29}{Documentation improvements} -%\changes{v1.1}{2007/09/29}{Several code sections re-factored} -%\changes{v1.1}{2007/09/29}{Improvements to documentation and -% \texttt{dtx} file} -%\changes{v1.2}{2007/10/26}{Altered implementation of \texttt{head} -% and \texttt{tail} options to allow moving of superscript -% citations} -%\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{head} -% and \opt{tail} implementation} -%\changes{v1.4}{2008/06/21}{\eTeX\ made optional (again), with -% control option to turn off use even if available} -%\changes{v1.5}{2008/09/08}{Bundle now includes experimental -% \LaTeX3 support} -%\changes{v1.6}{2008/10/21}{Fixed issue with \cs{nofiles}} -%\changes{v1.6}{2008/10/21}{Advice extended on various issues} -% -%\DoNotIndex{\@auxout,\@empty,\@fileswfalse,\@for,\@ifnextchar} -%\DoNotIndex{\@ifpackagelater,\@ifpackageloaded,\@ifundefined} -%\DoNotIndex{\@nameuse,\AtBeginDocument,\AtEndDocument} -%\DoNotIndex{\AtNextCite,\begingroup,\closeout} -%\DoNotIndex{\csname,\DeclareRobustCommand,\def,\define@boolkey} -%\DoNotIndex{\define@choicekey,\define@cmdkeys,\do,\edef,\else} -%\DoNotIndex{\endcsname,\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{\nocite,\noexpand,\openout,\PackageError,\PackageInfo} -%\DoNotIndex{\newwrite,\PackageWarning,\patchcmd,\printbibliography} -%\DoNotIndex{\ProcessOptionsX,\ProvidesPackage,\relax,\renewcommand} -%\DoNotIndex{\RequirePackage,\setkeys,\space,\stepcounter,\string} -%\DoNotIndex{\the,\typeout,\unexpanded,\value,\write,\xdef,\z@} -%\DoNotIndex{\protected@xdef,\protect} -% -%\DoNotIndex{\@bsphack,\@esphack,\@makeother,\@onelevel@sanitize} -%\DoNotIndex{\@thanks,\AtEndOfPackage} -%\DoNotIndex{\c@footnote,\catcode,\define@key,\dospecials,\global} -% -%\setkeys{lst}{language=[LaTeX]{TeX},moretexcs={bibnote,% -% bibnotemark,bibnotetext,citenote,niibsetup,newif,printbibliography}} -% -%\title{\currpkg\ --- Integrating notes into the -% bibliography^^A -% \thanks{This file describes version \fileversion, last revised -% \filedate.}} -%\author{Joseph Wright^^A -% \thanks{E-mail: joseph.wright@morningstar2.co.uk}} +%\changes{V2.0}{2009/09/24}{Second version of package using \pkg{expl3} +% internally} +% +%\title{^^A +% \pkg{notes2bib} --- Integrating notes into the bibliography^^A +% \thanks{^^A +% This file describes version \fileversion, last revised +% \filedate.^^A +% }^^A +%} +%\author{^^A +% Joseph Wright\thanks{E-mail: joseph.wright@morningstar2.co.uk}^^A +%} %\date{Released \filedate} % %\maketitle % %\begin{abstract} -% 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 \pkg{natbib} and -% \pkg{biblatex} as well as plain \LaTeX\ citations. Both sorted and -% unsorted bibliography styles are supported. +% The \pkg{notes2bib} 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 \pkg{natbib} and \pkg{biblatex} as +% well as plain \LaTeX\ citations. Both sorted and unsorted bibliography +% styles are supported. %\end{abstract} % -%\begin{multicols}{2} %\tableofcontents -%\end{multicols} % -%\section{Background} +%\begin{documentation} +% +%\section{Introduction} +% % In most subject areas, bibliographic citations and notes are % 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 -% create a notes database for each document that they write. -% -%\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. -% -% The aim of the \currpkg package is to make integration of notes +% literature and notes to be given together in a \enquote{References and +% Notes} section. By default, this requires that \BibTeX\ users +% create a notes database for each document that they write. This is +% also true if complex references are needed, which cannot be handled +% automatically. +% +% The aim of the \pkg{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. -% -%\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 \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} +% \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{Installation} +% +% The package is supplied in \file{dtx} format and as a pre-extracted +% zip file, \file{\jobname.tds.zip}. The later is most convenient for +% most users: simply unzip this in your local texmf directory and +% run \texttt{texhash} to update the database of file locations. If +% you want to unpack the \file{dtx} yourself, running +% \texttt{tex \jobname.dtx} will extract the package whereas +% \texttt{latex \jobname.dtx} will extract it and also typeset the +% documentation. +% +% The package requires \LaTeX3 support as provided in the +% \pkg{expl3} and \pkg{xpackages} bundles. Both of these are available +% on \href{http://www.ctan.org}{\textsc{ctan}} as ready-to-install +% zip files. Suitable versions are available in MiK\TeX\ 2.8 and +% \TeX\ Live 2009. The package also uses the \eTeX\ extensions: these +% are available on all modern \TeX\ systems. +% +%\section{Using the package} +% +% The package should be loaded as normal in the preamble. The package +% recognises a number of options, which can also be used in teh document +% body. These are described later in this document. +%\begin{LaTeXdemo}[code only] +% \usepackage[<options>]{notes2bib} +%\end{LaTeXdemo} +% +%\DescribeMacro \bibnote +%\begin{syntax} +% \cs{bibnote} \oarg{name} \marg{text} +%\end{syntax} +% The basic function provided by \pkg{notes2bib} is the \cs{bibnote} +% macro. This is used in exactly the same way as footnotes, taking +% a mandatory argument, the \meta{text} of the note, and an optional +% argument, a \meta{name} for the note. The \meta{text} will be saved to +% a \BibTeX\ database file for later inclusion in the bibliography, and +% a reference will be placed in the body text at the position of the +% note. +%\begin{LaTeXdemo} % 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. -% 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}. -%\end{LaTeXexample} -% -%\DescribeMacro{\bibnotemark} -%\DescribeMacro{\bibnotetext} -% 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 \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}. -%\end{LaTeXexample} -% -%\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.} -% -%\DescribeOption{footnote} -%\DescribeOption{endnotes} -% Some options control the general behaviour of \currpkg in the body -% of the \LaTeX\ source. The \opt{footnote} and \opt{endnotes} -% options control whether \cs{footnote} and \cs{endnote} macros are -% converted into bibnotes. Both are Boolean options, and are -% \defaultopt{false} by default. -%\DescribeOption{cite} -% The citation command used by \currpkg to insert bibnotes. It -% should be the name of a \LaTeX\ command (a ``csname''), and is set -% to \defaultopt{cite} on loading \currpkg; this means that \cs{cite} -% will be used as the citation command. -% -%\DescribeOption{field} -%\DescribeOption{name} -%\DescribeOption{record} -%\DescribeOption{keyword} -%\changes{v1.6}{2008/10/22}{New option \opt{keyword}} -% A number of options control the data added to the \BibTeX\ -% database. The \opt{field} and \opt{record} options control the type -% of \BibTeX\ entry created by \currpkg. On loading, \opt{record} is -% set to \defaultopt{Misc} an \opt{field} is set as -% \defaultopt{note}. Depending on the \BibTeX\ style in use, better -% choices may exist for these settings. The \opt{name} option is used -% to automatically generate citation names. The option starts with -% the value \defaultopt{Bibnote}, which may need to change for -% author--year styles in particular. For separating notes from other -% citations when using \pkg{biblatex}, the \opt{keyword} option is used -% for the name of the keyword used to control this. -%\DescribeOption{prefix} -% The name of the database itself is controlled by the \opt{prefix} -% option. This contains the ``marker'' used by \currpkg to attach to -% the job name when creating the storage database. The default is -% \defaultopt{niib-}. -% -%\DescribeOption{sort} -%\DescribeOption{head} -%\DescribeOption{tail} -% Bibnotes can be created so that thy will be sorted before or after -% normal citations. A list of values are recognised: -% \defaultopt{none} (no control of sorting), \opt{head} (notes appear -% before real citations) and \opt{tail} (notes appear after real -% citations). The shortcut options \opt{head} and \opt{tail} -% are also available. -%\DescribeOption{keyhead} -%\DescribeOption{keynone} -%\DescribeOption{keytail} -% A number of mechanisms are used to ensure correct sorting of -% bibnotes. For normal \BibTeX\ users, the options \opt{keyhead}, -% \opt{keynone} and \opt{keytail} are used to control sorting. These -% values are added to the start of the citation name in the -% \texttt{key} field, which controls sorting. The default values are -% \defaultopt{aaa}, nothing and \defaultopt{zzz}, respectively. -%\DescribeOption{presorthead} -%\DescribeOption{presortnone} -%\DescribeOption{presorttail} -% For \pkg{biblatex} users, control is made using the \opt{presort} -% system made available there. The \currpkg options -% \opt{presorthead}, \opt{presortnone} and \opt{presorttail} set up -% the appropriate values; default values are \defaultopt{ml}, -% \defaultopt{mm} and \defaultopt{ml}, respectively. -% -%\DescribeOption{writekey} -% When using the package with \pkg{natbib}, it may be necessary to avoid -% writing the \texttt{key} field to the temporary database. This is -% seen with the style \texttt{unsrtnat}, for example. The Boolean -% option \opt{writekey} is available to turn off writing the -% \texttt{key} field under these circumstances. -% -%\DescribeOption{log} -%\DescribeOption{debug} -% 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}), \defaultopt{normal}, \opt{errors} (errors -% only), \opt{none} (what it says). As a shortcut, the \opt{debug} -% option is provided as an alias to \opt{log=debug}. -%\DescribeOption{etex} -% The package has a single load-time only option, \opt{etex}. This -% is a Boolean switch, and determines whether \eTeX\ extensions are -% used if available. This is \defaultopt{true} by default; the -% intension here is for testing when sending to publishers, \etc., -% where \eTeX\ may be an issue. -% -%\subsection{Output of notes} -% Bibnotes are only printed when a bibliography is created. This -% 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 \cs{bibliography} in the source.\footnote{\LaTeX\ -% will complain if the user puts \cs{bibliography\{\}}.} The package -% 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 \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}. -%\end{LaTeXexample} -% -%\subsection{Interaction with other packages} -% \currpkg is designed to work well with as many other packages as -% possible. It has been tested with \pkg{cite}, \pkg{natbib}, -% \pkg{hyperref} and \pkg{mciteplus} with no problems. The \currpkg -% package is compatible with the current release of \pkg{biblatex} -% (v0.7); older versions of \pkg{biblatex} may or may not -% work.\footnote{As \pkg{biblatex} is experimental and is not -% currently added to \TeX\ distributions, users have little excuse -% for not using the latest release.} -% -%\section{Special effects} -%\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.\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 \currpkg does not pad the automatically-created labels with -% zeros. To get the correct sort order, \cs{thebibnote} should be -% redefined. -%\begin{LaTeXexample}[noexample] -% \makeatletter -% \renewcommand*{\thebibnote}{% -% \niib@name -% \ifnum\value{bibnote} < 9 0\fi -% \the\value{bibnote}} -% \makeatother -%\end{LaTeXexample} -% -% Using the package with \pkg{natbib} may require some work, for example -% when using the \texttt{unsrtnat} style. This requires a couple of -% setting changes to get the correct labelling.\footnote{This is due to -% the method used by \pkg{natbib} when creating labels.} -%\begin{LaTeXexample}[noexample] -% \niibsetup{writekey=false,name={}} -%\end{LaTeXexample} -% -% Notes can be separated from other citations easily using -% \pkg{biblatex}. Using the \opt{keyword} option, a key phrase can be -% used to mark notes. The optional argument to the -% \cs{printbibliography} can then be used to separate notes and -% other citations based on the keyword used. The following example -% also places note citations in the margin, and makes a switch available -% to control the appearance of notes. Note that the standard keyword is -% \opt{bibnote}. -%\begin{LaTeXexample}[noexample] -% \documentclass{article} -% \begin{filecontents}{demo.bib} -% @article{Test, -% title = {A test article}, -% author = {A. N. Other}, -% year = {2008}, -% pages = {1-10} -% } -% \end{filecontents} -% \usepackage{notes2bib,biblatex} -% \defbibheading{notes}{\section*{Notes}} -% \bibliography{demo} -% \newif\ifprintbibnotes\printbibnotesfalse -% \niibsetup{cite=mycite} -% \ifprintbibnotes -% \newcommand*{\mycite}[1]{\marginpar{\cite{#1}}} -% \else -% \newcommand*{\mycite}[1]{} -% \fi -% \begin{document} -% Some text\bibnote{A first note} and some more\bibnote{A second note}. -% A real citation \cite{Test}. -% \printbibliography[notkeyword=bibnote] -% \ifprintbibnotes -% \printbibliography[heading=notes,keyword=bibnote] -% \fi -% \end{document} -%\end{LaTeXexample} -% -%\section{Package requirements} -% The package has only one requirement, \pkg{xkeyval} version 2.5 or -% later. \eTeX\ is used if available, but is not a requirement. -% -%\section{Known issues} -% 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. -% 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} +%\end{LaTeXdemo} +% When used without the optional \meta{name} argument, each note is +% given an automatically-generated name. If notes need to be referred to +% again in a document, the optional argument avoids the need to +% understand the detail of the automated system. +%\begin{LaTeXdemo} +% An example of a named note \bibnote[labelled]{Note for the second +% example}. The text can then continue and reference the note again +% later \bibnotemark[labelled]. +%\end{LaTeXdemo} +% +% Verbatim text cannot be added directly to notes (in the same way that +% it cannot be used in footnotes). This means that the normal care +% will be needed with verbatim-like material. +%\begin{LaTeXdemo} % The next note contains some awkward text % \bibnote{Some \texttt{\textbackslash verb}-like output}. -%\end{LaTeXexample} -% -% The package relies on \BibTeX\ being able to open and process the -% temporary database containing the note text. The name of this file -% contains \cs{jobname}, the name of the main \LaTeX\ file being -% processed. This must consist only of characters that \BibTeX\ can -% handle. In particular, spaces in the file name will lead to -% problems. -% -%\bibliographystyle{unsrt} -%\renewcommand*{\refname}{Notes} -%\StopEventually{% +%\end{LaTeXdemo} +% +%\DescribeMacro \bibnotemark +%\begin{syntax} +% \cs{bibnotemark} \oarg{name} +%\end{syntax} +%\DescribeMacro \bibnotetext +%\begin{syntax} +% \cs{bibnotetext} \oarg{name} \marg{text} +%\end{syntax} +% In common with \cs{footnote}, the basic \cs{bibnote} macro has +% companion macros \cs{bibnotemark} and \cs{bibnotetext}. In contrast +% to the \LaTeXe\ kernel \cs{footnote} macro, \cs{bibnote} is naturally +% robust and so \cs{bibnotemark} and \cs{bibnotetext} should be needed +% much more rarely than the \cs{footnote} versions. +% +% As with the related \cs{footnote} functions, \cs{bibnotemark} can be +% used alone or will recognise an optional argument giving the +% \meta{name} of the note. \cs{bibnotetext} also recognises the same +% optional \meta{name} argument as well as the mandatory \meta{text}. +%\begin{LaTeXdemo} +% A note without a name \bibnotemark\ can be given with some +% text \bibnotetext{Text for the fourth example}. Note can also be +% given names \bibnotemark[named], which are then used for the +% text\bibnotetext[named]{More text for the fourth example}. +%\end{LaTeXdemo} +% +% The \cs{bibnotemark} macro can also be used to cross-reference notes +% given earlier in the document. This method is preferred for +% referencing notes over using the \cs{cite} macro as +% \cs{bibnotemark} will cope correctly with out-of-order notes +% (see Section~\ref{out-of-order}). +%\begin{LaTeXdemo} +% See notes \bibnotemark[labelled] and \bibnotemark[named]. +%\end{LaTeXdemo} +% +%\DescribeMacro \printbibnotes +%\begin{syntax} +% \cs{printbibnotes} +%\end{syntax} +% In most cases, there will be both notes and references in a document. +% The notes will be printed along with cited literature in the +% bibliography, produced using the \cs{bibliography} macro (or +% \cs{printbibliography} when using \pkg{biblatex}). However, it is +% possible to print only the notes in a document using the +% \cs{printbibnotes} macro. +% \bibliographystyle{unsrt} +%\begin{LaTeXdemo} % \printbibnotes -% \PrintChanges -% \PrintIndex} -% -%\section{The mechanism} -% The mechanism for positioning notes in the bibliography is somewhat -% 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 \pkg{endnotes} package and \REVTeX class. Both of these -% provided inspiration for this package. -% -%\subsection{The \texttt{endnotes} approach} -% 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 \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 \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 -% 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 \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 -% notes back into the document. This is achieved by modifying the -% \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 \pkg{natbib}. The method used is also not compatible with -% interspersing normal citations and notes. -% -%\subsection{The \texttt{notes2bib} approach} -% -% 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> -%\fi -%\section{The package code} +%\end{LaTeXdemo} +% +%\DescribeMacro \bibnotesetup +%\begin{syntax} +% \cs{bibnotesetup} \marg{key--value list} +%\end{syntax} +% The behaviour of \pkg{notes2bib} can be altered by setting one or +% more package options. These are given as arguments to the +% \cs{bibnotesetup} function, which takes a \meta{key--value list} and +% uses this to set up the package. With the exception of the +% \opt{file-name} option, all of the settings can be altered in the +% preamble or the document body. The various package options are +% described below. +% +%\subsection{Auto-generated note names} +% +%\DescribeOption {note-name} +% When no explicit label is given for a note, one is generated +% automatically by the package. This consists of two parts, a name and +% a number. The text of the name can be set up using the +% \opt{note-name} option. This should not contain any spaces, as +% \BibTeX\ does not support records with spaces in names. The numerical +% part of the label is always generated automatically, and is the +% number of the note. The standard setting for \opt{note-name} is +% \opt{Note}. +% +%\subsection{Underlying citation system} +% +%\DescribeOption {cite-function} +% \pkg{notes2bib} works by making the text of notes into citations. +% To do this, each note has to be \enquote{cited} in the appropriate +% place. \pkg{notes2bib} does not carry out any low-level citation +% itself: instead, a general citation macro is called. The nature of +% the function is set up using the \opt{cite-function} option, +% which should be set to a citation macro taking one mandatory +% argument. The initial setting is \opt{cite-function = \cs{cite}}. +% +%\subsection{Controlling the temporary database} +% +%\DescribeOption {file-name} +% The file name used for the database of notes is set using the +% \opt{file-name} option. The standard setting is to call the file +% |notes2bib-\jobname|, which may not be appropriate (for example, file +% names containing spaces may be problematic). Setting the +% \opt{file-name} option will alter the name of the file, with the +% file extension fixed as \file{bib}. In contrast to the other package +% options, this value can only be set in the preamble. +% +%\DescribeOption {record-type} +% Each note is written to the database as a standard \BibTeX\ record. +% The type of record created is set using the \opt{record-type} +% option. Usually, this will be set to \opt{misc}, but some \BibTeX\ +% styles have dedicated support for notes and so recognise the record +% type \opt{note} (or indeed some other value). +% +%\DescribeOption {note-field} +% The database field used to store the text of the note is available +% for change \emph{via} the \opt{note-field} option. The standard +% setting is \opt{note}. +% +%\DescribeOption {keyword-entry} +% Some styles (most notably \pkg{biblatex}) recognise keywords in +% \BibTeX\ records, stored in a \texttt{keywords} field. To allow the +% selective printing of notes, \pkg{notes2bib} includes a keyword in +% each note record. The keyword is set using the \opt{keyword-entry} +% option: the standard setting is \opt{note}. +% +%\subsection{Ordering notes in relation to citations} +%\label{out-of-order} +% +%\DescribeOption {placement} +% The standard method used by \pkg{notes2bib} places notes into the +% bibliography with no particular control of the relative position of +% notes with respect to citations. For unsorted bibliography styles, +% this will result in the notes appearing mixed in with citations. +% However, \pkg{notes2bib} can create notes so that they appear before +% or after citations, with both sorted an unsorted bibliography styles. +% This is controlled by the \opt{placement} option, which recognises +% the values \opt{before}, \opt{after} and \opt{mixed}. Setting +% \opt{placement = before} places notes before citations, with +% the \opt{after} setting forcing notes to appear after citation. +% The standard setting is \opt{placement = mixed}, which will result +% in mixing of notes and citations. +% +% When notes are placed in the bibliography without any change of order, +% it is possible to cross-reference to them using the standard \cs{cite} +% macro. However, when notes are out of the normal order this can lead +% to problems. These can be avoided by using the \cs{bibnotemark} macro +% to cross-reference notes. As this method will always work correctly, +% it is the recommended method for referencing notes under all +% circumstances. +% +%\DescribeOption {presort-before} +%\DescribeOption {presort-mixed} +%\DescribeOption {presort-after} +%\DescribeOption {sort-key-before} +%\DescribeOption {sort-key-mixed} +%\DescribeOption {sort-key-after} +% There are a number of different mechanisms used by \pkg{notes2bib} to +% achieve the desired ordering. Most standard \BibTeX\ styles recognise +% a \texttt{key} field, which can be used to override sorting by author +% or title. This is used by \pkg{notes2bib}, with the note name prefixed +% by a string to force the sort order. The appropriate strings are +% stored using the options \opt{sort-key-before}, \opt{sort-key-mixed} +% and \opt{sort-key-after}. These have standard settings +% \opt{aaa}, \opt{\meta{blank}} and \opt{zzz}, respectively. When the +% \pkg{biblatex} package is in use, a more powerful method is available +% to control sorting: the \texttt{presort} field. Data to be written +% to this field is set up using the \opt{presort-before}, +% \opt{presort-mixed} and \opt{presort-after} options. Here, the +% standard values are \opt{ml}, \opt{mm} and \opt{mn}, respectively. +% These standard values will probably be appropriate in almost all +% cases. +% +%\subsection{Converting footnotes and endnotes} +% +%\DescribeOption {convert-endnotes} +%\DescribeOption {convert-footnotes} +% It is possible to convert both \cs{footnote} and \cs{endnote} +% entries in a file into \cs{bibnote} entries in a flexible manner. +% This behaviour is controlled using the \opt{convert-endnotes} and +% \opt{convert-footnotes} options; both recognise the values +% \opt{true} and \opt{false}. The original definitions for the +% appropriate macros are stored by \pkg{notes2bib}, and so it is +% possible to switch this behaviour on and off. +% +%\DescribeMacro \thanks +% The package is designed so that converting footnotes to bibliographic +% notes will not affect the \cs{thanks} macro. Thus the option +% \opt{convert-footnotes = true} can be given before \cs{maketitle} +% with no implication for and \cs{thanks}. +% +%\subsection{Using author--date bibliography styles} +% +%\DescribeOption {use-sort-key} +% Author--date bibliography styles may not work well with the settings +% of the package as supplied. Some of the data written by +% \pkg{notes2bib} can be misunderstood by styles such as +% \file{unsrtnat}. To surpress creating a \texttt{key} field in the +% database, the option \opt{use-sort-key} should be set to \opt{false} +% with these problematic styles. At the same time, it may be necessary +% to alter the \opt{note-name} option to a blank value. +%\begin{LaTeXdemo}[code only] +% \bibnotesetup{ +% note-name = , +% use-sort-key = false +% } +%\end{LaTeXdemo} +% +%\section{Data written to the file} +% +% \pkg{notes2bib} writes some information to the \file{aux} file, so +% that it is available between runs. The functions added to the +% file are not needed directly by the user, but are documented here +% for completeness. However, it may be necessary to worry about the +% \file{aux} file when splitting bibliographies. +% +%\DescribeMacro \recordnotes +% \begin{syntax} +% \cs{recordnotes} +% \end{syntax} +% When notes are placed out-of-order in in a document (using +% \opt{placement = before} or \opt{placement = after}) \pkg{notes2bib} +% has to record information in the current \file{aux} file. When using +% multiple bibliographies, this will not necessarily happen totally +% automatically. To force \pkg{notes2bib} to write the current +% out-of-order notes to the \file{aux} file, the macro +% \cs{recordnotes} is available. It should be used immediately +% before changing between auxiliary files. +% +%\DescribeMacro \TotalNotes +%\begin{syntax} +% \cs{TotalNotes} \marg{number} +%\end{syntax} +% Records the total number of auto-numbered notes in a run. This +% information is needed to check if zero-filling is needed for the +% numbers used. +% +%\DescribeMacro \NotesAfterCitations +% \begin{syntax} +% \cs{NotesAfterCitations} \marg{note-list} +% \end{syntax} +%\DescribeMacro \NotesBeforeCitations +% \begin{syntax} +% \cs{NotesBeforeCitations} \marg{note-list} +% \end{syntax} +% These functions record the notes which have been placed outside of +% the normal order by the package. This information is used to check +% for changes in note order between \LaTeX\ runs, so that the need for +% re-running \LaTeX\ and \BibTeX\ can be detected. +% +%\section{Notes for upgrading from version one} +% +% Documents which compile with version one of \pkg{notes2bib} should +% work equally well with version two. The package recognises the +% older options and user functions (for example \cs{niibsetup}). These +% are not documented here as all new documents should use the improved +% structures provided here. As some auxiliary file functions have been +% altered, it may be necessary to delete \file{aux} files for documents +% processed initially with older versions of \pkg{notes2bib}. +% +%\end{documentation} +% +%\begin{implementation} +% +%\section{Code documentation} +% +%\subsection{Variables and constants} +% +%\begin{variable}{\c_niib_file_message_tl} +% Text written at the start of the auto-generated \file{bib} file: +% can be altered for translations, \emph{etc}. +%\end{variable} +% +%\begin{variable}{ +% \g_niib_after_clist | +% \g_niib_before_clist +%} +% Lists of notes which are out-of-order, either before or after +% citations. +%\end{variable} +% +%\begin{variable}{ +% \g_niib_all_after_clist | +% \g_niib_all_before_clist +%} +% A second list is needed for out-of-order citations so that comparisons +% work correctly even if some notes have been flushed. +%\end{variable} +% +%\begin{variable}{\g_niib_document_hook_tl} +% A token list hook added to the \cs{document} macro so that additional +% tasks can be carried out with the \file{aux} file open but before the +% document starts. +%\end{variable} +% +%\begin{variable}{\g_niib_previous_notes_int} +% The number of notes from the previous run is stored here. It is used +% to check if padding is needed for note numbers when using +% auto-generated names. +%\end{variable} +% +%\begin{variable}{\g_niib_file_stream} +% The file stream used to manage the notes database. +%\end{variable} +% +%\begin{variable}{\g_niib_note_int} +% Auto-numbered notes use this value for the note number: it is not +% implemented for notes with given names. +%\end{variable} +% +%\begin{variable}{\l_niib_presort_tl} +% The current value to be written to the \texttt{presort} field to +% enable correct ordering of notes. +%\end{variable} +% +%\begin{variable}{ +% \g_niib_previous_after_clist | +% \g_niib_previous_before_clist +%} +% Out-of-order notes from the previous run need to be recorded for +% comparison with those from the current run. This is used to flag up +% the need to re-run compilation. +%\end{variable} +% +%\begin{variable}{\g_niib_previous_notes_int} +% The number of notes from the previous run is stored here. It is used +% to check if padding is needed for note numbers when using +% auto-generated names. +%\end{variable} +% +%\begin{variable}{\l_niib_sortkey_tl} +% The current value to be written to the \texttt{key} or +% \texttt{sortkey} field as a prefix to the note name; used to ensure +% correct ordering of notes. +%\end{variable} +% +%\begin{variable}{\l_niib_sortkey_field_tl} +% The name of the field for the sorting key varies: it can be +% \texttt{key} or \texttt{sortkey}. The appropriate setting is saved +% here. +%\end{variable} +% +%\begin{variable}{\g_niib_total_notes_int} +% Every note adds one to the count here: needed to check if any notes +% are present in the document. +%\end{variable} +% +%\subsection{Storage for options} +% +%\begin{function}{\niib_cite:w} +% \begin{syntax} +% "\niib_cite:w" \marg{note-name} +% \end{syntax} +% The function used by \pkg{notes2bib} to store the citation command +% needed to cite notes. This will be a \LaTeXe\ user function, and so +% the input syntax will require one mandatory argument. +%\end{function} +% +%\begin{variable}{\g_niib_filename_tl} +% The name of the file used for the auto-generated database. +%\end{variable} +% +%\begin{variable}{\l_niib_keyword_tl} +% The keyword used to indicate records which are notes. +%\end{variable} +% +%\begin{variable}{\l_niib_note_field_tl} +% The field in the database to use for note text. +%\end{variable} +% +%\begin{variable}{\l_niib_note_name_tl} +% The prefix used when making note names automatically: will always +% be followed by number. +%\end{variable} +% +%\begin{variable}{ +% \l_niib_presort_after_tl | +% \l_niib_presort_before_tl | +% \l_niib_presort_mixed_tl | +%} +% Sorting string to be written to the \texttt{presort} field, for notes +% after, before and mixed with citations. +%\end{variable} +% +%\begin{variable}{\l_niib_record_type_tl} +% The database record type for notes. +%\end{variable} +% +%\begin{variable}{ +% \l_niib_sortkey_after_tl | +% \l_niib_sortkey_before_tl | +% \l_niib_sortkey_mixed_tl | +%} +% Sorting string to be written to the \texttt{key} or \texttt{sortkey} +% field, for notes after, before and mixed with citations. +%\end{variable} +% +%\begin{variable}{\l_niib_write_sortkey_bool} +% Flag to indicate whether \texttt{key} (or \texttt{sortkey}) field +% should be written to database. +%\end{variable} +% +%\subsection{Internal functions} +% +%\begin{function}{\niib_attach_bibliography:} +% \begin{syntax} +% "\niib_attach_bibliography:" +% \end{syntax} +% Carries out task of ensuring that note database will be included in +% those scanned for entries by \BibTeX\ (or \pkg{biber}). +%\end{function} +% +%\begin{function}{\niib_aux_hook:} +% \begin{syntax} +% "\niib_aux_hook:" +% \end{syntax} +% Hook for sorting out file switch when \pkg{cite} package is loaded +% (uses \cs{@restore@auxhandle}). +%\end{function} +% +%\begin{function}{\niib_bibliography:n} +% \begin{syntax} +% "\niib_bibliography:n" \marg{databases} +% \end{syntax} +% Saved copy of \cs{bibliography} macro as defined before +% \pkg{notes2bib} was loaded. +%\end{function} +% +%\begin{function}{ +% \niib_bibnote:nn | +% \niib_bibnote:xn +%} +% \begin{syntax} +% "\niib_bibnote:nn" \marg{note-name} \marg{text} +% \end{syntax} +% Creates a bibliography note called <note-name> and printing +% <text>. +%\end{function} +% +%\begin{function}{\niib_check_cite:} +% \begin{syntax} +% "\niib_check_cite:" +% \end{syntax} +% Checks and makes changes appropriate if the \pkg{cite} package is +% loaded. +%\end{function} +% +%\begin{function}{\niib_check_rerun:} +% \begin{syntax} +% "\niib_check_rerun:" +% \end{syntax} +% Checks if additional \LaTeX\ runs are required. +%\end{function} +% +%\begin{function}{\niib_create_print_notes:} +% \begin{syntax} +% "\niib_create_print_notes:" +% \end{syntax} +% Creates the appropriate \cs{niib_print_notes:} function at the +% start of the document. +%\end{function} +% +%\begin{function}{ +% \niib_endnote:w | +% \niib_endnotemark:w | +% \niib_endnotetext:w +%} +% \begin{syntax} +% "\niib_endnote:w" +% \end{syntax} +% Saved definitions for endnote functions, as available before +% \pkg{notes2bib} is loaded. +%\end{function} +% +%\begin{function}{\niib_filesw:} +% \begin{syntax} +% "\niib_filesw:" +% \end{syntax} +% A copy of \LaTeXe's \cs{if@filesw}. +%\end{function} +% +%\begin{function}{ \niib_flush_after_notes: } +% \begin{syntax} +% "\niib_record_notes:" +% \end{syntax} +% Clears stack of notes to appear after citations by marking them in +% the text and writing details to the \file{aux} file. +%\end{function} +% +%\begin{function}{ +% \niib_footnote:w | +% \niib_footnotemark:w | +% \niib_footnotetext:w +%} +% \begin{syntax} +% "\niib_footnote:w" +% \end{syntax} +% Saved definitions for footnote functions, as available before +% \pkg{notes2bib} is loaded. +%\end{function} +% +%\begin{function}{ +% \niib_mark_note:n | +% \niib_mark_note:x +%} +% \begin{syntax} +% "\niib_mark_note:n" \marg{note-name} +% \end{syntax} +% Marks the position of <note-name> in the text. +%\end{function} +% +%\begin{function}{ +% \niib_mark_note_after:n | +% \niib_mark_note_before:n | +% \niib_mark_note_mixed:n | +%} +% \begin{syntax} +% "\niib_mark_note_after:n" \marg{note-name} +% \end{syntax} +% Marks the position of <note-name> in the text, with appropriate +% control of note positioning in bibliography. +%\end{function} +% +%\begin{function}{\niib_note_name:} +% \begin{syntax} +% "\niib_note_name:" +% \end{syntax} +% Prints the name of a note using the current automatic note number +% and prefix text. +%\end{function} +% +%\begin{function}{\niib_print_notes:} +% \begin{syntax} +% "\niib_print_notes:" +% \end{syntax} +% Prints all bibliography notes currently defined. +%\end{function} +% +%\begin{function}{ +% \niib_save_endnote: | +% \niib_save_footnote: +%} +% \begin{syntax} +% "\niib_save_endnote:" +% \end{syntax} +% Saves current definitions for endnote and footnote functions for +% later recovery. +%\end{function} +% +%\begin{function}{\niib_set_cite_after:} +% \begin{syntax} +% "\niib_set_cite_after:" +% \end{syntax} +% Sets up function for including notes after citations, appropriate to +% the other packages loaded. +%\end{function} +% +%\begin{function}{\niib_set_sortkey_name:} +% \begin{syntax} +% "\niib_set_sortkey_name:" +% \end{syntax} +% Sets up name for sort key, appropriate to the other packages loaded. +%\end{function} +% +%\begin{function}{\niib_stream_check:} +% \begin{syntax} +% "\niib_stream_check:" +% \end{syntax} +% Checks that a stream is open to write notes into: one is opened if +% not. +%\end{function} +% +%\begin{function}{ +% \niib_to_bibnote:n | +% \niib_from_bibnote:n +%} +% \begin{syntax} +% "\niib_to_bibnote:n" \marg{note-type} +% \end{syntax} +% Convert notes of <note-type> to and from bibliography notes. +%\end{function} +% +%\begin{function}{ +% \niib_write_field:nn | +% \niib_write_field:Vn +%} +% \begin{syntax} +% "\niib_write_field:nn" \marg{field} \marg{text} +% \end{syntax} +% Sets up formatting to write <text> to database <field>. +%\end{function} +% +%\begin{function}{ +% \niib_write_note:nn | +% \niib_write_note:xn +%} +% \begin{syntax} +% "\niib_write_note:nn" \marg{note-name} \marg{text} +% \end{syntax} +% Writes <text> of <note-name> to database. +%\end{function} +% +%\begin{function}{\niib_write_total_notes:} +% \begin{syntax} +% "\niib_write_total_notes:" +% \end{syntax} +% Records total number of auto-numbered notes to the \texttt{aux} file. +%\end{function} +% +%\section{Implementation} % -%\subsection{Package setup code} -%\changes{v1.1}{2007/09/29}{Removed use of \pkg{xspace}} -% The package starts with the usual identification code and support -% loading. % \begin{macrocode} -\NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{notes2bib} - [2008/10/31 v1.6a Integrating notes into the bibliography] -\RequirePackage{xkeyval}[2005/05/07] +%<*package> % \end{macrocode} -%\begin{macro}{\niib@tempa} -%\begin{macro}{\niib@tempb} -% Some private temporary macros are declared. -% \begin{macrocode} -\newcommand*{\niib@tempa}{} -\newcommand*{\niib@tempb}{} +% +% Version data to start with. +% \begin{macrocode} +\ProvidesExplPackage + {notes2bib} {2009/09/28} {2.0} + {Integrating notes into the bibliography} +\RequirePackage{l3keys2e} +% \end{macrocode} +% +%\subsection{Variables and constants} +% +%\begin{macro}{\c_niib_file_message_tl} +% A short piece of text that is added to the top of an auto-generated +% file. Setting this up as a constant means that it can be changed +% (for example for translation) if necessary. +% \begin{macrocode} +\tl_new:Nn \c_niib_file_message_tl { + This~is~an~auxiliary~file~used~by~the~`notes2bib'~package. + \iow_newline: + This~file~may~safely~be~deleted. + \iow_newline: + It~will~be~recreated~as~required. + \iow_newline: +} % \end{macrocode} %\end{macro} -%\end{macro} % -%\subsection{Logging} -%\begin{macro}{\ifniib@debug} -%\begin{macro}{\ifniib@logmin} -%\begin{macro}{\ifniib@lognone} -% To control logging, some new switches are declared. +%\begin{macro}{\g_niib_after_clist} +%\begin{macro}{\g_niib_before_clist} +% Notes to be placed either before or after citations need to be tracked +% by the module. Simple comma lists will achieve this. % \begin{macrocode} -\newif\ifniib@debug -\newif\ifniib@logmin -\newif\ifniib@lognone +\clist_new:N \g_niib_after_clist +\clist_new:N \g_niib_before_clist % \end{macrocode} %\end{macro} %\end{macro} -%\end{macro} -%\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{macro}{\g_niib_all_after_clist} +%\begin{macro}{\g_niib_all_before_clist} +% As notes after citations can be flushed, there is a need for a second +% list which is never emptied. % \begin{macrocode} -\newcommand*{\niib@log@debug}[1]{% - \ifniib@lognone\else - \ifniib@debug - \PackageInfo{notes2bib}{#1}% - \fi - \fi} +\clist_new:N \g_niib_all_after_clist +\clist_new:N \g_niib_all_before_clist % \end{macrocode} %\end{macro} %\end{macro} -%\end{macro} % -%\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{macro}{\g_niib_note_int} +% A counter for the automatically-created notes is needed. This is a +% global value (life will get very complicated if not). % \begin{macrocode} -\newcommand*{\niib@opt@boolkey}[2][]{% - \define@boolkey[niib]{opt}[niib@]{#2}[true] - {#1\niib@log@debug{Option #2 set to ##1}}} +\int_new:N \g_niib_note_int % \end{macrocode} %\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{macro}{\l_niib_presort_tl} +%\begin{macro}{\l_niib_sortkey_tl} +% The text used for sorting citations is stored here: it is never set +% directly, as it depends on the type of sorting taking place. % \begin{macrocode} -\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}}} +\tl_new:N \l_niib_presort_tl +\tl_new:N \l_niib_sortkey_tl % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@opt@cmdkeys} -% A shortcut for \pkg{xkeyval} command keys. -% \begin{macrocode} -\newcommand*{\niib@opt@cmdkeys}[1]{% - \define@cmdkeys[niib]{opt}[niib@]{#1}} -% \end{macrocode} %\end{macro} -%\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{macro}{\g_niib_previous_after_clist} +%\begin{macro}{\g_niib_previous_before_clist} +% For comparison purposes, the lists of out-of-order notes from the +% previous \LaTeX\ run are needed. % \begin{macrocode} -\newcommand*{\niibsetup}{\setkeys[niib]{opt}} +\clist_new:N \g_niib_previous_after_clist +\clist_new:N \g_niib_previous_before_clist % \end{macrocode} %\end{macro} -% 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} -%\begin{macro}{\niib@opt@debug} -% A quick method to set \opt{log=debug}. -% \begin{macrocode} -\niib@opt@boolkey{debug} -% \end{macrocode} %\end{macro} -%\begin{macro}{\ifniib@footnotes} -%\begin{macro}{\ifniib@endnotes} -% The \opt{footnote} and \opt{endnote} options are declared here. +% +%\begin{macro}{\g_niib_previous_notes_int} +% The total number of notes created is needed, as this is used to see +% if any zero-padding is required for the numbers. Of course, for this +% to work there has to be a second \LaTeX\ run. % \begin{macrocode} -\niib@opt@boolkey[\niib@swapfoot]{footnotes} -\niib@opt@boolkey[\niib@swapend]{endnotes} +\int_new:N \g_niib_previous_notes_int % \end{macrocode} %\end{macro} -%\end{macro} -%\begin{macro}{\ifniib@head} -%\begin{macro}{\ifniib@tail} -% Switches are needed for placing notes before and after normal -% citations. +% +%\begin{macro}{\l_niib_sortkey_field_tl} +% The key for sorting is called \texttt{key} by standard \BibTeX\ and +% \texttt{sortkey} by \pkg{biblatex}. It keeps everything clearer if +% the appropriate name is stored in a token list. The value itself is +% set up later. % \begin{macrocode} -\newif\ifniib@tail -\newif\ifniib@head +\tl_new:N \l_niib_sortkey_field_tl % \end{macrocode} %\end{macro} -%\end{macro} -% 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. -% \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} -% The back-compatibility code; unlike earlier versions, this will -% take whatever the \opt{sort}-type key is given. +% +%\begin{macro}{\g_niib_total_notes_int} +% Tracks the total number of notes created, so that the module can tell +% if any have been used. % \begin{macrocode} -\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} +\int_new:N \g_niib_total_notes_int % \end{macrocode} -%\begin{macro}{\niib@writekey} -%\changes{v1.6}{2008/10/21}{Added \opt{writekey} option} -% Control of writing \texttt{key} to disk. +%\end{macro} +% +%\subsection{Control options} +% +%\begin{macro}{\niib_cite:w} +% The underlying function for citation starts off with no value: +% this is then set up by the key--value settings given next. % \begin{macrocode} -\niib@opt@boolkey{writekey} +\cs_new_nopar:Nn \niib_cite:w { } % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@cite} -%\begin{macro}{\niib@name} -%\begin{macro}{\niib@prefix} -%\begin{macro}{\niib@record} -%\begin{macro}{\niib@field} -%\begin{macro}{\niib@presorthead} -%\begin{macro}{\niib@presortnone} -%\begin{macro}{\niib@presorttail} -%\begin{macro}{\niib@keyhead} -%\begin{macro}{\niib@keynone} -%\begin{macro}{\niib@keytail} -%\begin{macro}{\niib@keyword} -% The various internal control values are set up as command keys. +% +%\begin{macro}{\g_niib_filename_tl} +%\begin{macro}{\l_niib_keyword_tl} +%\begin{macro}{\l_niib_note_field_tl} +%\begin{macro}{\l_niib_note_name_tl} +%\begin{macro}{\l_niib_presort_after_tl} +%\begin{macro}{\l_niib_presort_before_tl} +%\begin{macro}{\l_niib_presort_mixed_tl} +%\begin{macro}{\l_niib_record_type_tl} +%\begin{macro}{\l_niib_sortkey_after_tl} +%\begin{macro}{\l_niib_sortkey_before_tl} +%\begin{macro}{\l_niib_sortkey_mixed_tl} +%\begin{macro}{\l_niib_write_sortkey_bool} +% The various package options are created. % \begin{macrocode} -\niib@opt@cmdkeys{% - cite, - name, - prefix, - record, - field, - presorthead, - presortnone, - presorttail, - keyhead, - keynone, - keytail, - keyword} -\niibsetup{ - cite=cite, - name=Bibnote, - prefix=niib-, - record=Misc, - field=note, - presorthead=ml, - presortnone=mm, - presorttail=mn, - keyhead=aaa, - keynone={}, - keytail=zzz, - keyword=bibnote, - writekey=true} +\keys_define:nn { notes2bib } { + cite-function .code:n = { + \AtBeginDocument { \cs_set_eq:NN \niib_cite:w #1 } + } , + file-name .tl_gset_x:N = \g_niib_filename_tl , + convert-endnotes .choice: , + convert-endnotes / false .code:n = { + \AtBeginDocument { \niib_from_bibnote:n { endnote } } + }, + convert-endnotes / true .code:n = { + \AtBeginDocument { \niib_to_bibnote:n { endnote } } + }, + convert-footnotes .choice: , + convert-footnotes / false .code:n = { + \AtBeginDocument { \niib_from_bibnote:n { footnote } } + }, + convert-footnotes / true .code:n = { + \AtBeginDocument { \niib_to_bibnote:n { footnote } } + }, + keyword-entry .tl_set:N = \l_niib_keyword_tl , + note-field .tl_set:N = \l_niib_note_field_tl , + note-name .tl_set:N = \l_niib_note_name_tl , + placement .choice: , + placement / after .code:n = { + \cs_set_eq:NN \niib_mark_note:n \niib_mark_note_after:n + \tl_set_eq:NN \l_niib_presort_tl \l_niib_presort_after_tl + \tl_set_eq:NN \l_niib_sortkey_tl \l_niib_sortkey_after_tl + } , + placement / before .code:n = { + \cs_set_eq:NN \niib_mark_note:n \niib_mark_note_before:n + \tl_set_eq:NN \l_niib_presort_tl \l_niib_presort_before_tl + \tl_set_eq:NN \l_niib_sortkey_tl \l_niib_sortkey_before_tl + }, + placement / mixed .code:n = { + \cs_set_eq:NN \niib_mark_note:n \niib_mark_note_mixed:n + \tl_set_eq:NN \l_niib_presort_tl \l_niib_presort_mixed_tl + \tl_set_eq:NN \l_niib_sortkey_tl \l_niib_sortkey_mixed_tl + }, + presort-after .tl_set:N = \l_niib_presort_after_tl , + presort-before .tl_set:N = \l_niib_presort_before_tl , + presort-mixed .tl_set:N = \l_niib_presort_mixed_tl , + record-type .tl_set:N = \l_niib_record_type_tl , + sort-key-after .tl_set:N = \l_niib_sortkey_before_tl , + sort-key-before .tl_set:N = \l_niib_sortkey_after_tl , + sort-key-mixed .tl_set:N = \l_niib_sortkey_mixed_tl , + use-sort-key .bool_set:N = \l_niib_write_sortkey_bool, +} % \end{macrocode} %\end{macro} %\end{macro} @@ -889,1017 +1086,735 @@ unsorted bibliography styles are supported. %\end{macro} %\end{macro} %\end{macro} -%\begin{macro}{\ifniib@etex} -% The option to turn off \eTeX\ needs to ensure that the user does -% not ask for \eTeX\ if it is not there. On the other hand, the -% default is to use \eTeX\ if it is available. -% \begin{macrocode} -\niib@opt@boolkey{etex} -\begingroup - \@ifundefined{eTeXversion} - {} - {\global\niib@etextrue} -\endgroup -% \end{macrocode} -%\end{macro} % -%\subsection{Footnote and endnote handling} -%\begin{macro}{\niib@org@footnote} -%\changes{v1.3c}{2008/02/26}{Saved in package} -%\begin{macro}{\niib@org@footnotemark} -%\changes{v1.3c}{2008/02/26}{Saved in package} -%\begin{macro}{\niib@org@footnotetext} -%\changes{v1.3c}{2008/02/26}{Saved in package} -% To allow dynamic handling of footnotes and endnotes, the original -% definitions are backed up. +% Default values for the keys are set up. Many of these probably never +% change, but done in this way the package is much more flexible. % \begin{macrocode} -\let\niib@org@footnote\footnote -\let\niib@org@footnotemark\footnotemark -\let\niib@org@footnotetext\footnotetext +\keys_set:nn { notes2bib } { + cite-function = \cite , + file-name = notes2bib-\jobname , + keyword-entry = note , + note-field = note , + note-name = Note , + presort-after = mn , + presort-before = ml , + presort-mixed = mm , + record-type = misc , + sort-key-after = zzz , + sort-key-before = aaa , + use-sort-key = true +} % \end{macrocode} -%\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} -\AtBeginDocument{ - \@ifpackageloaded{endnotes} - {\let\niib@org@endnote\endnote - \let\niib@org@endnotemark\endnotemark - \let\niib@org@endnotetext\endnotetext - \let\niib@org@theendnotes\theendnotes}{}} +% +% A few options need to be altered or deactivated at the start of +% the document. +% \begin{macrocode} +\cs_set_nopar:Nn \niib_options_redefine: { + \keys_define:nn { notes2bib } { + cite-function .code:n = { + \cs_set_eq:NN \niib_cite:w ##1 + } , + file-name .code:n = { + \msg_info:nnn { notes2bib } { preamble-only } { file-name } + } , + convert-endnotes / false .code:n = { + \niib_from_bibnote:n { endnote } + }, + convert-endnotes / true .code:n = { + \niib_to_bibnote:n { endnote } + }, + convert-footnotes / false .code:n = { + \niib_from_bibnote:n { footnote } + }, + convert-footnotes / true .code:n = { + \niib_to_bibnote:n { footnote } + }, + } +} +\msg_new:nnn { notes2bib } { preamble-only } {% + The option `#1' can only be used in the preamble.% +} +\AtBeginDocument { \niib_options_redefine: } +% \end{macrocode} +% +%\subsection{Options from version one} +% +% The new option names are preferred, but the old ones still need to +% work correctly. +% \begin{macrocode} +\keys_define:nn { notes2bib } { + cite .meta:x = { cite-function = \exp_not:c {#1} } , + debug .code:n = { } , + endnotes .meta:n = { convert-footnotes = #1 } , + etex .code:n = { } , + field .meta:n = { note-field = #1 } , + footnotes .meta:n = { convert-footnotes = #1 } , + head .meta:n = { placement = before } , + keyhead .meta:n = { sort-key-before = #1 } , + keytail .meta:n = { sort-key-after = #1 } , + keynone .meta:n = { sort-key-mixed = #1 } , + keyword .meta:n = { keyword-entry = #1 } , + log .meta:n = { } , + name .meta:n = { note-name = #1 } , + prefix .meta:n = { file-name = #1 \jobname } , + presorthead .meta:n = { presort-before = #1 } , + presorttail .meta:n = { presort-after = #1 } , + presortnone .meta:n = { presort-mixed = #1 } , + record .meta:n = { record-type = #1 } , + sort .choice: , + sort / head .meta:n = { placement = before } , + sort / none .meta:n = { placement = after } , + sort / tail .meta:n = { placement = mixed } , + tail .meta:n = { placement = after } , + writekey .meta:n = { use-sort-key = #1 } +} +% \end{macrocode} +% +%\subsection{Utility functions} +% +%\begin{macro}{\niib_note_name:} +% When note citations are generated automatically, the text to indicate +% a note plus the number of the current note needs to be turned into +% something printable. The value tests here mean that if there are more +% than nine notes, notes 1--9 have the number padded to get proper +% sorting. This needs two passes, as the total number of notes is only +% available at the end of the \LaTeX\ run. +% \begin{macrocode} +\cs_new_nopar:Nn \niib_note_name: { + \tl_use:N \l_niib_note_name_tl + \intexpr_compare:nT { \g_niib_previous_notes_int > \c_nine } { + \intexpr_compare:nT { \g_niib_note_int < \c_ten } { + 0 + } + } + \int_to_arabic:n { \g_niib_note_int } +} % \end{macrocode} %\end{macro} -%\end{macro} -%\end{macro} -%\end{macro} -%\begin{macro}{\thanks} -%\changes{v1.3c}{2008/02/26}{Altered redefinition method} -%\changes{v1.3c}{2008/02/26}{Redefinition in preamble} -% The \cs{thanks} macro is redefined. +% +%\begin{macro}{\niib_filesw:} +% Making sorting work means messing about with \cs{if@filesw}. The +% function created here is used to store the current status of the +% flag. % \begin{macrocode} -\@ifundefined{thanks}{} - {\renewcommand*{\thanks}[1]{% - \niib@org@footnotemark - \protected@xdef\@thanks{\@thanks - \protect\niib@org@footnotetext[\the\c@footnote]{#1}}}} +\cs_new_nopar:Nn \niib_filesw: { } % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@swapfoot} -%\changes{v1.3c}{2008/02/26}{Simplified code} -%\begin{macro}{\footnote} -%\begin{macro}{\footnotemark} -%\begin{macro}{\footnotetext} -% The swapping code can now be implemented. +% +%\subsection{Marking notes in the text} +% +%\begin{macro}{\niib_mark_note:n} +%\begin{macro}{\niib_mark_note:x} +% The function to mark note positions is initially declared with no +% expansion. The real meaning will be set by the key--value setting, +% and depends on the placement of notes compared with real citations. % \begin{macrocode} -\newcommand*{\niib@swapfoot}{% - \ifniib@footnotes - \let\footnote\bibnote - \let\footnotemark\bibnotetext - \let\footnotetext\bibnotemark - \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} -\AtBeginDocument{\niib@swapfoot} +\cs_new:Nn \niib_mark_note:n { } +\cs_generate_variant:Nn \niib_mark_note:n { x } % \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{macro}{\niib_mark_note_after:n} +%\begin{macro}[aux]{\niib_mark_note_after_aux:n} +% For notes which come after citations, the entry is recorded and an +% auxiliary is called. The nature of the second function is dependent +% on the other packages loaded. % \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}}} +\cs_new:Nn \niib_mark_note_after:n { + \int_gincr:N \g_niib_total_notes_int + \clist_gput_right:Nx \g_niib_after_clist {#1} + \niib_mark_note_after_aux:n {#1} +} +\cs_new:Nn \niib_mark_note_after_aux:n { } % \end{macrocode} %\end{macro} %\end{macro} -%\end{macro} -%\end{macro} -%\end{macro} -% Options can now be processed. -% \begin{macrocode} -\ProcessOptionsX[niib]<opt> -\AtEndOfPackage{ - \define@key[niib]{opt}{etex} - {\niib@log@warn{Option `etex' only available - \MessageBreak when loading notes2bib}}} -\begingroup - \@ifundefined{eTeXversion} - {\ifniib@etex - \niib@log@warn{e-TeX unavailable}% - \global\niib@etexfalse - \fi} - {\ifniib@etex\else - \niib@log@inf{Use of e-TeX disabled}% - \fi} -\endgroup -% \end{macrocode} % -%\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{macro}{\niib_mark_note_before:n} +% Notes to appear before all citations are simple recorded, as they will +% be set up on the next \LaTeX\ run. % \begin{macrocode} -\newcounter{bibnote} -\renewcommand*{\thebibnote}{\niib@name\the\value{bibnote}} +\cs_new:Nn \niib_mark_note_before:n { + \int_gincr:N \g_niib_total_notes_int + \clist_gput_right:Nx \g_niib_before_clist {#1} + \niib_cite:w {#1} +} % \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 -% \cs{niib@bibnote}. +% +%\begin{macro}{\niib_mark_note_mixed:n} +% Mixed citations are very easy to handle: just use whatever cite +% command is current. % \begin{macrocode} -\DeclareRobustCommand*{\bibnote}{% - \stepcounter{bibnote}% - \@ifnextchar[%] - {\niib@bibnote} - {\niib@bibnote[\thebibnote]}} +\cs_new:Nn \niib_mark_note_mixed:n { + \int_gincr:N \g_niib_total_notes_int + \niib_cite:w {#1} +} % \end{macrocode} %\end{macro} -%\begin{macro}{\bibnotemark} -%\changes{v1.1}{2007/09/29}{Macro made robust} -% The \cs{bibnotemark} macro works in the same way as \cs{bibnote}, -% but calls \cs{niib@mark} rather than \cs{niib@bibnote}. +% +%\subsection{Writing note text to the database} +% +%\begin{macro}{\niib_stream_check:} +%\begin{macro}{\g_niib_file_stream} +% All notes are written to a temporary file. This is only opened if +% necessary, as this means that \pkg{notes2bib} can be loaded +% \enquote{silently} in classes, \emph{etc}. The file name +% is variable, but the extension is always \file{.bib}. % \begin{macrocode} -\DeclareRobustCommand*{\bibnotemark}{% - \stepcounter{bibnote}% - \@ifnextchar[%] - {\niib@mark} - {\niib@mark[\thebibnote]}} +\cs_new_nopar:Nn \niib_stream_check: { + \cs_if_free:NT \g_niib_file_stream { + \iow_new:N \g_niib_file_stream + \iow_open:Nn \g_niib_file_stream { \g_niib_filename_tl .bib } + \iow_now:Nx \g_niib_file_stream { \c_niib_file_message_tl } + } +} % \end{macrocode} %\end{macro} -%\begin{macro}{\bibnotetext} -%\changes{v1.1}{2007/09/29}{Macro made robust} -% The text companion to the mark macro above, with no increment of -% the counter. There is nothing special to do, so the \LaTeX\ kernel -% handling of optional arguments can be used. +%\end{macro} +% +%\begin{macro}{\niib_write_field:nn} +%\begin{macro}{\niib_write_field:Vn} +% To keep the auto-generated database readable, there needs to be some +% formatting. This is provided by using a dedicated function to +% write the various fields to it. Although the \texttt{V} variant is +% not technically needed (writing expands everything), it helps to keep +% the intention of the code here clearer. % \begin{macrocode} -\DeclareRobustCommand*{\bibnotetext}[1][\thebibnote]{% - \let\niib@next\niib@gobble - \niib@text{#1}} +\cs_new:Nn \niib_write_field:nn { + \iow_space: \iow_space: #1 \iow_space: = \iow_space: {#2} , + \iow_newline: +} +\cs_generate_variant:Nn \niib_write_field:nn { V } % \end{macrocode} %\end{macro} -%\begin{macro}{\printbibnotes} -%\changes{v1.1}{2007/09/29}{Macro made robust} -%\changes{v1.3b}{2008/01/16}{Definition moved to beginning of -% document} -% To allow for the possibility of there being no other notes, a -% command to print only notes is given. In the \pkg{biblatex} case, -% the best that can be done is to issue \cs{printbibliography}. +%\end{macro} +% +%\begin{macro}{\niib_write_note:nn} +%\begin{macro}[aux]{\niib_write_note_aux:nn} +%\begin{macro}{\niib_write_note:xn} +% The writing function takes two arguments: the name of the note, and +% the text itself. There is a need to check on the \LaTeXe\ system to +% turn off writing, with a hand-over so there is no problem with +% balancing ifs. % \begin{macrocode} -\AtBeginDocument{ - \@ifpackageloaded{biblatex} - {\let\printbibnotes\printbibliography} - {\DeclareRobustCommand*{\printbibnotes} - {\niib@org@bib{\niib@prefix\jobname}}}} +\cs_new_nopar:Npn \niib_write_note:nn { + \if@filesw + \exp_after:wN \niib_write_note_aux:nn + \fi: +} +\cs_new:Nn \niib_write_note_aux:nn { + \niib_stream_check: + \iow_now:Nx \g_niib_file_stream { + @ \l_niib_record_type_tl { + #1 , \iow_newline: + \niib_write_field:Vn \l_niib_note_field_tl { \exp_not:n {#2} } + \bool_if:NT \l_niib_write_sortkey_bool { + \niib_write_field:Vn \l_niib_sortkey_field_tl + { \l_niib_sortkey_tl #1 } + } + \niib_write_field:nn { keywords } { \l_niib_keyword_tl } + \niib_write_field:nn { presort } { \l_niib_presort_tl } + } + } +} +\cs_generate_variant:Nn \niib_write_note:nn { x } % \end{macrocode} +%\end{macro} %\end{macro} -%\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}} -%\changes{v1.3b}{2008/01/16}{Writes stack to \ext{aux} file} -%\changes{v1.3b}{2008/01/16}{Added check for correct \opt{tail} -% citations in \ext{aux} file} -% 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 \ext{aux} file. This -% is done here, and the stack is cleared so collection can begin -% again. +%\end{macro} +% +%\subsection{Handling out of order notes} +% +%\begin{macro}{\niib_record_notes:} +%\begin{macro}[aux]{\niib_flush_notes_aux:} +% Notes after citations are not written to the \file{aux} file when +% given, but are held in a queue. This is flushed here, which means +% actually doing the citation and also recording the notes so they +% are available in the next \LaTeX\ run. The list is also transferred +% to a secondary one, which is used for comparison purposes right at the +% end of the document. % \begin{macrocode} -\DeclareRobustCommand*{\flushnotestack}{% - \let\niib@taillist\niib@stack - \ifniib@rerun\else - \niib@checkrerun{tail}% +\cs_new_nopar:Nn \niib_record_notes: { + \if@filesw + \exp_after:wN \niib_flush_notes_aux: \fi - \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}% - \if@filesw - \immediate\write\@auxout{% - \string\niibtailcite{\niib@stack}}% - \fi - \expandafter\nocite\expandafter{\niib@stack}% - \gdef\niib@stack{}% - \fi} +} +\cs_new_nopar:Nn \niib_flush_notes_aux: { + \clist_if_empty:NF \g_niib_before_clist { + \iow_now:Nx \@auxout { + \NotesBeforeCitations { \exp_not:V \g_niib_before_clist } + } + \clist_gput_right:NV \g_niib_all_before_clist \g_niib_before_clist + \clist_gclear:N \g_niib_before_clist + } + \clist_if_empty:NF \g_niib_after_clist { + \iow_now:Nx \@auxout { + \NotesAfterCitations { \exp_not:V \g_niib_after_clist } + } + \exp_args:NV \nocite \g_niib_after_clist + \clist_gput_right:NV \g_niib_all_after_clist \g_niib_after_clist + \clist_gclear:N \g_niib_after_clist + } +} % \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.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. +%\end{macro} +% +%\subsection{Interchanging note types} +% +%\begin{macro}{\niib_to_bibnote:n} +% Converting other notes to bibliography notes is simple: just set +% them equal. % \begin{macrocode} -\DeclareRobustCommand*{\citenote}[1]{\niib@mark[#1]} +\cs_new_nopar:Nn \niib_to_bibnote:n { + \cs_set_eq:cN {#1} \bibnote + \cs_set_eq:cN { #1 mark } \bibnotemark + \cs_set_eq:cN { #1 text } \bibnotetext +} % \end{macrocode} %\end{macro} % -%\subsection{Internal macros} -%\begin{macro}{\niib@keyname} -%\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{macro}{\niib_from_bibnote:n} +% The reverse process needs the original definitions, which are saved +% by the module for later recovery. % \begin{macrocode} -\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}}} +\cs_new_nopar:Nn \niib_from_bibnote:n { + \cs_set_eq:cc {#1} { niib_ #1 :w } + \cs_set_eq:cc { #1 mark } { niib_ #1 mark:w } + \cs_set_eq:cc { #1 text } { niib_ #1 text:w } +} % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@presort} -%\changes{v1.3}{2008/01/08}{Dynamic rather than static definition} -%\begin{macro}{\niib@key} -%\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{macro}{\niib_save_endnote:} +%\begin{macro}{\niib_endnote:w} +%\begin{macro}{\niib_endnotemark:w} +%\begin{macro}{\niib_endnotetext:w} +%\begin{macro}{\niib_save_footnote:} +%\begin{macro}{\niib_footnote:w} +%\begin{macro}{\niib_footnotemark:w} +%\begin{macro}{\niib_footnotetext:w} +% At the start of the document, the definitions for endnotes and +% footnotes are saved so that footnotes and endnotes can be turned into +% bibliography notes and back again. % \begin{macrocode} -\newcommand*{\niib@presort}{% - \ifniib@head - \niib@presorthead - \else - \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} +\cs_new_nopar:Nn \niib_save_endnote: { + \cs_set_eq:NN \niib_endnote:w \endnote + \cs_set_eq:NN \niib_endnotemark:w \endnotemark + \cs_set_eq:NN \niib_endnotetext:w \endnotetext +} +\cs_new_nopar:Nn \niib_save_footnote: { + \cs_set_eq:NN \niib_footnote:w \footnote + \cs_set_eq:NN \niib_footnotemark:w \footnotemark + \cs_set_eq:NN \niib_footnotetext:w \footnotetext +} +\AtBeginDocument { + \niib_save_endnote: + \niib_save_footnote: +} % \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. -% \begin{macrocode} -\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} -% \end{macrocode} %\end{macro} -%\begin{macro}{\niib@stack} -% This macro is needed to store any citations at the end of the -% bibliography. Initially, this is empty. -% \begin{macrocode} -\newcommand*{\niib@stack}{} -% \end{macrocode} %\end{macro} -%\begin{macro}{\niib@addtostack} -%\changes{v1.3}{2008/01/08}{Macro renamed from \cs{niib@stackup}} -% 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} -\newcommand*{\niib@addtostack}[1]{% - \niib@log@debug{Adding citation #1\MessageBreak to `tail' - 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} %\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} -\long\def\niib@bibnote[#1]#2{% - \let\niib@next\niib@mark - \niib@text{#1}{#2}} -% \end{macrocode} %\end{macro} -%\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} -\newcommand*{\niib@headlist}{} -% \end{macrocode} %\end{macro} -%\begin{macro}{\niib@mark} -% 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@mark[#1]{% - \ifniib@head - \edef\niib@tempa{#1}% - \ifx\@empty\niib@headlist\@empty - \xdef\niib@headlist{\niib@tempa}% - \else - \xdef\niib@headlist{\niib@headlist,\niib@tempa}% - \fi - \if@filesw - \niib@log@debug{Adding citation #1 to list for next run}% - \immediate\write\@auxout{\string\niibheadcite{#1}}% - \fi - \fi -% \end{macrocode} -% When the \opt{sort=tail} option is active, citation is handled by -% another macro, so a switch is needed. -% \begin{macrocode} - \ifniib@tail - \expandafter\niib@tailcite% - \else - \expandafter\niib@normcite% - \fi - {#1}} -% \end{macrocode} %\end{macro} -%\begin{macro}{\ifniib@filesw} -% A switch is used to back up \cs{if@filesw}. +% +%\subsection{Package-dependent code} +% +%\begin{macro}{\niib_create_print_notes:} +%\begin{macro}[aux]{\niib_create_print_notes_aux:} +%\begin{macro}{\niib_print_notes:} +% The method for printing notes depends on whether \pkg{biblatex} is +% in use. If it is, then a selective call to \cs{printbibliography} is +% made. Otherwise, the original \cs{bibliography} function is called, +% and passed the name of the notes file. % \begin{macrocode} -\newif\ifniib@filesw +\cs_new_nopar:Nn \niib_create_print_notes: { + \@ifpackageloaded { biblatex } { + \cs_new_nopar:Nn \niib_print_notes: { + \cs_set:Nx \niib_create_print_notes_aux: { + \printbibliography [ keyword = \exp_not:V \l_niib_keyword_tl ] + } + \niib_create_print_notes_aux: + } + }{ + \cs_new_nopar:Nn \niib_print_notes: { + \exp_args:NV \niib_bibliography:n \g_niib_filename_tl + } + } +} +\cs_new:Nn \niib_create_print_notes_aux: { } +\AtBeginDocument { \niib_create_print_notes: } % \end{macrocode} %\end{macro} -%\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} -\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@tcite} -% Actually carrying out the citation, and restoring the value of -% \cs{if@filesw} depends on whether \pkg{cite} is loaded. -% \begin{macrocode} -\AtBeginDocument{% - \@ifpackageloaded{cite} - {\newcommand*{\niib@tcite}[1]{\niib@normcite{#1}}} - {\newcommand*{\niib@tcite}[1]{% - \niib@normcite{#1}% - \niib@restorefilesw}}} +% +%\begin{macro}{\niib_attach_bibliography:} +%\begin{macro}{\bibliography} +%\begin{macro}{\niib_bibliography:n} +% Getting the database created here to be scanned by \BibTeX\ is +% dependant on whether \pkg{biblatex} is being used. If it is, and it is +% already loaded, then the data can be added now. On the other hand, if +% it is not already loaded a check is made at the end of the preamble. +% The \cs{bibliography} function has to be patched if \pkg{biblatex} is +% not in use. +% \begin{macrocode} +\cs_new_nopar:Nn \niib_attach_bibliography: { + \@ifpackageloaded { biblatex } { + \exp_args:NV \bibliography \g_niib_filename_tl + }{ + \cs_new_eq:NN \niib_bibliography:n \bibliography + \RenewDocumentCommand \bibliography { m } { + \intexpr_compare:nTF { \g_niib_total_notes_int = \c_zero } { + \niib_bibliography:n {##1} + }{ + \cs_set_nopar:Nx \niib_attach_bibliography: { + \exp_not:N \niib_bibliography:n { + \exp_not:n {##1} , \exp_not:V \g_niib_filename_tl + } + } + \niib_attach_bibliography: + } + } + } +} +\@ifpackageloaded { biblatex } { + \exp_args:NV \bibliography \g_niib_filename_tl + \cs_gundefine:N \niib_attach_bibliography: +}{ + \AtBeginDocument { \niib_attach_bibliography: } +} % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@normcite} -% The normal citation command. -% \begin{macrocode} -\newcommand*{\niib@normcite}{\@nameuse{\niib@cite}} -% \end{macrocode} %\end{macro} -%\begin{macro}{\niib@next} -%\begin{macro}{\niib@gobble} -% To allow correct detection of following punctuation by -% \cs{niib@mark}, it has to follow \cs{niib@text}. However, to -% prevent category code issues, \cs{niib@text} can only take -% \emph{one} argument. Hence, a ``follow-on'' macro is needed; this -% is provided here. The no-op here has to gobble a square-bracketed -% argument. +%\end{macro} +% +%\begin{macro}{\niib_set_sortkey_name:} +% \pkg{biblatex} uses the name \texttt{sortkey} for a key to sort by, +% whereas other style call the same concept \texttt{key}. % \begin{macrocode} -\newcommand*{\niib@next}{} -\def\niib@gobble[#1]{} -\let\niib@next\niib@gobble +\cs_new_nopar:Nn \niib_set_sortkey_name: { + \@ifpackageloaded { biblatex } { + \tl_set:Nn \l_niib_sortkey_field_tl { sortkey } + }{ + \tl_set:Nn \l_niib_sortkey_field_tl { key } + } + \cs_gundefine:N \niib_set_sortkey_name: +} +\AtBeginDocument { \niib_set_sortkey_name: } +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{\niib_set_mark_note_after:} +% To get the correct ordering for notes, writing to the \file{aux} file +% needs to be turned on and off. With \pkg{biblatex}, there is a +% convenient hook for this. Otherwise, everything has to happen after +% the citation command. +% \begin{macrocode} +\cs_new_nopar:Nn \niib_set_mark_note_after: { + \@ifpackageloaded { biblatex } { + \cs_set:Nn \niib_mark_note_after_aux:n { + \AtNextCite { \@fileswfalse } + \niib_cite:w {##1} + } + }{ + \cs_set:Nn \niib_mark_note_after_aux:n { + \cs_set_eq:NN \niib_filesw: \if@filesw + \@fileswfalse + \niib_cite:w {##1} + \cs_set_eq:NN \if@filesw \niib_filesw: + } + } +} +\AtBeginDocument { \niib_set_mark_note_after: } +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{\niib_check_cite:} +%\begin{macro}{\niib_aux_hook:} +% If the \pkg{cite} package is loaded, then there is a hook to +% reset the \file{aux} file after the citation. This means that moving +% punctuation will still work under these circumstances. However, the +% way \pkg{cite} sets things up is a little complicated. The link needs +% to be made at the end of the \cs{document} macro. +% \begin{macrocode} +\cs_new_nopar:Nn \niib_check_cite: { + \@ifpackageloaded { cite } { + \cs_set:Nn \niib_mark_note_after_aux:n { + \cs_set_eq:NN \niib_filesw: \if@filesw + \@fileswfalse + \cs_set_nopar:Nn \niib_aux_hook: { + \cs_set_eq:NN \if@filesw \niib_filesw: + \cs_set_nopar:Nn \niib_aux_hook: { } + } + \niib_cite:w {##1} + } + \cs_new_nopar:Nn \niib_aux_hook: { } + \tl_gput_right:Nn \g_niib_document_hook_tl { + \cs_if_exist:NF \@restore@auxhandle { + \tl_new:N \@restore@auxhandle + } + \tl_put_right:Nn \@restore@auxhandle { \niib_aux_hook: } + } + } { } +} +\AtBeginDocument { \niib_check_cite: } % \end{macrocode} %\end{macro} %\end{macro} -%\begin{macro}{\niib@text} -%\begin{macro}{\niib@out} -%\begin{macro}{\niib@stream} -% The \cs{niib@text} macro is the outer part of the writing system. -% It does not absorb the text of note, as without \eTeX\ this is bad -% news. -% \begin{macrocode} -\newcommand*{\niib@text}{% - \@bsphack - \@ifundefined{niib@out} - {\if@filesw - \newwrite\niib@out - \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 - \expandafter\niib@write - \else - \expandafter\niib@tidy - \fi} +% +%\subsection{User functions} +% +%\begin{macro}{\bibnote} +%\begin{macro}{\niib_bibnote:nn} +%\begin{macro}{\niib_bibnote:xn} +% Creating a not from scratch is a multi-step operation. First, check +% if a label was given by the user. If it was not, then one is created +% by incrementing the automatic number and fully expanding +% \cs{niib_note_name:}. The second phase is to create the note. The text +% is dealt with first as this leaves the note-marking code at the end +% of the function (needed if punctuation is to be moved). +% \begin{macrocode} +\NewDocumentCommand \bibnote { o +m } { + \IfNoValueTF {#1} { + \int_gincr:N \g_niib_note_int + \niib_bibnote:xn { \niib_note_name: } {#2} + }{ + \niib_bibnote:nn {#1} {#2} + } +} +\cs_new:Nn \niib_bibnote:nn { + \niib_write_note:nn {#1} {#2} + \niib_mark_note:n {#1} +} +\cs_generate_variant:Nn \niib_bibnote:nn { x } % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} -%\begin{macro}{\niib@tidy} -% When not writing to file. -% \begin{macrocode} -\newcommand*{\niib@tidy}[2]{% - \@esphack - \niib@next[#1]} +% +%\begin{macro}{\bibnotemark} +% Simply marking a note has similar requirements, but as there is only +% a single internal function to call the code is less complex. +% \begin{macrocode} +\NewDocumentCommand \bibnotemark { o } { + \IfNoValueTF {#1} { + \int_gincr:N \g_niib_note_int + \niib_mark_note:x { \niib_note_name: } + }{ + \niib_mark_note:n {#1} + } +} % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@write} -% The \cs{niib@write} macro deals with writing data verbatim to the -% \BibTeX\ file. When \eTeX\ is available, this is easy; the macro -% absorbs the note text and uses \cs{unexpanded}. -% \begin{macrocode} -\ifniib@etex - \newcommand*{\niib@write}[2]{% - \niib@log@debug{Writing bibnote #1 contents - \MessageBreak---\MessageBreak#2\MessageBreak - ---\MessageBreak to BibTeX database}% - \immediate\write\niib@out{% - @\niib@record\string{#1,^^J% - presort = \string{\niib@presort\string},^^J% - \ifniib@writekey - \niib@keyname\space= \string{\niib@key#1\string},^^J% - \fi - keywords = \string{\niib@keyword\string},^^J% - \niib@field\space= \string{\unexpanded{#2}\string}^^J% - \string}^^J}% - \@esphack - \niib@next[#1]} -% \end{macrocode} -% Life is more awkward when \eTeX\ is unavailable. The code here is -% based on a suggestion by Ulrich Diez, with alterations to the -% specifics needed here. -% \begin{macrocode} -\else - \newcommand*{\niib@write}[1]{% - \begingroup - \let\do\@makeother - \dospecials - \catcode`\{=1\relax - \catcode`\}=2\relax - \niib@write@{#1}} -\fi +% +%\begin{macro}{\bibnotetext} +% As text for a note uses the same number as the preceeding mark, +% things are slightly less complex here. The basic \texttt{o} argument +% type is used as this means that full expansion of the note name can +% take place \enquote{early}. +% \begin{macrocode} +\NewDocumentCommand \bibnotetext { o +m } { + \IfNoValueTF {#1} { + \niib_write_note:xn { \niib_note_name: } {#2} + }{ + \niib_write_note:nn {#1} {#2} + } +} % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@write@} -% Two support macros are needed if \eTeX\ is not available. -% \cs{niib@write@} works with the category codes altered as above, -% which means that text is written (essentially) verbatim to the -% \BibTeX\ file. +% +%\begin{macro}{\recordnotes} +% A direct call to the internal function: no arguments are needed. % \begin{macrocode} -\newcommand\niib@write@[1]{% - \long\def\niib@tempa##1{% - \def\niib@tempa{##1}% - \@onelevel@sanitize\niib@tempa\expandafter\endgroup - \expandafter\def\expandafter\niib@tempa\expandafter{% - \niib@tempa}% - \niib@write@@{#1}}% - \catcode`\^^M=10\relax - \niib@tempa} +\NewDocumentCommand \recordnotes { } { + \niib_record_notes: +} % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@write@@} -% Writing to the file is a very slightly altered version of the -% \eTeX\ version. In this case, the debugging data is given here, -% after category code changes. +% +%\begin{macro}{\bibnotesetup} +% A user set up function. % \begin{macrocode} -\newcommand*\niib@write@@[1]{% - \niib@log@debug{Writing bibnote #1 contents - \MessageBreak---\MessageBreak\niib@tempa\MessageBreak - ---\MessageBreak to BibTeX database}% - \immediate\write\niib@out{% - @\niib@record\string{#1,^^J% - presort = \string{\niib@presort\string},^^J% - \niib@keyname\space= \string{\niib@key#1\string},^^J% - \niib@field\space= \string{\niib@tempa\string}^^J% - \string}^^J}% - \@esphack - \niib@next[#1]} +\NewDocumentCommand \bibnotesetup { m } { + \keys_set:nn { notes2bib } {#1} +} % \end{macrocode} %\end{macro} % -%\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{macro}{\printbibnotes} +% A direct translation for the internal function. % \begin{macrocode} -\newcommand*{\niib@headcitelist}{} +\NewDocumentCommand \printbibnotes { } { + \niib_print_notes: +} % \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} -% 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{macro}{\citenote} +%\changes{v2.0}{2009/09/25}{Depreciated in favour of \cs{bibnotemark}} +%\begin{macro}{\flushnotestack} +%\changes{v2.0}{2009/09/28}{Depreciated in favour of +% \cs{recordnotes}} +%\begin{macro}{\niibsetup} +%\changes{v2.0}{2009/09/25}{Depreciated in favour of \cs{bibnotesetup}} +% A few functions which are depreciated in version two. % \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}}} +\NewDocumentCommand \citenote { m } { + \niib_mark_note:n {#1} +} +\cs_new_eq:NN \flushnotestack \recordnotes +\cs_new_eq:NN \niibsetup \bibnotesetup % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} -%\begin{macro}{\niib@tailcitelist} -%\changes{v1.3b}{2008/01/16}{New macro} -%\begin{macro}{\niibtailcite} -%\changes{v1.3b}{2008/01/16}{New macro} -% To enable proper logging of citations when \opt{sort=tail}, a -% similar system to the above is employed without the \cs{nocite} -% part. -% \begin{macrocode} -\newcommand*{\niib@tailcitelist}{} -\newcommand*{\niibtailcite}[1]{% - \edef\niib@tempa{#1}% - \ifx\@empty\niib@tailcitelist\@empty - \xdef\niib@tailcitelist{\niib@tempa}% - \else - \xdef\niib@tailcitelist{\niib@tailcitelist,\niib@tempa}% - \fi} -% \end{macrocode} -%\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. +% +%\subsection{Auxiliary file functions} +% +% \pkg{notes2bib} needs to write information to the \file{aux} file +% for carrying information between runs. Rather than give them cryptic +% names, they have long design-level ones. They are also declared +% as protected functions so that writing to the \file{aux} file is +% easier. +% +%\begin{macro}{\NotesAfterCitations} +%\begin{macro}{\NotesBeforeCitations} +% The functions to pass information on out-of-order notes from one +% run to another both add the information to the appropriate lists. +% For notes before citations, there is also a need to put the +% \cs{citation} calls into the \file{aux} file at the correct stage. % \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 +\NewDocumentCommand \NotesAfterCitations { m } { + \clist_gput_right:Nn \g_niib_previous_after_clist {#1} +} +\NewDocumentCommand \NotesBeforeCitations { m } { + \clist_gput_right:Nn \g_niib_previous_after_clist {#1} + \tl_gput_right:Nn \g_niib_document_hook_tl { + \nocite {#1} + } +} % \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{macro}{\TotalNotes} +% This function allows the total number of bibliography notes to be +% carried forward from one run to the next. % \begin{macrocode} -\AtBeginDocument{ - \@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} -%\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}}} +\NewDocumentCommand \TotalNotes { m } { + \int_gset:Nn \g_niib_previous_notes_int {#1} +} % \end{macrocode} %\end{macro} -%\end{macro} % -%\subsection{Finalisation} -%\begin{macro}{\ifniib@rerun} -% A switch is needed for the re-run test. +%\subsection{Code at the start of the document} +% +%\begin{macro}{\g_niib_document_hook_tl} +% \pkg{notes2bib} needs to be able to carry out a few tasks right at the +% beginning of the document. To do that, a hook is added to the +% \cs{document} macro, which can be treated as a token list variable +% as it has no arguments. % \begin{macrocode} -\newif\ifniib@rerun +\tl_gput_right:Nn \document { \g_niib_document_hook_tl } +\tl_new:N \g_niib_document_hook_tl % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@checkrerun} -%\changes{v1.3b}{2008/01/16}{Added ability to check for both -% \opt{head} and \opt{tail} re-runs} -%\changes{v1.3b}{2008/01/16}{Bug fix with logging for -% \opt{debug} logging} -% Any ``head'' notes may mean a second \LaTeX\ run is needed. -% \begin{macrocode} -\newcommand*{\niib@checkrerun}[1]{% - \niib@rerunfalse - \expandafter\ifx\expandafter\@empty - \csname niib@#1list\endcsname\@empty - \expandafter\ifx\expandafter\@empty - \csname niib@#1citelist\endcsname\@empty - \niib@log@debug{No `#1' notes detected}% - \else - \niib@reruntrue - \niib@log@debug{No `#1' notes found this run\MessageBreak - but .aux files contained the `#1' requests: - \MessageBreak\csname niib@#1citelist\endcsname}% - \fi - \else - \expandafter\ifx\expandafter\@empty - \csname niib@#1citelist\endcsname\@empty - \niib@reruntrue - \niib@log@debug{No `#1' requests in .aux file - \MessageBreak but `#1' notes in this run: - \MessageBreak\csname niib@#1list\endcsname}% - \else -% \end{macrocode} -% If the package gets here, then there are some notes and some -% requests in the aux file. The two lists are now compared. +% +%\subsection{Code at end of the document} +% +% There are a few tasks which have to be carried out a the end of +% the \LaTeX\ run, so that data is available for the next run. +% +% First, all of the notes need to be added to the auxiliary file. +% This ensures that the comparisons made in the next step make sense. % \begin{macrocode} - \niib@checklists{#1}% - \fi - \fi - \ifniib@rerun +\AtEndDocument { \niib_record_notes: } % \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{macro}{\niib_check_rerun:} +% The list of out-of-order notes from the current run needs to match +% that from the previous run. If not, then there is a need to re-run +% \LaTeX. % \begin{macrocode} - \niib@log@warn{Rerun LaTeX to get correct \MessageBreak - `#1' 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} +\cs_new_nopar:Nn \niib_check_rerun: { + \clist_if_eq:NNTF \g_niib_all_before_clist + \g_niib_previous_before_clist { + \clist_if_eq:NNF \g_niib_all_after_clist + \g_niib_previous_after_clist { + \msg_info:nn { notes2bib } { rerun } + } + }{ + \msg_info:nn { notes2bib } { rerun } + } +} +\AtEndDocument { + \niib_check_rerun: +} +\msg_new:nnn { notes2bib } { rerun } {% + To get notes in the correct order, please run:\\% + 1) LaTeX \\% + 2) BibTeX \\% + 3) LaTeX +} % \end{macrocode} %\end{macro} -%\begin{macro}{\niib@checklists} -%\changes{v1.3b}{2008/01/16}{Added ability to check for both -% \opt{sort=head} and \opt{sort=tail}} -% The business end of comparing the two lists. Two sweeps are made, -% to check that the lists match entirely. +% +%\begin{macro}{\niib_write_total_notes:} +% The total number of bibliography notes from the current run is +% recorded to the \file{aux} file. This will then be picked up in the % \begin{macrocode} -\newcommand*{\niib@checklists}[1]{% +\cs_new_nopar:Nn \niib_write_total_notes: { + \intexpr_compare:nT { \g_niib_note_int > \c_zero } { + \iow_now:Nx \@auxout { + \TotalNotes { \int_to_arabic:n { \g_niib_note_int } } + } + } +} +\AtEndDocument { \niib_write_total_notes: } % \end{macrocode} -%\begin{macro}{\niib@list} -%\changes{v1.3b}{2008/01/16}{New macro} -%\begin{macro}{\niib@citelist} -%\changes{v1.3b}{2008/01/16}{New macro} -% To allow \cs{niib@checklists} to handle both \opt{sort=head} and -% \opt{sort=tail} citations, the expanded list is needed for the -% \cs{@for} loops. +%\end{macro} +% +%\subsection{Tidying up} +% +%\begin{macro}{\thanks} +% The \cs{thanks} macro has to be replaced by one that uses the original +% \cs{footnotemark} and \cs{footnotetext} under all circumstances. This +% is the kernel definition modified: if an alternative version is in use +% things may go wrong. +% \begin{macrocode} +\cs_set:Npn \thanks #1 { + \niib_footnotemark:w + \protected@xdef \@thanks { + \@thanks + \protect \niib_footnotetext:w [ \the \c@footnote ] {#1} + } +} +% \end{macrocode} +%\end{macro} +% +% The final job is to set note placement: this is done here as various +% parts of the module need to be in place for this to work correctly. % \begin{macrocode} - \expandafter\edef\expandafter\niib@list\expandafter - {\csname niib@#1list\endcsname}% - \expandafter\edef\expandafter\niib@citelist\expandafter - {\csname niib@#1citelist\endcsname}% +\keys_set:nn { notes2bib } { placement = mixed } % \end{macrocode} -%\end{macro} -%\end{macro} -% The loops can now being. +% +% Any load time options are processed. % \begin{macrocode} - \@for\niib@tempa:=\niib@list\do{% - \niib@reruntrue - \@for\niib@tempb:=\niib@citelist\do{% - \ifx\niib@tempa\niib@tempb - \niib@rerunfalse - \fi} - \ifniib@rerun - \niib@log@debug{Note \niib@tempa\space is a `#1' note - \MessageBreak but request not in .aux file}% - \fi} - \ifniib@rerun\else - \@for\niib@tempa:=\niib@citelist\do{% - \niib@reruntrue - \@for\niib@tempb:=\niib@list\do{% - \ifx\niib@tempa\niib@tempb - \niib@rerunfalse - \fi} - \ifniib@rerun - \niib@log@debug{Note \niib@tempa\space is set to `#1' - in .aux\MessageBreak file but is not a `#1' note}% - \fi} - \fi} +\ProcessKeysOptions { notes2bib } % \end{macrocode} -%\end{macro} -%\begin{macro}{\niib@taillist} -%\changes{v1.3b}{2008/01/16}{New macro} -% At the end of the document, any delayed citations are written to the -% \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{% - \niib@rerunfalse - \niib@checkrerun{head}% - \flushnotestack - \@ifundefined{niib@out}{} - {\immediate\closeout\niib@out - \niib@log@debug{Closed BibTeX database file\MessageBreak - \niib@stream}}} +%</package> % \end{macrocode} -%\end{macro} % -%\iffalse -%</package> -%\fi -% \Finale -%\iffalse -%<*jawltxdoc> -\NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{jawltxdoc} -\usepackage[T1]{fontenc} -\usepackage{lmodern} -\usepackage[final]{listings,graphicx,microtype} -\usepackage[scaled=0.95]{helvet} -\usepackage[version=3]{mhchem} -\usepackage[osf]{mathpazo} -\usepackage{booktabs,array,url,courier,xspace,varioref} -\usepackage{upgreek,ifpdf,float,caption,longtable,babel} -\begingroup - \@ifundefined{eTeXversion} - {\aftergroup\@gobble} - {\aftergroup\@firstofone} -\endgroup -{\usepackage{etoolbox}} -\floatstyle{plaintop} -\restylefloat{table} -\labelformat{figure}{\figurename~#1} -\labelformat{table}{\tablename~#1} -\ifpdf - \usepackage{embedfile} - \embedfile[% - stringmethod=escape,% - mimetype=plain/text,% - desc={LaTeX docstrip source archive for package `\jobname'}% - ]{\jobname.dtx} -\fi -\IfFileExists{\jobname.sty} - {\usepackage{\jobname}}{} -\usepackage[numbered]{hypdoc} -\setcounter{IndexColumns}{2} -\newlength\LaTeXwidth -\newlength\LaTeXoutdent -\newlength\LaTeXgap -\setlength\LaTeXgap{1em} -\setlength\LaTeXoutdent{-0.15\textwidth} -\newbox\lst@samplebox -\edef\LaTeXexamplefile{\jobname.tmp} -\lst@RequireAspects{writefile} -\lstnewenvironment{LaTeXexample}[1][example]{% - \global\let\lst@intname\@empty - \ifcsname LaTeXcode#1\endcsname - \expandafter\let\expandafter\LaTeXcode - \csname LaTeXcode#1\endcsname - \expandafter\let\expandafter\LaTeXcodeend - \csname LaTeXcode#1end\endcsname - \else - \PackageError{jawltxdoc} - {Undefined example type `#1'} - \@ehd - \let\LaTeXcode\relax - \let\LaTeXcodeend\relax - \fi - \LaTeXcode} - {\lst@EndWriteFile - \LaTeXcodeend} -\newcommand*{\LaTeXcodeexample}{% - \setbox\lst@samplebox=\hbox\bgroup - \LaTeXcodefloat} -\let\LaTeXcoderesultonly\LaTeXcodeexample -\newcommand*{\LaTeXcodeexampleend}{% - \egroup - \setlength\LaTeXwidth{\wd\lst@samplebox}% - \begin{list}{}{% - \setlength\itemindent{0pt} - \setlength\leftmargin\LaTeXoutdent - \setlength\rightmargin{0pt}}% - \item - \setlength\LaTeXoutdent{-0.15\textwidth} - \begin{minipage}[c]{% - \textwidth-\LaTeXwidth-\LaTeXoutdent-\LaTeXgap} - \LaTeXcodefloatend - \end{minipage}% - \hfill - \begin{minipage}[c]{\LaTeXwidth}% - \hbox to\linewidth{\box\lst@samplebox\hss}% - \end{minipage}% - \end{list}} -\newcommand*{\LaTeXcodefloat}{% - \setkeys{lst}{tabsize=4,gobble=3,breakindent=0pt, - basicstyle=\small\ttfamily,basewidth=0.51em, - keywordstyle=\color{blue}}% - \lst@BeginAlsoWriteFile{\LaTeXexamplefile}} -\let\LaTeXcodenoexample\LaTeXcodefloat -\let\LaTeXcodenoexampleend\@empty -\newcommand*{\LaTeXcodefloatend}{% - \MakePercentComment\catcode`\^^M=10\relax - \small - {\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}% - {\lst@ProcessTabulator}}% - \leavevmode \input{\LaTeXexamplefile}}% - \MakePercentIgnore} -\newcommand*{\LaTeXcoderesultonlyend}{\egroup\LaTeXcodefloatend} -\lstnewenvironment{BibTeXexample}{% - \global\let\lst@intname\@empty - \setbox\lst@samplebox=\hbox\bgroup - \setkeys{lst}{tabsize=4,gobble=3,breakindent=0pt, - basicstyle=\small\ttfamily,basewidth=0.51em, - keywordstyle=\color{black}} - \lst@BeginAlsoWriteFile{\LaTeXexamplefile}} - {\lst@EndWriteFile - \LaTeXcodeexampleend} -\newcommand*{\DescribeOption}{% - \leavevmode\@bsphack\begingroup\MakePrivateLetters - \Describe@Option} -\newcommand*{\Describe@Option}[1]{\endgroup - \marginpar{\raggedleft\PrintDescribeEnv{#1}}% - \SpecialOptionIndex{#1}\@esphack\ignorespaces} -\newcommand*{\SpecialOptionIndex}[1]{\@bsphack - \index{#1\actualchar{\protect\ttfamily#1} - (option)\encapchar usage}% - \index{options:\levelchar#1\actualchar{\protect\ttfamily#1}% - \encapchar usage}\@esphack} -\newcommand*{\indexopt}[1]{\DescribeOption{#1}\opt{#1}} -\newcommand*{\DescribeOptionInfo}[2]{% - \DescribeOption{#1}% - \opt{#1=\meta{#2}}\xspace} -\newcommand*{\ofixarg}[1]{% - {\ttfamily[}% - \ifmmode \expandafter \nfss@text \fi - {% - \meta@font@select - \edef\meta@hyphen@restore{% - \hyphenchar\the\font\the\hyphenchar\font}% - \hyphenchar\font\m@ne - \language\l@nohyphenation - #1\/% - \meta@hyphen@restore - }% - {\ttfamily]}} -\newcommand*{\pkg}[1]{\textsf{#1}} -\newcommand*{\currpkg}{\pkg{\jobname}\xspace} -\newcommand*{\opt}[1]{\texttt{#1}} -\newcommand*{\defaultopt}[1]{\opt{\textbf{#1}}} -\newcommand*{\file}[1]{\texttt{#1}} -\newcommand*{\ext}[1]{\file{.#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*{\etal}{% - \@ifnextchar. - {\latin{et~al.}} - {\latin{et~al}.\xspace}} -\newcommand*{\AMS}{{\protect\usefont{OMS}{cmsy}{m}{n}% - A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}} -\providecommand*{\eTeX}{\ensuremath{\varepsilon}-\TeX} -\DeclareRobustCommand*{\XeTeX} - {X\kern-.125em\lower.5ex\hbox{\reflectbox{E}}\kern-.1667em\TeX} -\providecommand*{\CTAN}{\textsc{ctan}} -\@ifpackageloaded{etoolbox} - {\patchcmd{\@addmarginpar} - {\@latex@warning@no@line {Marginpar on page \thepage\space moved}} - {\relax}{}{}} - {} -\newcounter{argument} -\g@addto@macro\endmacro{\setcounter{argument}{0}} -\newcommand*\darg[1]{% - \stepcounter{argument}% - {\ttfamily\char`\#\theargument~:~}#1\par\noindent\ignorespaces} -\newcommand*\doarg[1]{% - \stepcounter{argument}% - {\ttfamily\makebox[0pt][r]{[}% - \char`\#\theargument]:~}#1\par\noindent\ignorespaces} -%</jawltxdoc> -%\fi +%\end{implementation} +% +%\PrintChanges +%\PrintIndex
\ No newline at end of file |