diff options
author | Karl Berry <karl@freefriends.org> | 2009-04-14 00:01:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-04-14 00:01:40 +0000 |
commit | 51a42f5a7d7a3d89c8c99827632415eca05b2826 (patch) | |
tree | a3f943c5753575c59ee172f6a9ca6b3482a981f8 /Master/texmf-dist/tex/latex/cite | |
parent | d3d3ce4e340ac8da12dee848b80a7875eaed6549 (diff) |
chapterbib 1.14 (13apr09)
git-svn-id: svn://tug.org/texlive/trunk@12712 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cite')
-rw-r--r-- | Master/texmf-dist/tex/latex/cite/chapterbib.sty | 265 |
1 files changed, 180 insertions, 85 deletions
diff --git a/Master/texmf-dist/tex/latex/cite/chapterbib.sty b/Master/texmf-dist/tex/latex/cite/chapterbib.sty index 66224a2c4b7..573d3eb12e4 100644 --- a/Master/texmf-dist/tex/latex/cite/chapterbib.sty +++ b/Master/texmf-dist/tex/latex/cite/chapterbib.sty @@ -1,14 +1,19 @@ -% chapterbib.sty Version 1.11 (29-FEB-2004) Donald Arseneau +% chapterbib.sty Version 1.14 (31-Mar-2009) Donald Arseneau % % Allow multiple bibliographies in a LaTeX document, including items % \cite'd in more than one bibliography. % +% Copyright (C) 1989-2009 by Donald Arseneau and Niel Kempson +% These macros may be freely transmitted, reproduced, or modified +% provided that this notice is left intact. +% % Instructions are below, after \endinput. % %====================== BEGIN MACROS =========================== \newenvironment{cbunit}% {\global\advance\c@inputfile\@ne \xdef\the@ipfilectr{@-\the\c@inputfile}% + \@namedef{b@*\@extra@b@citeb}{}% \@CB@writeContext}% {\gdef\the@ipfilectr{}\@CB@writeContext} @@ -40,15 +45,17 @@ \@ifundefined{@extra@b@citeb}{% if not defined by compatible package \def\@citex[#1]#2{% Add \@extra@b@citeb to \cite - \let\@citea\@empty + \leavevmode \let\@citea\@empty \@cite{\@for\@citeb:=#2\do {\@citea\let\@citea\citepunct \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}% \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi - \@ifundefined{b@\@citeb \@extra@b@citeb}{\mbox{\reset@font\bf ?}% - \@warning{Citation `\@citeb' in file `\@currentipfile' - on page \thepage \space undefined}\G@refundefinedtrue}% - {\hbox{\citeform{\csname b@\@citeb \@extra@b@citeb\endcsname}}}}}{#1}} + \@ifundefined{b@\@citeb \@extra@b@citeb}{\hbox{\reset@font\bfseries ?}% + \G@refundefinedtrue + \@latex@warning{Citation `\@citeb' in file `\@currentipfile' + on page \thepage \space undefined}}% + {\@cite@ofmt{\citeform{\csname b@\@citeb + \@extra@b@citeb\endcsname}}}}}{#1}} }{}% % Test if \@extra@b@citeb hook needs to be added to \nocite @@ -71,8 +78,7 @@ \@esphack} \fi -\long\def\@firstofone#1{#1} - +\@ifundefined{@cite@ofmt}{\let\@cite@ofmt\hbox}{} \@ifundefined{citeform}{\let\citeform\@empty}{} \@ifundefined{citepunct}{\def\citepunct{,\penalty\@m\ }}{} @@ -84,17 +90,24 @@ \gdef\@extra@binfo{} % in case .aux files are left from old run. -\@ifundefined{reset@font}{\let\reset@font\relax}{} -\@ifundefined{G@refundefinedtrue}{\let\G@refundefinedtrue\relax}{} - \let\cb@bibliographystyle\bibliographystyle \def\bibliographystyle#1{\if\cb@roottest\cb@bibliographystyle{#1}\fi} \def\cb@roottest{11}% for [rootbib]: {2\ifx\the@ipfilectr\@empty 1\else2\fi} \def\bibliography#1{\if\cb@roottest \if@filesw\immediate\write\@auxout{\string\bibdata{#1}}\fi - \fi \cb@dobiblio{\@currentipfile.bbl}} + \fi + \begingroup % localize hooks into \@bibitem + \ifx\@CitationPrefix\@empty\else \ifx\the@ipfilectr\@empty\else + \@cb@insertprefix + \fi\fi + \cb@dobiblio{\@currentipfile.bbl}% + \endgroup} +\long\def\@firstofone#1{#1} +\@ifundefined{reset@font}{\let\reset@font\relax}{} +\@ifundefined{bfseries}{\def\bfseries{\bf}}{} +\@ifundefined{G@refundefinedtrue}{\let\G@refundefinedtrue\relax}{} \@ifundefined{PackageWarning}{\let\cb@warning\@warning}% {\def\cb@warning{\PackageWarning{chapterbib}}} @@ -106,6 +119,9 @@ \let\cb@dobiblio\@input}% {\let\cb@dobiblio\@input@} +\def\FinalBibPrefix{\bibname\space for\space}% +\def\@auto@bibname{Bibliography} + \def\sectionbib#1#2{% Macro to convert \thebibliography command \@ifundefined{bibsection}{% Regular -- patch \thebibliography \long\def\@tempa##1##{% to parse beginning of old def @@ -121,7 +137,7 @@ \expandafter\expandafter\expandafter\cb@sectionbib\fi \cb@thebibliography}% \expandafter\def\expandafter\cb@sectionbib\@tempc##1{#1{\bibname}% - \ifx\@currentlabel\@empty \begingroup \c@secnumdepth\z@ + \ifx\@currentlabel\@empty \begingroup \c@secnumdepth\m@ne \addcontentsline{toc}{#2}{\bibname}% local: * -> no num \csname#2mark\endcsname{\bibname}\endgroup\fi \@ifnextchar\@mkboth{\@gobblethree}{}}% @@ -145,14 +161,52 @@ \def\strip@prefix#1>{} \@ifundefined{bibname}{\def\bibname{Bibliography}}{} +% The following very messy hacking is to apply a prefix to each +% cite value, shown in the cites and the bibitems, and active +% with hyperref. The user should declare something like: +% \CitationPrefix{\thechapter.} +% +\let\@cb@use@prefix\@empty +\let\@CitationPrefix\@empty +% +\newcommand\bibitemPrefix[1]{% + \def\@CitationPrefix{#1}% + \@ifundefined{cb@emptytoks}{\newtoks\cb@emptytoks}{}% + \cb@emptytoks={}% + \def\@cb@valuehack##1{% hook into "\the\value\@listctr" + \ifx\@listctr##1% only affect "\value\@listctr" + \cb@emptytoks % use up the preceding \the + \@CitationPrefix % insert the prefix text + \the % restore \the + \fi + \csname c@\@listctr\endcsname}% regular \value +% +% This is performed once, at the first \bibitem of each (sub-)bibliography + \def\@cb@use@prefix{% + \let\value\@cb@valuehack + \def\@itemlabel{\@biblabel {\the\value\@listctr}}% + \let\@cb@use@prefix\@empty} +} + +% redefine \@lbibitem to use prefixed number; set hook to use prefix +% (through \value) in \@bibitem also. +\def\@cb@insertprefix{% + \let\@cborg@lbibitem\@lbibitem \let\@cborg@bibitem\@bibitem + \def\@bibitem{\@cb@use@prefix\@cborg@bibitem}% + \def\@lbibitem[##1]{\@cb@use@prefix\@cborg@lbibitem[\@CitationPrefix##1]}% +} \@ifundefined{DeclareOption}{% LaTeX2.09 \def\@CB@wtoc#1{}% disable; broken in 2.09 }{% LaTeX2e option -\ProvidesPackage{chapterbib}[2004/02/29 \space v 1.11] +\ProvidesPackage{chapterbib}[2009/03/31 \space v 1.14] \DeclareOption{sectionbib}{\AtBeginDocument{\sectionbib{\section*}{section}}% - \providecommand\StartFinalBibs{\chapter*{\bibname}\chaptermark\bibname - \protected@edef\bibname{\chaptername\space\noexpand\thechapter}}}% + \let\FinalBibPrefix\@empty + \providecommand\StartFinalBibs{\chapter*{\bibname}% + \begingroup \c@secnumdepth\m@ne + \addcontentsline{toc}{chapter}{\bibname}% + \chaptermark{\bibname}\endgroup + \def\bibname{\@auto@bibname}}}% \DeclareOption{draft}{\let\cbinput=\include} \DeclareOption{rootbib}{\def\cb@roottest{2\ifx\the@ipfilectr\@empty2\else1\fi}} \DeclareOption{duplicate}{\gdef\cb@biblist{}\let\cb@sub@input\@input@} @@ -170,24 +224,31 @@ \let\cb@elt\cb@dogatherbib \cb@biblist \if@filesw\immediate\write\@auxout{\let\string\bibcite\string\cb@bc}\fi}% \fi + \ifx\cb@sub@input\@gobble % For [gather] \def\cb@dofinalbibs{\let\cb@elt\cb@dogatherbib \cb@biblist}% \fi + \ifx\cb@biblist\@empty % duplicate or gather declared - \providecommand\StartFinalBibs{\protected@edef\bibname - {\bibname\space for \chaptername\space \noexpand\thechapter}}% + \providecommand\StartFinalBibs{\def\bibname{\@auto@bibname}}% \def\cb@dobiblio#1{\begingroup\makeatletter \ifx\the@ipfilectr\@empty % in root \StartFinalBibs \cb@dofinalbibs \else % in chapter, or section - \let\cb@elt\relax - \xdef\cb@biblist{\cb@biblist - \cb@elt{\csname the\CBMainSectioning\endcsname}% = \thechapter - {\the\c@inputfile}{\@currentipfile}}% + \let\cb@elt\relax % list \cb@elt{title}{input#}{file} + \let\@ifchapapp\@secondoftwo % provide a *possible* title + \expandafter\ifx\csname the\CBMainSectioning\endcsname\thechapter + \@ifundefined{@chapapp}{}{\let\@ifchapapp\@firstoftwo}\fi + \@ifundefined{FinalBibTitles}{\def\FinalBibTitles % locally + {\FinalBibPrefix + \@ifchapapp{\@chapapp}{\csname the\CBMainSectioning\endcsname}\space + \csname the\CBMainSectioning\endcsname}}{}% + \protected@xdef\cb@biblist{\cb@biblist + \cb@elt{\FinalBibTitles}{\the\c@inputfile}{\@currentipfile}}% \cb@sub@input{#1}% \fi\endgroup} - \def\cb@dogatherbib#1#2#3{% - \setcounter{\CBMainSectioning}{#1}% + \def\cb@dogatherbib#1#2#3{% Title, count, fname + \protected@edef\@auto@bibname{#1}% \global\c@inputfile#2\global\advance\c@inputfile\m@ne \IfFileExists{#3.bbl}{\cb@input{#3.bbl}}{}} \fi @@ -199,18 +260,22 @@ %====================== BEGIN INSTRUCTIONS =========================== - chapterbib.sty Version 1.11 (29-FEB-2004) DA (allow \nocite check) - ~~~~~~~~~~~~~~ 1.10 (23-JUN-2003) DA (\bibsection \CBMainSectioning) - 1.9 (19-SEP-2001) DA (sectionbib change; babel) - 1.8 (29-APR-1999) DA (gather, duplicate, toc) - 1.7 (21-JUL-1997) DA (sectionbib, \nocite) - 1.6 (08-FEB-1997) Donald Arseneau (more sectionbib) - 1.5 (09-OCT-1995) Donald Arseneau (rootbib) - 1.4 (11-MAR-1995) Donald Arseneau (sectionbib) - 1.3 (04-JUL-1994) Donald Arseneau (2e, cbunit) - 1.2 (21-MAY-1993) Donald Arseneau (bug fix) - 1.1 (24-MAR-1993) Donald Arseneau - 1.0 (23-NOV-1988) Niel Kempson + chapterbib.sty Version + ~~~~~~~~~~~~~~ 1.14 (31-MAR-2009) DA (\nocite*, \CitationPrefix, etc) + 1.13 (11-DEC-2007) DA (new final-bib titling) + 1.12 (21-MAR-2004) DA + 1.11 (29-FEB-2004) DA (allow \nocite check) + 1.10 (23-JUN-2003) DA (\bibsection \CBMainSectioning) + 1.9 (19-SEP-2001) DA (sectionbib change; babel) + 1.8 (29-APR-1999) DA (gather, duplicate, toc) + 1.7 (21-JUL-1997) DA (sectionbib, \nocite) + 1.6 (08-FEB-1997) Donald Arseneau (more sectionbib) + 1.5 (09-OCT-1995) Donald Arseneau (rootbib) + 1.4 (11-MAR-1995) Donald Arseneau (sectionbib) + 1.3 (04-JUL-1994) Donald Arseneau (2e, cbunit) + 1.2 (21-MAY-1993) Donald Arseneau (bug fix) + 1.1 (24-MAR-1993) Donald Arseneau + 1.0 (23-NOV-1988) Niel Kempson Allow multiple bibliographies in a LaTeX document, including items \cite'd in more than one bibliography. Despite the name "chapterbib", @@ -222,8 +287,9 @@ There are also the commands \begin{cbunit}, \end{cbunit}, and \cbinput to allow multiple bibliographies without using \include (see item 4). - There are two added hooks, \citeform and \citepunct, to customise the - formatting of each entry in a citation list. + There are two added hooks, \citeform and \citepunct, which you can + redefine to customise the formatting of each entry in a citation list, + and the declaration \CitationPrefix to use in preference to \citeform. Usage, Restrictions, and Options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -232,17 +298,13 @@ each \include'd file. Run LaTeX; run BibTeX on each included file; run LaTeX; run LaTeX. - 2. If you get errors like "! LaTeX Error: Command \xxx already defined." - then bibtex is foolishly putting "\newcommand" in each bbl file. The - fix is to put the \bibliography command in braces: {\bibliography{x}}. - - 3. The \bibliography and \bibliographystyle commands are not normally used + 2. The \bibliography and \bibliographystyle commands are not normally used in the root file, only in files that have been \include'd. To have a - whole-document bibliography, see items 7-10, depending on which style of + whole-document bibliography, see items 6-9, depending on which style of whole-document bib. - 4. If you can't use \include because a new section must start below the - preceding bibliography on the same page [odd format!], then you can + 3. If you can't use \include because a new section must start below the + preceding bibliography on the same page (odd format!), then you can use \begin{cbunit}...\end{cbunit} or \cbinput, with a {thebibliography} environment in each unit or input file. To use BibTeX: input separate files using \cbinput; at first use the package or global option [draft], @@ -253,7 +315,7 @@ With old LaTeX, do the preliminary run using \include commands, and change these to \cbinput for the final run(s). - 5. Your preferred citation style (xxx.sty) may not work with chapterbib at + 4. Your preferred citation style (xxx.sty) may not work with chapterbib at first, but it is easy to make it compatible: In `xxx.sty' change every "@\@citeb" to "@\@citeb\@extra@b@citeb", and insert the line \@ifundefined{@extra@b@citeb}{\def\@extra@b@citeb{}}{} @@ -272,7 +334,7 @@ you may need to redefine "\nocite" (with any "@\@citeb" changed to "@\@citeb\@extra@b@citeb") in that sty file. - 6. The report and book document classes usually treat the bibliography as + 5. The report and book document classes usually treat the bibliography as an unnumbered chapter (\chapter*), which is not so good for bibliographies IN a chapter. You can specify \usepackage[sectionbib]{chapterbib} @@ -290,62 +352,87 @@ does \sectionbib{\section*}{section}. Again, for the most control, it is better to redefine \thebibliography entirely. - 7. If you want a completely unrelated bibliography in the root file, perhaps + 6. If you want a completely unrelated bibliography in the root file, perhaps for a general reading list, you can provide your own bibliography there using the thebibliography environment. I don't suppose this will appeal to BibTeX users! - 8. To have a cohesive bibliography for the whole document, plus individual + 7. To have a cohesive bibliography for the whole document, plus individual bibs in the chapters, put \bibliography commands in the included chapters - plus in the root file; use \usepackage[rootbib]{chapterbib}; run LaTeX; - run BibTeX on the root file; change to \usepackage{chapterbib}; run - LaTeX; run BibTeX on each included file; run LaTeX; run LaTeX. - This produces an independent `overall' bibliography which only makes - sense for various `named' bibliography styles; a style with numbering - will give unrelated numbers in each bibliography. - Actually, you probably don't *need* to ever run with [rootbib] - because, although bibTeX should complain about multiple \bibdata - commands, it should produce all the right bbl files -- but the root - \bibliographystyle must come first in the document. - - 9. To have a bibliography-by-chapter at the end instead of separate bibs + plus in the root file. Make sure the \bibliographystyle for the overall + bibliography appears FIRST, before any chapters are included. Run LaTeX; + run BibTeX on the root file; run BibTeX on each included file; run LaTeX; + run LaTeX. This produces an independent `overall' bibliography which only + makes sense for various `named' bibliography styles; a numbered style, or + one with any type of automatic enumeration (like Me2007a, Me2007b) will + give unrelated numbers in each bibliography and lead to confusion. + Bibtex will complain about multiple \bibdata commands when it makes + the whole bibliography, but it should obey the first. If you don't + want to see any error messages from bibtex, or if you don't want to put + the main \bibliographystyle command first in the document, then use + \usepackage[rootbib]{chapterbib} when you run LaTeX first; run BibTeX + on the root file; change to \usepackage{chapterbib}; run LaTeX; run + BibTeX on each included file; run LaTeX; run LaTeX. + + 8. To have a bibliography-by-chapter at the end instead of separate bibs in the chapters, use \usepackage[gather]{chapterbib}, put \bibliography commands in each file, and at the end of the main file. Run LaTeX as - in item 1. You can control the titling of the final bibliography by - defining \StartFinalBibs. The default definition is (like) + in item 1. You can control the titling of the final bibliographies by + defining \FinalBibTitles, such as + + \newcommand\FinalBibTitles{References for Chapter \thechapter} + + A similar effect may be achived by RE-defining \FinalBibPrefix as + + \renewcommand\FinalBibPrefix{References for } + + Even more control is achieved by redefining \StartFinalBibs. + The default definition is (like) \newcommand{\StartFinalBibs}{% - \renewcommand{\bibname}{Bibliography for Chapter \thechapter}} + \renewcommand{\bibname}{Bibliography for chapter n}} normally, but when using the [sectionbib] option it becomes - \newcommand{\StartFinalBibs}{% - \chapter*{\bibname}\chaptermark{\bibname}% - \renewcommand{\bibname}{Chapter \thechapter}} + \newcommand{\StartFinalBibs}{\chapter*{\bibname}% + \addcontentsline{toc}{chapter}{\bibname}\@mkboth{\bibname}{\bibname}% + \renewcommand{\bibname}{Chapter n}} - You should really provide your own definition. If you are using the - article document class and \section, then you MUST do so. + where the \bibname text is now provided by \@auto@bibname, which + relies on bookkeeping and \FinalBibPrefix. If your document class has neither section nor chapter, then you must - define \StartFinalBibs (of course) and also indicate the sectioning: - \newcommand\CBMainSectioning{motif} - if the main sectioning command is \motif, for example. + define \StartFinalBibs and also indicate the sectioning: for example, + if the main sectioning command in your document class is \motif: + \newcommand\CBMainSectioning{motif} -10. To have bibliographies in each chapter PLUS a bibliography-by-chapter at + 9. To have bibliographies in each chapter PLUS a bibliography-by-chapter at the end, follow item 9, but declare \usepackage[duplicate]{chapterbib} (or \usepackage[duplicate,sectionbib]{chapterbib}). -11. If you use Babel, load chapterbib before babel. +10. If you use Babel, load chapterbib before babel. - \citeform and \citepunct: - ~~~~~~~~~~~~~~~~~~~~~~~~~ + \citeform, \citepunct and \CitationPrefix: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Normally, the citations are formatted as given, but you can define \citeform (with one parameter) to reformat every citation. Some possibilities: \renewcommand\citeform[1]{\romannumeral 0#1}% roman numerals: [iv,x] \renewcommand\citeform[1]{(#1)} % parentheses: [(3),(4),(7)] - \renewcommand\citeform[1]{\thechapter.#1} % number by chapter: [3.9,3.10] - If you change \citeform, you should define \@biblabel to match. - \citepunct gives the punctuation (comma-penalty-space) between items. + If you change \citeform, you should probably define \@biblabel to match. + + Another not-so-good example to provide a chapter-number prefix is + \renewcommand\citeform[1]{\thechapter.#1} % number by chapter. + This partially works, but has only limited applicability: it does not + work with cites in the front-matter (TOC, LOF) or with hyperref. + Instead, there is a \CitationPrefix command to apply a prefix to the + citation numbers (or names) in the bibliographies and \cite commands + for the included files. Use it by declaring something like + \CitationPrefix{\thechapter.} + in the preamble. The prefix will be applied to all the chapter-bibs + but will not be used in an overall (root) bibliography, if you have one. + + \citepunct gives the punctuation (comma-penalty-space) between items + in the \cite list. %====================== END INSTRUCTIONS =========================== % @@ -408,14 +495,11 @@ % ~~~~~~~~~~~~~~~~~~~~~~~~~ % These customization hooks are present in cite.sty; others (\citemid, % \citeleft, \citeright) are not defined here because \@cite is not redefined. +% LaTeX has now adopted \@cite@ofmt, which is normally \hbox, so use both. % % We redefine \@testdef so that it properly checks whether the % \cite labels have changed. % -% Handle package options and redefining thebibliography. [sectionbib] -% converts "\chapter*{...}" to "\section*{\bibname\markright{\bibname}% -% \addcontentsline{toc}{section}{\bibname}}" -% % Table of contents etc: % ~~~~~~~~~~~~~~~~~~~~~~ % As of version 1.8, definitions of \@extra@b@citeb are written to the @@ -425,11 +509,22 @@ % be sequenced by where they originated -- but the problem was worse with % chapterbib. % +% \CitationPrefix: +% ~~~~~~~~~~~~~~~~ +% This is a really ugly hack, but \citeform worked poorly for putting +% a chapter-identifier on each cite. It locally redefines both +% \@bibitem and \@lbibitem at each \bibliography. The insertion +% of the prefix is straightforward for \@lbibitem, but for \@bibitem +% the prefix is inserted by a redefined \value macro (eeek!). +% %--------------------------------------------------------------- % % Authors Niel Kempson (original) -% ~~~~~~~ Donald Arseneau <asnd@triumf.ca> March 1993 - Feb 2004 +% ~~~~~~~ Donald Arseneau <asnd@triumf.ca> March 1993 - Mar 2009 % +% Changes with ver 1.14: No warning from \nocite* in chapters, \CitationPrefix +% Changes with ver 1.13: Rewrite final-bibs titling +% Changes with ver 1.12: Update \@citex \bfseries % Changes with ver 1.11: Follow LaTeX's barring \nocite from preamble % Changes with ver 1.10: \CBMainSectioning; \bibsection hook % Changes with ver 1.9: sectionbib remove \@mkboth |