3

I have split my bibliography thematically in several reference segments at the end of my article. I would like to use \nocite locally inside some of the segment environments, but that seems not possible with \refsegment, it still acts globally. Here is an example:

\documentclass[10pt,a4paper,reqno]{amsart} 

\usepackage[
    backend=biber,
    %heading = references,
    citestyle=alphabetic,
    bibstyle=alphabetic,
    sorting=anyvt,
    backref=true,
    backrefstyle=none,
    locallabelwidth=true
    ]{biblatex}

\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm} 

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@Book{Ahl,
author = {Ahlfors, L. V.},
title = {Complex Analysis, An Introduction to the Theory of Analytic Functions of One Complex Variable},
edition = {3},
publisher = {McGraw-Hill},
year = {1979},
keywords = {complex analysis}
}

@Book{BerGay,
author = {Berenstein, C. A. and Gay, R.},
title = {Complex Variables, An Introduction},
publisher = {Springer},
year = {1991},
keywords = {complex analysis}
}

@Book{AM,
author = {Atiyah, M. F. and MacDonald, I. G.},
title = {Introduction to Commutative Algebra},
publisher = {Addison-Wesley},
year = {1969},
keywords = {Algebra}
}

@Book{HoffKun,
author = {Hoffman, K. and Kunze, R.},
title = {Linear Algebra},
publisher = {Prentice-Hall},
edition = {2},
year = {1971},
keywords = {Algebra}
}

@Book{GrRem,
author = {Grauert, H. and Remmert, R.},
title = {Coherent Analytic Sheaves},
publisher = {Springer},
year = {1984}
}

