1

I am trying to list the references of two different people with the same last name:

\newcommand*{\generateauthorcategory}[3]{%
 \DeclareBibliographyCategory{by#1}%
 \DeclareIndexNameFormat{cat#1}{%
    \ifboolexpr{test {\ifdefstring{\namepartfamily}{#2}}
                and test {\ifdefstring{\namepartgiven}{#3}}}
      {\addtocategory{by#1}{\thefield{entrykey}}}
      {}}%
  \AtDataInput{\indexnames[cat#1][1-999]{author}}}


\generateauthorcategory{foo}{Foo}{Andrew}
\generateauthorcategory{foo}{Foo}{Fernand}

\begin{document}
\printbibliography[heading=none, category=byfoo, check=yr2018,]
\printbibliography[heading=none, category=byfoo, check=yr2017,]
\printbibliography[heading=none, category=byfoo, check=yr2016,]

\printbibliography[heading=none, category=byfoo, check=yr2018,]
\printbibliography[heading=none, category=byfoo, check=yr2017,]
\printbibliography[heading=none, category=byfoo, check=yr2016,]
\nocite{*}
\end{document}

It tells me I already have a foo catergory so i cant have two.

Michael
  • 87
  • 2
    \generateauthorcategory{fooa}{Foo}{Andrew} \generateauthorcategory{foof}{Foo}{Fernand} and then category=byfooa and category=byfoof respectively? The first argument of \generateauthorcategory must be unique and should only contain ASCII chars (I prefer to keep them lowercase) - it is however only used internally and so need not bear relation to the second and third arguments. – moewe Apr 12 '18 at 21:00
  • 1
    I assume the code is from https://tex.stackexchange.com/q/397832/35864 or https://tex.stackexchange.com/q/406061/35864. In the future it would be great if you could give a link to the solution. And please also consider posting a proper MWE and not just code snippets. A full code example that we can run directly makes it much easier to help you: We can get started more quickly and we can be sure that we are actually talking about the same thing. – moewe Apr 12 '18 at 21:03

1 Answers1

3

The first argument <catname> of \generateauthorcategory as defined in Add arguments to \declaresourcemap is an 'internal' name that is used to identify the bibliography category by<catname>. That name must be unique across all \generateauthorcategorys so there are no clashes between categories for different people (in your example which Foo do you expect to see with category=byfoo Andrew or Fernand?). Since <catname> is used for internal purposes it should only contain ASCII chars and I prefer to keep the characters lowercase as well. The <catname> identifier need not bear a relation to the other two arguments, but of course it helps if it does.

You will need to choose two different names here, for example fooa and foof,

\generateauthorcategory{fooa}{Foo}{Andrew}
\generateauthorcategory{foof}{Foo}{Fernand}

and then

\printbibliography[heading=none, category=byfooa]
\printbibliography[heading=none, category=byfoof]
moewe
  • 175,683