The citations are contained in the .aux
file.
\usepackage{atveryend}
\makeatletter
\let\origcitation\citation
\AtEndDocument{\def\mycites{\@gobble}%
\def\citation#1{\g@addto@macro\mycites{,#1}\origcitation{#1}}}
\AtVeryEndDocument{\typeout{***^^JCited keys: \mycites^^J***}}
\makeatother
This will show on screen and in the .log file, at the end of the LaTeX run, a message such as
***
Cited keys: xxx,yyy,*
***
It would be possible to avoid the appearance of *
, but I don't think it's worthy the trouble. Only actually cited keys will appear (BibTeX uses \citation{*}
as a signal for including the whole database).
One can output the citations to an auxiliary file, instead:
\makeatletter
\let\origcitation\citation
\AtEndDocument{\def\mycites{}%
\def\citation#1{\g@addto@macro\mycites{#1^^J}\origcitation{#1}}}
\AtVeryEndDocument{\newwrite\citeout\immediate\openout\citeout=\jobname.cit
\immediate\write\citeout{\mycites}\immediate\closeout\citeout}
\makeatother
Then, if the file is test.tex
, the citation keys will be saved in the file test.cit
one per line.
I have some .bib
files, some of them have 1000 lines.
To be sure that they are working well I always use this test MWE (package filecontents
and sample .bib
file added only for a running MWE; delete it and use your own .bib
file please):
\RequirePackage{filecontents} % loading package filecontents
% writing file \jobname.bib, for example mb-bibtex.bib.
\begin{filecontents*}{\jobname.bib}
@Book{adams,
author = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
title = {The LaTeX Companion},
edition = {1},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
@Book{adams,
title = {The Restaurant at the End of the Universe},
author = {Douglas Adams},
series = {The Hitchhiker's Guide to the Galaxy},
publisher = {Pan Macmillan},
year = {1980}
}
@Article{Mathetitle,
author = {Mezzacapo, F. and Cirac, J. I.},
title = {Ground-state properties of the spin-$\frac{1}{2}$ antiferromagnetic Heisenberg
model on the triangular lattice: a variational study based on
entangled-plaquette states.},
year = {2010},
journal = {New. J. Phys.},
number = {12},
issn = {103039},
}
\end{filecontents*}
\documentclass{article}
\usepackage[numbers]{natbib} % bibliography style
\usepackage[colorlinks]{hyperref} % better urls in bibliography
\begin{document}
Test the complete \texttt{.bib} file: \nocite{*}.
\bibliographystyle{plainnat} % needs package natbib
\bibliography{\jobname} % uses \jobname.bib, according to \jobname.tex
\end{document}
The sample file includes two errors: key adams
you will find twice (that gives an error) and in the Mathetitle
there is an field missing (that gives a warning).
The MWE is build to test a .bib
file with BibTeX. You have to choose your used bib style (my example uses package natbib
with numbers
). So this MWE shows you the resulting errors and warnings for the given .bib
with BibTeX and perhaps resulting tex
errors.
That is my way to be sure there is no bib
error or tex
error in the .bib
file.
Best Answer
Using
biblatex
, you may add theshorthand
field: