2

I am using @moewe's answer in: Bibliography per chapter and a global bibliography in alphabetic order

I would like for the references used AFTER the global bibliography to not be included in it. Here's a modified MWE from the link above:

\documentclass{report}
\usepackage{chemmacros}
\usepackage[style=chem-acs,articletitle=true,chaptertitle=true,bibencoding=utf8,refsection=chapter,maxbibnames=99]{biblatex}

\addbibresource{test.bib}


\DeclareBibliographyCategory{cited}
\AtEveryCitekey{\addtocategory{cited}{\thefield{entrykey}}}

\makeatletter
\newcount\c@globalpageref

\defbibenvironment{globalbibliography}
{\list
    {}
    {\setlength{\leftmargin}{\bibhang}%
        \setlength{\itemindent}{-\leftmargin}%
        \setlength{\itemsep}{\bibitemsep}%
        \setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item
    \iflistundef{globalpageref}
    {}
    {\savelist{globalpageref}{\tmpblx@pageref}%
        \c@pageref\c@globalpageref
        \restorelist{pageref}{\tmpblx@pageref}}}


\protected\def\blx@aux@backref#1#2#3#4#5{%
    \ifcsundef{blx@pref@#3@\detokenize{#2}}
    {\global\cslet{blx@pref@#3@\detokenize{#2}}\@empty
        \expandafter\blx@onlypreamble\csname blx@pref@#3@\detokenize{#2}\endcsname}
    {}%
    \ifinlistcs{#4}{blx@pref@#3@\detokenize{#2}}
    {}
    {\listcsgadd{blx@pref@#3@\detokenize{#2}}{#4}}%
    \ifcsundef{blx@pref@global@\detokenize{#2}}
    {\global\cslet{blx@pref@global@\detokenize{#2}}\@empty}
    {}%
    \ifinlistcs{#4}{blx@pref@global@\detokenize{#2}}
    {}
    {\listcsgadd{blx@pref@global@\detokenize{#2}}{#4}}%
    \blx@addpagesum{#1}{#5}}
\let\abx@aux@backref\blx@aux@backref


\AtDataInput{%
    \ifcsundef{blx@pref@global@\abx@field@entrykey}
    {}
    {\blx@addpagerefglobal{\abx@field@entrykey}}}

\def\blx@addpagerefglobal#1{%
    \begingroup
    \blx@tempcnta\z@
    \let\blx@tempa\@empty
    \def\do##1{%
        \appto\blx@tempa{{##1}}%
        \advance\blx@tempcnta\@ne}%
    \dolistcsloop{blx@pref@global@#1}%
    \edef\blx@tempa{\endgroup\noexpand\blx@bbl@listdef
        {globalpageref}{\the\blx@tempcnta}{\blx@tempa}}%
    \blx@tempa
}
\makeatother


\begin{document}
\chapter{Chapter 1}
Foo foo \autocite{Fujita1999}. Bar Bar \autocite{Felton2007}.
\printbibliography[heading=subbibliography]

\chapter{Chapter 2}
Foo foo \autocite{Fujita1999}. Bar Bar \autocite{Felton2009}.
\printbibliography[heading=subbibliography]

\newrefsection
\nocite{*}
\newrefcontext[sorting=nyt]
\printbibliography[env=globalbibliography, title={Global Bibliography}, category=cited]

\appendix

\chapter{Appendix 1}
Bla ble bli \autocite{Ghadiri1992}. Foo bar \autocite{Fujita1999}.
\printbibliography[heading=subbibliography]
\end{document}

The test.bib file is:

 @article{Felton2009,
  author = {Felton, Greg A. N. and Mebi, Charles A. and Petro, Benjamin J. and Vannucci, Aaron K. and Evans, Dennis H. and Glass, Richard S. and Lichtenberger, Dennis L.},
  title = {Review of electrochemical studies of complexes containing the \ch{Fe2S2} core characteristic of [FeFe]-hydrogenases including catalysis by these complexes of the reduction of acids to form dihydrogen},
  journal = {Journal of Organometallic Chemistry},
  volume = {694},
  number = {17},
  pages = {2681-2699},
  DOI = {https://doi.org/10.1016/j.jorganchem.2009.03.017},
  url = {http://www.sciencedirect.com/science/article/pii/S0022328X09001946},
  year = {2009},
  type = {Journal Article}
 }

 @article{Felton2007,
  author = {Felton, Greg A. N. and Vannucci, Aaron K. and Chen, Jinzhu and Lockett, L. Tori and Okumura, Noriko and Petro, Benjamin J. and Zakai, Uzma I. and Evans, Dennis H. and Glass, Richard S. and Lichtenberger, Dennis L.},
  title = {Hydrogen Generation from Weak Acids: Electrochemical and Computational Studies of a Diiron Hydrogenase Mimic},
  journal = {Journal of the American Chemical Society},
  volume = {129},
  number = {41},
  pages = {12521-12530},
  DOI = {10.1021/ja073886g},
  url = {https://doi.org/10.1021/ja073886g},
  year = {2007},
  type = {Journal Article}
 }

 @article{Fujita1999,
  author = {Fujita, Etsuko},
  title = {Photochemical carbon dioxide reduction with metal complexes},
  journal = {Coordination Chemistry Reviews},
  volume = {185-186},
  pages = {373-384},
  keywords = {Carbon dioxide reduction
   Small molecule activation
   Photocatalysis
   Carboxylates
   Macrocycles
   Diimine},
  DOI = {https://doi.org/10.1016/S0010-8545(99)00023-5},
  url = {http://www.sciencedirect.com/science/article/pii/S0010854599000235},
  year = {1999},
  type = {Journal Article}
 }

@article{Ghadiri1992,
   author = {Ghadiri, M. R. and Soares, C. and Choi, C.},
   title = {A convergent approach to protein design. Metal ion-assisted spontaneous self-assembly of a polypeptide into a triple-helix bundle protein},
   journal = {Journal of the American Chemical Society},
   volume = {114},
   number = {3},
   pages = {825-831},
   DOI = {10.1021/ja00029a004},
   url = {<Go to ISI>://WOS:A1992HB53700004},
   year = {1992},
   type = {Journal Article}
}
@article{Ghirlanda2002,
   author = {Ghirlanda, G. and Lear, J. D. and Ogihara, N. L. and Eisenberg, D. and DeGrado, W. F.},
   title = {A hierarchic approach to the design of hexameric helical barrels},
   journal = {Journal of Molecular Biology},
   volume = {319},
   number = {1},
   pages = {243-253},
   DOI = {10.1016/s0022-2836(02)00233-4},
   url = {<Go to ISI>://WOS:000176042700019},
   year = {2002},
   type = {Journal Article}
}

As you can see, references that only appear in the appendix (after the Global References) are also included in the Global References. I would like them to be disregarded (yet, have a local References section after the Appendix for whatever was cited within).

  • Haven't tested it, because I should get some sleep now, but have you tried adding \newrefsection before \appendix (or \chapter{Appendix 1})? Or are we only talking about the pageref? – moewe Jun 24 at 21:05
  • @moewe Just tried it, didn't work :/. The work around I'm using is to have a separate bib file with the refs in appendices and a particular keyword and assigning those to a category appendix while using notcategory=appendix when printing the global references – ralk912 Jun 24 at 21:13
3

The code sets the category cited at every cite key. You can make this category conditional on if you are in the appendix or not. In the code below a boolean \ifapx is created that is initially false, and (manually) set to true in the appendix. The \AtEveryCitekey command uses this boolean to add the cited category only in the main text.

Code:

\documentclass{report}
\usepackage{chemmacros}
\usepackage[style=chem-acs,articletitle=true,chaptertitle=true,bibencoding=utf8,refsection=chapter,maxbibnames=99]{biblatex}

\addbibresource{fgtest.bib}

\newif\ifapx
\apxfalse

\DeclareBibliographyCategory{cited}
\AtEveryCitekey{\ifapx\relax\else\addtocategory{cited}{\thefield{entrykey}}\fi}

\makeatletter
\newcount\c@globalpageref

\defbibenvironment{globalbibliography}
{\list
    {}
    {\setlength{\leftmargin}{\bibhang}%
        \setlength{\itemindent}{-\leftmargin}%
        \setlength{\itemsep}{\bibitemsep}%
        \setlength{\parsep}{\bibparsep}}}
{\endlist}
{\item
    \iflistundef{globalpageref}
    {}
    {\savelist{globalpageref}{\tmpblx@pageref}%
        \c@pageref\c@globalpageref
        \restorelist{pageref}{\tmpblx@pageref}}}


\protected\def\blx@aux@backref#1#2#3#4#5{%
    \ifcsundef{blx@pref@#3@\detokenize{#2}}
    {\global\cslet{blx@pref@#3@\detokenize{#2}}\@empty
        \expandafter\blx@onlypreamble\csname blx@pref@#3@\detokenize{#2}\endcsname}
    {}%
    \ifinlistcs{#4}{blx@pref@#3@\detokenize{#2}}
    {}
    {\listcsgadd{blx@pref@#3@\detokenize{#2}}{#4}}%
    \ifcsundef{blx@pref@global@\detokenize{#2}}
    {\global\cslet{blx@pref@global@\detokenize{#2}}\@empty}
    {}%
    \ifinlistcs{#4}{blx@pref@global@\detokenize{#2}}
    {}
    {\listcsgadd{blx@pref@global@\detokenize{#2}}{#4}}%
    \blx@addpagesum{#1}{#5}}
\let\abx@aux@backref\blx@aux@backref


\AtDataInput{%
    \ifcsundef{blx@pref@global@\abx@field@entrykey}
    {}
    {\blx@addpagerefglobal{\abx@field@entrykey}}}

\def\blx@addpagerefglobal#1{%
    \begingroup
    \blx@tempcnta\z@
    \let\blx@tempa\@empty
    \def\do##1{%
        \appto\blx@tempa{{##1}}%
        \advance\blx@tempcnta\@ne}%
    \dolistcsloop{blx@pref@global@#1}%
    \edef\blx@tempa{\endgroup\noexpand\blx@bbl@listdef
        {globalpageref}{\the\blx@tempcnta}{\blx@tempa}}%
    \blx@tempa
}
\makeatother


\begin{document}
\chapter{Chapter 1}
Foo foo \autocite{Fujita1999}. Bar Bar \autocite{Felton2007}.
\printbibliography[heading=subbibliography]

\chapter{Chapter 2}
Foo foo \autocite{Fujita1999}. Bar Bar \autocite{Felton2009}.
\printbibliography[heading=subbibliography]

\newrefsection
\nocite{*}
\newrefcontext[sorting=nyt]
\printbibliography[env=globalbibliography, title={Global Bibliography}, category=cited]

\appendix
\apxtrue
\chapter{Appendix 1}
Bla ble bli \autocite{Ghadiri1992}. Foo bar \autocite{Fujita1999}.
\printbibliography[heading=subbibliography]
\end{document}

Result:

enter image description here

  • Ah I did think of using an if statement (and notice the problem might have been with that AtEveryCitekey, but I couldn't find how to declare it ! – ralk912 Jun 24 at 21:14
  • 1
    It's a bit of a workaround, there probably is a solution from within biblatex that properly separates the reference sections - but this was quick and it worked... – Marijn Jun 24 at 21:18
  • You're right, I always get excited when something is easy and works! :P I'll wait, but I think this is a pretty good way to do this =) – ralk912 Jun 24 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.