14

How do I print any field from a .bib file?

For example how do I print the title from the following entry?

@article{Gerace2019,
Author = {Gerace, Dario and Laussy, Fabrice and Sanvitto, Daniele},
Journal = {Nature Materials},
Number = {3},
Pages = {200--201},
Title = {Quantum nonlinearities at the single-particle level},
Volume = {18},
Year = {2019}
}

I want to do something like:

The title of the paper \cite{Gerace2019} is \printtitle{Gerace2019}
Tom
  • 483

1 Answers1

15

If you are using biblatex the command you are looking for is called \citetitle.

For the most common fields biblatex has dedicated \cite... commands (\citeauthor, \citetitle, \citedate, \cityear, \citeurl) if the field you want to print is not amongst those, then you can use the generic \citefield{<key>}{<field>}. Since biblatex differentiates between fields, lists and name lists, there are \citefield, \citelist and \citename, see also How to extract BibTeX entries (as DOI, abstract, etc.). It is possible to create your own \cite... command for fields that don't have one yet (see also the previous link).

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=numeric, backend=biber]{biblatex}

%\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Gerace2019,
  author  = {Gerace, Dario and Laussy, Fabrice and Sanvitto, Daniele},
  journal = {Nature Materials},
  number  = {3},
  pages   = {200--201},
  title   = {Quantum nonlinearities at the single-particle level},
  volume  = {18},
  year    = {2019},
}
\end{filecontents}

\addbibresource{\jobname.bib}


\begin{document}
The title of the paper \cite{Gerace2019} is \citetitle{Gerace2019}
\printbibliography
\end{document}

The title of the paper [1] is ‘Quantum nonlinearities at the single-particle level’


If you are using a BibTeX-based solution, you can load the usebib package and use its \usebibentry command.

Note that usebib does not parse the field contents like BibTeX or Biber. In particular, name lists and other lists are not split up as usual. That means that while it is possible to display name fields like author with usebib, the output will look exactly as the input in the .bib file.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage{usebib}


%\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Gerace2019,
  author  = {Gerace, Dario and Laussy, Fabrice and Sanvitto, Daniele},
  journal = {Nature Materials},
  number  = {3},
  pages   = {200--201},
  title   = {Quantum nonlinearities at the single-particle level},
  volume  = {18},
  year    = {2019},
}
\end{filecontents}

\bibinput{\jobname} % give the file name of your .bib file here (without extension)
                    % just as in \bibliography

\begin{document}
The title of the paper \cite{Gerace2019} is \usebibentry{Gerace2019}{title}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}

The title of the paper [1] is Quantum nonlinearities at the single-particle level

moewe
  • 175,683
  • Wow that was quick. Thanks! – Tom Mar 10 '19 at 16:51
  • Is there also a way to check if a filed is defined, e.g. if \citefield{key}{note} would return an actual note or a placeholder? – white_gecko Jan 02 '20 at 10:24
  • 1
    @white_gecko I don't think there is a user-level command like \citefield (and I couldn't find one in the documentation just now, but there is lots in there, so I might just have forgotten it and not searched for the right keywords). There is \iffieldundef, but that can only be used inside a \DeclareCiteCommand. What exactly do you have in mind (use case)? I guess this would be a good topic for a new question. – moewe Jan 02 '20 at 10:39
  • Your comment and this helped me already: https://tex.stackexchange.com/a/73801/11820 Don't know if a new question would just be duplicate to this one. – white_gecko Jan 02 '20 at 11:18
  • @white_gecko If you found a solution that works for you (especially if you found it on this site), a new question might not be necessary. – moewe Jan 02 '20 at 12:12