10

In chemistry it's quite common to add prefixes to bibitems or even add notes to the references. See some example in literature to give you a hint what I mean. It is not created with LaTeX!

I've fiddled around with biblatex + biber and the \mcite and \bibnote comand, but came to no solution. I want to add some text in certain references with subentries before the bibitem.

I created this MWE:

\documentclass[english]{article}
\usepackage{selinput}
\SelectInputMappings{adieresis={ä},germandbls={ß},Euro={€}}
\usepackage{babel}
\usepackage[T1]{fontenc}

\usepackage[%
  citestyle=numeric-comp,
  bibstyle=chem-angew,
  sorting=none,
  backend=biber,
  mcite=true,
  subentry,
]{biblatex}
\usepackage{notes2bib}
\usepackage{filecontents}

\begin{filecontents}{example.bib}
@article{Boncella1984,
author = {Boncella, James M. and Andersen, Richard A.},
journal = {Inorg. Chem.},
pages = {432--437},
volume = {23},
year = {1984}
}

@article{Tilley1982,
author = {Tilley, T. Don and Andersen, Richard},
journal = {J. Am. Chem. Soc.},
pages = {1772--1774},
volume = {104},
year = {1982}
}
\end{filecontents}

\addbibresource{example.bib} 

\begin{document}
\section{sec1}

This is some nice text I want to cite.\mcite{set1,*Boncella1984,*Tilley1982}
I want to add this note in references.\bibnote{test note}
Here I cite a single paper from the previous set.\cite{Tilley1982} This is how it should look like with included note.\bibnote{See, for example: \fullcite{set1}}

\printbibliography
\end{document} 

I'm fine with the subentries how they're created in ref 1 by:

\mcite{set1,*Boncella1984,*Tilley1982}

and with citing members of the set by referencing just one key from the predefined set1:

 \cite{Tilley1982}

I'm also fine with notes which I can add to references section like in ref 2 by:

\bibnote{test note}

But I also need to add some text before the bibitem in a certain reference. This should look like in ref 3. However,

\bibnote{See, for example: \fullcite{set1}}

gives me only an endnote followed by a copy of ref 1. This is not applicable as I have to define set1 with \mcite before, which results of course in 2 referneces. Ref 3 is only for demonstration how it should look like. I'm not able to get a single reference which looks like ref 3. Something like

\bibnote{See, for example:\mcite{set1,*Boncella1984,*Tilley1982}}

doesn't work. It gives me 2 references.

How can I create a reference with text followed by subentries? I also want to have the opportunity to cite single members of the set elsewhere, like in ref 1b.

Edit 1:

This is some nice text I want to cite.\bibnote{some added text:\mcite{set1,*Boncella1984,*Tilley1982}}
I want to add this note in references.\bibnote{test note}
Here I cite a single paper from the previous set.\cite{Tilley1982} This is how it should look like with included note.\bibnote{more added text: \fullcite{set1}}

gives me the following:

\bibnote{some added text:\mcite{set1,*Boncella1984,*Tilley1982}}

just adds the text followed by reference in brackets as you can see in ref 1 in the 2nd example. I just want to create a reference with subentries in which some text is followed by subentry (a). It should look like in ref 3. However, ref 3 is just constructed to give you the look. It can not be created as "stand alone" reference, only in combination with a second.

Edit 2:

as it seems still not clear. Apllying only this:

\begin{document}
\section{sec1}

This is some nice text I want to cite.\bibnote{some added text:\mcite{set1,*Boncella1984,*Tilley1982}}

\printbibliography
\end{document} 

gives me the following output: enter image description here

in which 2 references are created instead of 1 desired and none looks the way I want it.

Edit 3:

Inspired by this question I created an example. However, the added note is of course after the corresponding bibitem as in the quoted question. How can I get the added notes before my bibitems, but still after the reference number [X]? I've got a huge document in which every chapter has its own references. Addition of notes seems to work, however not elegant. Since, my notes are work (chapter) related, I don't want to edit my *.bbl. However, the chosen way with loadfiles is not very elegant. But I'm still able to place my note in near of \cite commands. It would be not applicable to put all the notes in the preamble of the document or elsewhere.

