3

Following scenario (many questions about it on the site): I have a bibliography that contains items I cite and some items I do not cite. As I wish to keep the sort order in my bibliography I do not want to have to different sections as answered before: How to split bibliography into "works cited" and "works not cited"? (MWE sort of copied from there)

What I'm trying to achieve is the following: I want \printbibliography to print the whole entry text and key in grey if the item is not cited within the document. That means if the entry is not in category cited the items shall print differently.

Note: I use a more complex setup for the bibliography in my main document, so changing every single field to print different for different categories should be avoided.

\documentclass{article}

\begin{filecontents*}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents*}

\usepackage{biblatex}

\DeclareBibliographyCategory{cited}
\AtEveryCitekey{\addtocategory{cited}{\thefield{entrykey}}}
\addbibresource{\jobname.bib}
\nocite{*}

\begin{document}
Some text \autocite{A01,B02}.
\printbibliography
\end{document}
TeXnician
  • 33,589

1 Answers1

4

I think a combination of ifcategory, DeclareFieldFormat, and AtEveryBibitem will do it for you.

Try this:

\documentclass{article}

\begin{filecontents*}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents*}

\usepackage{xcolor}
\usepackage{biblatex}

\pagestyle{empty}
\DeclareBibliographyCategory{cited}
\AtEveryCitekey{\addtocategory{cited}{\thefield{entrykey}}}
\AtEveryBibitem{%
  \ifcategory{cited}{}{\color{black!50}}}
\DeclareFieldFormat{labelnumberwidth}{%
  \ifcategory{cited}{}{\color{black!50}}\mkbibbrackets{#1}}
\addbibresource{\jobname.bib}
\nocite{*}

\begin{document}
Some text \autocite{A01,B02}.
\printbibliography
\end{document}

enter image description here

David Purton
  • 25,884