@Book{Loday,
author = {Loday, J.-L.},
title = {Cyclic Homology},
publisher = {Springer},
year = {1998},
edition = {2}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{Ahl}, \cite{AM}, \cite{GrRem} are great books. 

\begin{refsegment}
\nocite{*}
\printbibliography[keyword={complex analysis},title={References on Complex Analysis}]   
\end{refsegment}

\begin{refsegment}
    \printbibliography[keyword={Algebra},title={References on Algebra}] 
\end{refsegment}

\printbibliography[notkeyword={complex analysis},notkeyword={Algebra},title={Other References}]

\end{document}

I know that \nocite behaves locally with \refsection, but I don't want to split my .bib file in various different .bib files, and moreover, the biblatex manual says that \refsegment is the intended environment for my case :-) Indeed \refsection behaves a little funky when I use the same .bib file for different reference sections.

An ugly workaround would be to group together all \nocite reference segments after the no-\nocite reference segments, but this breaks the logical order of the topics.

Does anyone know a solution for this?

moewe
  • 175,683
M.G.
  • 547
  • Mmh, that's interesting, I report I can reproduce the described behavior. I'm not sure it is expected. But, alas, I don't know how to solve it. – gusbrs Dec 01 '18 at 11:24
  • Since refsegments basically just add a marker (much like a keyword) to an entry and otherwise don't change anything it is sort of expected that \nocite{*} would add all entries. In fact I have a hard time figuring out how a local \nocite{*} should work, but I might be missing something (are you using \nocite with an argument different from *, i.e. a \nocite{sigfridsson}?). A short example document (https://tex.meta.stackexchange.com/q/228/3586 or https://tex.meta.stackexchange.com/q/4407/35864) might help me understand what is going on in more detail. – moewe Dec 01 '18 at 11:34
  • @moewe: Thanks for the reply! No, I am just using the standard \nocite{*} in basic amsart or report, see my edit. Do you still need me to include a full MWE? – M.G. Dec 01 '18 at 11:51
  • Yes, please include a full MWE. I'm still struggling to understand what exactly you are after. In your example a normal \cite{sigfridsson} should behave exactly the same as a \nocite{*}. – moewe Dec 01 '18 at 11:53
  • @moewe How so? If a refsegment works like a marker, why should a \nocited entry show up in the bibliography of another refsegment? (And it does https://gist.github.com/gusbrs/ba5686c28efc631343c9a128061c9707). – gusbrs Dec 01 '18 at 11:57
  • @gusbrs It's a marker that is not evaluated or acted upon by default, cf. https://gist.github.com/moewew/5d73e4b075e9332f65cd5c1a159feb3f – moewe Dec 01 '18 at 12:05
  • @gusbrs That is to say the OP could probably get what they ask for with segment=\therefsegment, but I don't know whether that is really what they want or need and I don't understand why the question only asks about \nocite when a normal \cite has the same effect. (Of course that could be explained if the OP simply does not use \cite...) – moewe Dec 01 '18 at 12:10
  • @moewe Ah, I get your point. Indeed segment=\therefsegment was the missing piece here. Thanks. That likely is also the solution for the OP, but indeed, more info is needed to know for sure. – gusbrs Dec 01 '18 at 12:14
  • @moewe: finished adding a MWE, I hope I have not forgotten anything important. I have cited one reference from each group, yet all six references are listed in the bibliography, while I would like only the first group of references to be listed in the full. I hope I am explaining that well. What am I doing wrong? – M.G. Dec 01 '18 at 12:18
  • The MWE was almost good, I had to change a few things to make it compilable (the name of the .bib file should not be \references.bib). I also removed the title of the paper, because it is not important. I also changed algebra to Algebra, so the second bibliography would print something. Please always test your MWEs in a new, empty directory before you send them off. What output would you want from your MWE? What should be different? For me the MWE already looks quite sensible: No entry appears twice, everything is sorted as expected ... – moewe Dec 01 '18 at 12:26
  • @moewe A comment on "not evaluated or acted upon by default". The documentation for \printbibliography states for segment the default: 0 which is supposed to mean "outside a refsegment environment" and not quite "not acted upon". – gusbrs Dec 01 '18 at 12:28
  • @gusbrs Mhhh, I guess that's a lie, my tests seem to suggest otherwise. I hope I can investigate this later, but if I forget, feel free to open a bug report to remind me. – moewe Dec 01 '18 at 12:31
  • @moewe: oops, thanks for fixing the mwe. Under "References on Algebra" and "Other References" only the cited references should appear. Yet all references from the .bib file appear there because \nocite acts globally spreading outside of the first refsegment. So how do I fix that? – M.G. Dec 01 '18 at 12:32
  • Aha! Now I understand. – moewe Dec 01 '18 at 12:35
  • @moewe If I grasp this correctly, probably what's going on is the following. refsegment is useful when we need a global bibliography alongside separated ones. The option segment in printbibliography is an integer. 0 may really be the default, but if so it is somehow hardwired to mean "all refsegments", because that's what we need for a global bibliography. Implicitly, to get the global bibliography, segment has to be ommited. If an option segment=all existed, the default could be, more naturally, segment=\therefsegment. I'm guessing here... But, ok, more on github, if need be. – gusbrs Dec 01 '18 at 12:50
  • 1
    @gusbrs The default is not segment=0, instead the default is nothing at all. Similar to, say, filtering by type= or category=. I have changed the docs (I'm currently in the process of tweaking the docs on a larger scale, so this change might be committed a little later with the other changes I have lined up). – moewe Dec 01 '18 at 14:17

1 Answers1

3

As mentioned in the comments, refsegments only add a marker to entries (much like keywords or category), it does not do much more. By default biblatex does not even evaluate the marker, so an entry \nocite{*}/\nocite'd in one refsegment will naturally appear in all other segments as well.

If you want to restrict a \printbibliography to one refsegment, you have to use the segment option. This might work as follows

\documentclass[10pt,a4paper,reqno]{amsart} 
\usepackage[
    backend=biber,
    style=alphabetic,
    sorting=anyvt,
    backref=true,
    backrefstyle=none,
    locallabelwidth=true
    ]{biblatex}

\newrobustcmd{\mklocalfilter}[1]{%
  \defbibfilter{#1}{%
    segment=0
    or
    segment=\therefsegment
  }}    

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Ahl,
  author = {Ahlfors, L. V.},
  title = {Complex Analysis, An Introduction to the Theory of Analytic Functions of One Complex Variable},
  edition = {3},
  publisher = {McGraw-Hill},
  year = {1979},
  keywords = {complex analysis}
}
@book{BerGay,
  author = {Berenstein, C. A. and Gay, R.},
  title = {Complex Variables, An Introduction},
  publisher = {Springer},
  year = {1991},
  keywords = {complex analysis}
}
@book{AM,
  author = {Atiyah, M. F. and MacDonald, I. G.},
  title = {Introduction to Commutative Algebra},
  publisher = {Addison-Wesley},
  year = {1969},
  keywords = {algebra}
}
@book{HoffKun,
  author = {Hoffman, K. and Kunze, R.},
  title = {Linear Algebra},
  publisher = {Prentice-Hall},
  edition = {2},
  year = {1971},
  keywords = {algebra}
}
@book{GrRem,
  author = {Grauert, H. and Remmert, R.},
  title = {Coherent Analytic Sheaves},
  publisher = {Springer},
  year = {1984}
}
@book{Loday,
  author = {Loday, J.-L.},
  title = {Cyclic Homology},
  publisher = {Springer},
  year = {1998},
  edition = {2}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\cite{Ahl}, \cite{AM}, \cite{GrRem} are great books. 

\begin{refsegment}
\mklocalfilter{nocitelocal}
\nocite{*}
\printbibliography[keyword={complex analysis},filter=nocitelocal,title={References on Complex Analysis}]   
\end{refsegment}

% only cited entries, please
\printbibliography[keyword={algebra},segment=0,title={References on Algebra}] 

% only cited entries, please
\printbibliography[notkeyword={complex analysis},notkeyword={algebra},segment=0,title={Other References}]
\end{document}

The MWE shows three citations and three bibliographies. The first bibliography contains both cited and uncited entries, while the other two bibliographies only have cited entries.

Note that segment=0 applies to all entries outside a specific refsegment and that the bibfilter nocitelocal is defined locally directly in the refsegment in order to use the variable \therefsegment.

In this setup all entries that were explicitly \cite'd were cited in section=0, but \nocite{*} happened in segment=1. Hence restricting a bibliography to segment=0 gives all cited entries, allowing the current segment as well gives a way to locally \nocite{*} all entries.


If we look at your problem from a different angle though, it seems to me more natural to reformulate it as follows: How can I \nocite only entries with a certain keyword? Unfortunately, as Is it possible to add entries to the bibliography based on keyword using Biblatex/Biber and within the document code? and other questions on this site show, there is no universal way to do that. One has to find sly workarounds.

In your case we can apply How to split bibliography into "works cited" and "works not cited"? and come up with

\documentclass[10pt,a4paper,reqno]{amsart} 

\usepackage[
    backend=biber,
    %heading = references,
    style=alphabetic,
    sorting=anyvt,
    backref=true,
    backrefstyle=none,
    locallabelwidth=true
    ]{biblatex}

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

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Ahl,
  author = {Ahlfors, L. V.},
  title = {Complex Analysis, An Introduction to the Theory of Analytic Functions of One Complex Variable},
  edition = {3},
  publisher = {McGraw-Hill},
  year = {1979},
  keywords = {complex analysis}
}
@book{BerGay,
  author = {Berenstein, C. A. and Gay, R.},
  title = {Complex Variables, An Introduction},
  publisher = {Springer},
  year = {1991},
  keywords = {complex analysis}
}
@book{AM,
  author = {Atiyah, M. F. and MacDonald, I. G.},
  title = {Introduction to Commutative Algebra},
  publisher = {Addison-Wesley},
  year = {1969},
  keywords = {algebra}
}
@book{HoffKun,
  author = {Hoffman, K. and Kunze, R.},
  title = {Linear Algebra},
  publisher = {Prentice-Hall},
  edition = {2},
  year = {1971},
  keywords = {algebra}
}
@book{GrRem,
  author = {Grauert, H. and Remmert, R.},
  title = {Coherent Analytic Sheaves},
  publisher = {Springer},
  year = {1984}
}
@book{Loday,
  author = {Loday, J.-L.},
  title = {Cyclic Homology},
  publisher = {Springer},
  year = {1998},
  edition = {2}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\nocite{*}
\begin{document}
\cite{Ahl}, \cite{AM}, \cite{GrRem} are great books. 

% all entries, cited and uncited
\printbibliography[keyword={complex analysis},title={References on Complex Analysis}]   

% only cited entries, please
\printbibliography[keyword={algebra},category=cited,title={References on Algebra}] 

% only cited entries, please
\printbibliography[notkeyword={complex analysis},notkeyword={algebra},category=cited,title={Other References}]
\end{document}

The screenshot of the MWE shows three bibliographies. The first contains one cited and an uncited entry. The other two bibliographies only contain cited entries.

moewe
  • 175,683