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.
https://tex.stackexchange.com/questions/492631/biblatex-how-to-catch-authors-name-for-categories
tex.stackexchange.com
crawl=CC-MAIN-2019-35
132813
application/http; msgtype=response
sha1:O2O6I6E6AQL3IFCVSUPA4YW4ZUFAFRVX
<urn:uuid:60a2acf4-8f5d-433d-b687-4fdf5223fa01>
2019-08-19T17:21:17Z
151.101.65.69
text/html
sha1:KBVNYHFOBT2C7IQACJG5AXCRB26YBJNK
<urn:uuid:c4ce8ddf-9b3d-4eec-979c-9fd70ffd5adc>
https://tex.stackexchange.com/questions/492631/biblatex-how-to-catch-authors-name-for-categories
response
<urn:uuid:efe8b616-1f9d-48a6-a8b8-a629fc4f7305>
isPartOf: CC-MAIN-2019-35
publisher: Common Crawl
description: Wide crawl of the web for August 2019
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-67-67-85.ec2.internal
software: Apache Nutch 1.15 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.1-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/