To repeat my question: How can I get the added notes in front of my bibiem applying the \loadfiles option to have them look like ref 3 in above examples?

\documentclass[english]{article}
\usepackage{selinput}
\SelectInputMappings{adieresis={ä},germandbls={ß},Euro={€}}
\usepackage{babel}
\usepackage[T1]{fontenc}

\usepackage[%
 citestyle=numeric-comp,
   bibstyle=chem-angew,
   sorting=none,
  backend=biber,
  mcite=true,
  subentry,
  loadfiles=true,
]{biblatex}
\usepackage{notes2bib}
\usepackage{filecontents}

\begin{filecontents}{example.bib}
@article{Boncella1984,
author = {Boncella, James M. and Andersen, Richard A.},
journal = {Inorg. Chem.},
pages = {432--437},
volume = {23},
year = {1984}
}

@article{Tilley1982,
author = {Tilley, T. Don and Andersen, Richard},
journal = {J. Am. Chem. Soc.},
pages = {1772--1774},
volume = {104},
year = {1982}
}
\end{filecontents}

\DeclareFieldFormat{annotation}{#1}
\renewbibmacro*{annotation}{
  \IfFileExists{notes/note-\thefield{entrykey}.tex}{\par}{}
  \printfile[annotation]{notes/note-\thefield{entrykey}.tex}
}

\AtEveryBibitem{
\csappto{blx@bbx@\thefield{entrytype}}{\usebibmacro{annotation}}
}

\addbibresource{example.bib} 

\begin{document}
\section{sec1}
\begin{refsection}
This is some text I want to cite.\mcite{set1,*Boncella1984,*Tilley1982}
\begin{filecontents}{notes/note-set1.tex}
hello world
\endinput
\end{filecontents}
\printbibliography
\end{refsection}

\section{sec2}
\begin{refsection}

This is even more text I want to cite.\mcite{set2,*Boncella1984,*Tilley1982}

\begin{filecontents}{notes/note-set2.tex}
hello again
\endinput
\end{filecontents}
\printbibliography
\end{refsection}
\end{document}

enter image description here

user49794
  • 135
  • Welcome to TeX SE. First, it is great that you post code but you need to complete it. I don't have library.bib so I can't reproduce the issue. I tried faking a couple of entries with appropriate names but when I did that, the output looked fine. So either your entries have a twist missing in my fakes or I'm not understanding what the problem is. – cfr Apr 13 '14 at 01:55
  • I'm sorry, but I do not seem to fully grasp your problem. What output exactly do you expect and what do you get? Also a full compilable MWE where you include library.bib or use entries from biblatex-examples.bib (the latter comes shipped with all biblatex versions in the doc folder) would be very much appreciated. Something very similar to your last line of code worked fine here. (While you are at it you might want to find out your biblatex and Biber versions just in case.) – moewe Apr 13 '14 at 06:18
  • Sorry for asking again, but what is wrong with the way ref. 3 is created? If it is the output you want (I think it is since you are claiming the output should look like ref. 3) what is wrong with obtaining it that way? – moewe Apr 13 '14 at 11:23
  • I expect to look ref 1 like ref 3 in the 2nd example. However as I mentioned above. Ref 3 is just constructed, it gives you always the reference without added text like in ref 4, too. So what I want is a single! reference which looks like ref 3. This is not possible. – user49794 Apr 13 '14 at 11:28
  • The problem is that a \bibnote is something like an \endnote (in disguise) and the citation will be processed after the \endnote [that is \bibnote will get a number and the citation within that bibnote will be assigned a number as well, but afterwards. A simple \cite is executed for set1 and this yields the second number]. – moewe Apr 13 '14 at 11:45
  • 1
    This seems to be more complicated than thought. One thing though: the bibliography is really not the place to place comments before entries. – moewe Apr 13 '14 at 12:02
  • This is nothing extrordinary. This standard in Chemistry and Physics and is published in exactly this way. And many user are looking to solve this problem. – user49794 Apr 13 '14 at 12:08
  • Hmm, but these documents might have used \fullcite. – moewe Apr 13 '14 at 12:16
  • In this question it is described to get notes after an reference using loadfiles. How to change the code to get the note before the reference? – user49794 Apr 13 '14 at 14:33
  • Note that I got output of exactly the kind you seemed to want when I tried this as I described above i.e. note before citations in a single reference with one number. – cfr Apr 13 '14 at 15:42
  • Is the point that you don't want to write \fullcite? – cfr Apr 13 '14 at 15:55
  • 1
    There is a reason biblatex-chem doesn't attempt to cover this: I don't feel there is a workable interface on an automated basis. The way that (some) chemists give compound citations simply doesn't work: there are too many different ways people include notes. – Joseph Wright Apr 13 '14 at 16:52
  • 1
    @cfr 'bibliography is really not the place to place comments before entries': The example given in the question is actually quite 'tame' by chemistry standards. A classic form is to have a citations which has (1) an introductory sentence, (2) 'see for example', (3) subdivision of the examples (say by metal, or ...), (4) citation of some (but not all!) of those individually labelled cases, (5) post-text of the form 'and references cited therein' :-) – Joseph Wright Apr 13 '14 at 16:54
  • I already figured out that there seems not to be an automated solution. However, many people seem to need this feature of adding text. And what "manual" possibilities are there to add text before references and especially before references with subentries? – user49794 Apr 13 '14 at 16:59
  • @JosephWright But why call that a 'bibliography'? It seems more like very elaborate endnotes with a verbose citation style and therefore no need of a bibliography. – cfr Apr 13 '14 at 18:04
  • 1
    @cfr It doesn't matter how it's called. No one insists to call it bibliography. This is the way refernces look like in chemistry. – user49794 Apr 13 '14 at 18:15
  • Use \defbibentryset{set1}{Boncella1984,Tilley19823}\bibnote{See, for example: \fullcite{set1}} instead of \mcite. – Ulrike Fischer Apr 14 '14 at 08:06
  • I applied your code. This seems not to work. This gives again 2! references instead of one: the first with added text, and the second without. – user49794 Apr 14 '14 at 10:17
  • Please check the following answer for an easy solution. https://tex.stackexchange.com/a/422527/56448 – Ravphys Mar 22 '18 at 09:56

