[Tex/LaTex] How to extract BibTeX entries (as DOI, abstract, etc.)

bibentrybiblatex

I want to automate personal reading notes generation, I'd like to be able to automatically extract a field's content from a BibTeX entry (other than year or author).

E.g. given a BibTeX entry

@article{einstein05,
   author={Albert Einstein},
   title={Zur Elektrodynamik bewegter K{\"o}rper},
   abstract={Interesting article, which claims that time is relative.},
   journal={Annalen der Physik und Chemie},
   volume={17},
   year={1905},
   pages={891--921}
}

I want to have a macro in my TeX file (e.g. \citeabstract) that will return the string Interesting article, which claims that time is relative. (the same for DOI, etc.)

I've found the \printfield command that might help me, but I'm not smart enough to know how to use it.

I don't know if it has any influence on the answer, but I'm using BibLaTeX+BibTeX.

Best Answer

You have at least two options to achieve this.

\citefield and friends

We can use \citefield and friends to access any field of any bibliography entry using the

\citefield[<prenote>][<postnote>]{<key>}[<format>]{<field>}

syntax (so \citefield does indeed work like your normal cite command).

One needs to be aware, however, that in biblatex what one would naively call data field comes in three flavours (1) field - a field containing one item such as title, journaltitle or doi, also range field such as pages, (2) list a list of items such as publisher (one book might be published by quite some publishers, apparently), address (the publisher might have an office in New York and one in Berlin), and (3) name lists for author, editor and the like. As these three types need different handling, there are \citefield, \citelist and \citename (see §3.7.7 Low-level Commands, p. 91 of the biblatex documentation). So we need to choose the right \cite*-command for the job, if it is not clear which one to choose, the biblatex documentation lists all the available fields (in the wider sense) in §2.2 Entry Fields starting at page 13 down to page 30.

So you would use \citefield{einstein05}{abstract} and \citefield{einstein05}{doi} to cite the abstract and DOI of your example entry, but \citename{einstein05}{author} (which does essentially the same as \citeauthor here) to display the author's name.

Note that the \cite* commands by default (i.e. if the optional argument <format> is empty) use the generic formats citename, citelist and citelist for their output regardless of the field you intend to print. So you will have to give the format explicitly if it deviates from the plain cite... formats. If you want the DOI formatted in its usual doi format you need to issue \citefield{einstein05}[doi]{doi}. See the discussion in biblatex: clickable doi outside the reference section. This limitation (or feature) goes away if you use the second method described below.

A custom command

If you do need to cite the abstract field quite often, you might want to save you some typing (especially of those pesky curly braces), you could then declare a \citeabstract command like this

\DeclareCiteCommand{\citeabstract}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield{abstract}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

and use it like \citeabstract{einstein05}.

This command will always pick up the appropriate format for the printed field in the appropriate context. Of course this can be explicitly overridden by the optional argument to \printfield.

Related Question