0

I've been trying to implement author name categories in BibLaTeX based on this answer while using biber. However, I don't seem to be able to catch the author name using \iffieldequalstr in \AtEveryBibItem:

\DeclareBibliographyCategory{authorSmith}

\AtEveryBibitem{\iffieldequalstr{author}{Smith, John}{\addtocategory{authorSmith}{\thefield{entrykey}}{}}}

When I issue the \printbibliography[category=authorSmith] command, nothing is printed from the bibliography.

Here's a MWE showing the issue and all the name combinations I could think of, and how it doesn't happen when with year:

mwe.tex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[sorting=none]{biblatex}
\addbibresource{mwe.bib}

\DeclareBibliographyCategory{authorSmith}

\AtEveryBibitem{\iffieldequalstr{author}{Smith, John}{\addtocategory{authorSmith}{\thefield{entrykey}}{}}}

\AtEveryBibitem{\iffieldequalstr{author}{Smith,John}{\addtocategory{authorSmith}{\thefield{entrykey}}{}}}

\AtEveryBibitem{\iffieldequalstr{author}{SmithJohn}{\addtocategory{authorSmith}{\thefield{entrykey}}{}}}

\AtEveryBibitem{\iffieldequalstr{author}{JohnSmith}{\addtocategory{authorSmith}{\thefield{entrykey}}{}}}

\AtEveryBibitem{\iffieldequalstr{author}{John Smith}{\addtocategory{authorSmith}{\thefield{entrykey}}{}}}

\DeclareBibliographyCategory{year1984}
\AtEveryBibitem{\iffieldequalstr{year}{1984}{\addtocategory{year1984}{\thefield{entrykey}}{}}}


\begin{document}

\nocite{*}

\printbibliography

\section*{Sorted by Author}

\printbibliography[category=authorSmith]

\section*{Sorted by Year}

\printbibliography[category=year1984]

\end{document}

mwe.bib

@article{smith:TestPaper,
    addendum = {This should show up},
    author = {Smith, John},
    journal = {Test Journal},
    year = {1984},
    title = {Test Paper}
}

ibL

Does anyone know how I can catch the author's name? I have similar issues with source maps.

1

Name fields are special and can not be tested with \iffieldequalstr. In my opinion the best way to test for a certain name is by testing with name hashes, see Highlight an author in bibliography using biblatex allowing bibliography style to format it. There are some subtleties if we do that, though, we can test for the full author list or just for one name in the author list. It is slightly simpler to test for the full list and your usage example looks like that might be intended anyway, so I will present that solution here.

The downside of this approach is that you have to look up the namehash in the .bbl once. Just open the .bbl, search for the relevant entry and copy the namehash value.

\entry{smith:TestPaper}{article}{}
  \name{author}{1}{}{%
    {{uniquename=0,uniquepart=base,hash=5d0ddda3a367ceb26fbaeca02e391c22}{%
       family={Smith},
       familyi={S\bibinitperiod},
       given={John},
       giveni={J\bibinitperiod},
       givenun=0}}%
  }
  \strng{namehash}{5d0ddda3a367ceb26fbaeca02e391c22}

Shows that in my Biber version the hash for Smith, John/John Smith is 5d0ddda3a367ceb26fbaeca02e391c22. So that is what we are going to test against.

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

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

\DeclareBibliographyCategory{authorSmith}

\AtDataInput{%
  \iffieldequalstr{namehash}{5d0ddda3a367ceb26fbaeca02e391c22}
    {\addtocategory{authorSmith}{\thefield{entrykey}}}
    {}}


\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{smith:TestPaper,
  addendum = {This should show up},
  author   = {Smith, John},
  journal  = {Test Journal},
  year     = {1984},
  title    = {Test Paper},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}


\begin{document}
\cite{sigfridsson,smith:TestPaper}

\printbibliography[category=authorSmith, title={Smith's Papers}]

\printbibliography
\end{document}

Two bibliographies: The first is titled "Smith's Papers" and contains only <code>smith:TestPaper</code>. The second is titled "References" and contains both <code>sigfridsson</code> and <code>smith:TestPaper</code>

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.