1 Answers1

2

Updated

As I understand it, you want to be able to add a note which will be printed at the start of a bibliographical entry (consistently with the use in your field where the bibliography seems to include material which might, in other fields, appear in footnotes or endnotes).

I've had various tries at this during the course of today, getting somewhat closer each time. I think the best solution is probably along these lines:

  1. We define a command \prenotation{key}{text} which writes to the .aux file. The reason for doing it this way is that we need to use \AtEveryBibitem, which can only be used in the preamble; but its inconvenient to have to give all these notations in the preamble (though it would work).

  2. What actually gets written to the .aux file is an internal command which sets up a check that is made at every bibitem. This could slow things down if you have lots of these notes, but I'm assuming that will not be a problem. I've refined the check so that if by any chance a given key gets used more than once (as it might if there are multiple bibliographies) the note gets printed only on the first occasion.

  3. We then need some housekeeping to undefine this internal command (or,rather, to castrate it) so that we don't try to use \AtEveryBibitem when the .aux file gets read in again at the end.

\documentclass[english]{article}
\usepackage{selinput}
\SelectInputMappings{adieresis={ä},germandbls={ß},Euro={€}}
\usepackage{babel}
\usepackage[T1]{fontenc}

\usepackage[%
 citestyle=numeric-comp,
   bibstyle=chem-angew,
   sorting=none,
  backend=biber,
  mcite=true,
  subentry,
  loadfiles=true,
]{biblatex}
\usepackage{notes2bib}
\usepackage{filecontents}

\begin{filecontents}{example.bib}
@article{Boncella1984,
author = {Boncella, James M. and Andersen, Richard A.},
journal = {Inorg. Chem.},
pages = {432--437},
volume = {23},
year = {1984}
}

