2

Sometimes, when citing a reference, I would like to add a note into the printed references. I know enough biblatex to get the note printed once it is inside the citation record (e.g. the note field). However, since the note is not really a general attribute of the cited reference but rather concerns the particular context where it is cited, I do not want to add the note to the bibliography database, such as adding a note to the .bib file. Instead, I would like to add that data from within my LaTeX document. Surely, biblatex's flexible data model has a way to do this?

EDIT: To conform with the always have a MWE(B), even if it is really just a copy of the most basic biblatex template:

\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{key,
  author = {Author, A.},
  year = {2001},
  title = {Title},
  publisher = {Publisher},
}
\end{filecontents}

\newcommand\notecite[2]{%
    \cite{#1}%
    % some magic biblatex to set note field in record
    % corresponding to key #1 to #2
}
\begin{document}

\notecite{key}{That is what we're talking about!}

\printbibliography

\end{document}

The question is, what magic to put into \notecite.

  • 1
    Maybe there's a simplest way, but I think it is possible to put one (or more) if within a \AtEveryBibitem{...} to test the citekey you would like to comment and add its specific text. If you add a minimal working example with bibliography (MWEB) I'll try to do it. – CarLaTeX Dec 15 '16 at 15:30
  • Thanks for the suggestion, but if in \AtEveryBibitem to test for keys doesn't sound very elegant to me. I was hoping to find something around biblatex's sourcemapping features. – burnpanck Dec 15 '16 at 17:51
4

I don't think you can use source mapping for this since source mapping is done at the biber stage, not the LaTeX stage.

What about this?

\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{key1,
  author = {AuthorA, A.},
  year = {2001},
  title = {Title1},
  publisher = {Publisher1},
}
@book{key2,
  author = {AuthorB, A.},
  year = {2001},
  title = {Title2},
  publisher = {Publisher2},
}
\end{filecontents}
\makeatletter
\newcommand\citewithnote[2]{%
  \csdef{abx@field@note@#1}{#2}%
  \cite{#1}%
}
\AtEveryBibitem{%
  \ifcsdef{abx@field@note@\thefield{entrykey}}
    {\def\abx@field@note{\csuse{abx@field@note@\thefield{entrykey}}}}{}%
}
\makeatother
\pagestyle{empty}
\begin{document}
\citewithnote{key1}{That is what we're talking about!}
\citewithnote{key2}{A different note}
\printbibliography
\end{document}

enter image description here

  • Great! I didn't know that \AtEveryBibitem{...} can be used more than once in a document. – CarLaTeX Dec 16 '16 at 4:56
  • Looks great! I assume \abx@field@note is the macro where biblatex stores the value of the note field for the current bibitem? Does this also work when mixed with normal citations? Wouldn't that require some sort of test if \abx@field@note@somekey is defined at all? – burnpanck Dec 16 '16 at 13:07
  • @burnpanck, yes it does need a test if \abx@field@note@somekey is defined. I was a bit lazy. I'll fix the example – David Purton Dec 16 '16 at 13:25
  • updated example with a test to make sure \abx@field@note@somekey is defined. – David Purton Dec 17 '16 at 0:59

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.