@article{Tilley1982,
author = {Tilley, T. Don and Andersen, Richard},
journal = {J. Am. Chem. Soc.},
pages = {1772--1774},
volume = {104},
year = {1982}
}
\end{filecontents}

\makeatletter
\newcommand{\prenotation}[2]{%
  \write\@mainaux{\noexpand\bl@makeprenotation{#1}{#2}}}
\newcommand{\bl@makeprenotation}[2]{%
  \AtEveryBibitem{%
    \ifcsdef{bl@prenote#1}
      {}
      {\iffieldequalstr{entrykey}{#1}
         {\expandafter\gdef\csname bl@prenote#1\endcsname{}%
          #2}
         {}}}}
\AtBeginDocument{\let\bl@makeprenotation\@gobbletwo}
\makeatother

\addbibresource{example.bib} 

\begin{document}

\section{sec1}
\begin{refsection}
This is some text I want to cite.\mcite{set1,*Tilley1982,*Boncella1984}
\prenotation{set1}{Here is an introductory text for set 1: }%

\printbibliography
\end{refsection}

\section{sec2}
\begin{refsection}

This is even more text I want to cite \mcite{set2,*Tilley1982,*Boncella1984}, with a note \bibnote{And here is a bibnote.}. 

\prenotation{set2}{Here is an introductory text for set 2: }%

\printbibliography
\end{refsection}
\end{document}

enter image description here

Paul Stanley
  • 18,151
  • This looks promising, however I could not reproduce it. I get this error message. `! LaTeX Error: Can be used only in preamble.

    See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

    l.9 \AtEveryBibitem {\iffieldequalstr {entrykey}{set1}{Here is some text to ...`

    – user49794 Apr 14 '14 at 14:44
  • Eek! Sorry: so do I (latexmk was hiding the error from me). That is what I was trying (and failing) to avoid by using the .aux file. Let me think again, slightly. – Paul Stanley Apr 14 '14 at 14:57
  • I'm using MiKTeX 2.9 biblatex 2.8a and biber 1.8 with WinEdt, as far as this might be relevant. – user49794 Apr 14 '14 at 15:01
  • It wasn't relevant! The fault was all mine. Given the absence of time, I haven't struggled to find a way to do this in such a way that the command can be placed anywhere. This now works, and requires only one run, but the \prenotation commands must, I'm afraid, be put in the preamble. The way to avoid this would be to write them to an external file and read them in, but (my bad) the .aux file is not going to do it. – Paul Stanley Apr 14 '14 at 15:05
  • Okay, this is fine, at least your example. I'll try now to implement it in my thesis... – user49794 Apr 14 '14 at 15:10
  • @user49794 If you are interested in another way to do this, a few days ago I did something very similar in http://tex.stackexchange.com/a/170776/35864. – moewe Apr 14 '14 at 17:21
  • @PaulStanley As far as I can say this seems to work in my specific case so far... I'll still have to check whether it works with multiple identical keys, as several references appear in more than one bibliography. But anyway it's more convenient as your first try, as I'm not confined to the preamble with my notes. What I can say already is, that using \mcite seems to be not compatible with \AtEveryBibitem{\clearfield{month}}, which I need because Mendeley still doesn't allow to select entryfields for export. But this is another question... – user49794 Apr 16 '14 at 00:41
  • Have you tried a \DeclareSourcemap rather than \AtEveryBibitem? Probably better. When you cite a set I doubt the latter can 'see' the relevant entries. If that fails post a new question. – Paul Stanley Apr 16 '14 at 07:37
  • Exactly this is described in this question. – user49794 Apr 16 '14 at 09:48
  • Yes. That's how I'd try to do it. That way the data is altered before it ever enters the .bbl file. – Paul Stanley Apr 16 '14 at 13:45
  • For the time being I managed to compile my thesis including 200+ references. It took me a little trial and error to arrange all the keys in the correct order. Finaly I got my references as I wanted them. Still, the use of all this set-keys is not not the most convenient way to manage it. However, this is the way biblatex implements the mciteplus-package. A wraping command might be more comfortable to avoid the set-keys. – user49794 Apr 16 '14 at 16:02