2

Say I use a bibliography file in my document, relying on Biblatex and Biber for citation management.

Given a citation command such as \cite{A, B, C} (or any other standard Biblatex citation command), I'd like the resulting citations to be typeset differently depending on whether a given field (e.g. the author field) in the corresponding bibliography entry contains a given string (e.g. someone's lastname).

Besides, I'd like to generate two different bibliography sections in the resulting document, depending on the same condition as above.

Typically this would be used to differentiate, both at the citation level in the main text and in the appendix, the publications that I co-authored from others.

EDIT: adding a MWE:

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber,style = alphabetic]{biblatex}
\usepackage[colorlinks=true, breaklinks, allcolors = blue]{hyperref}
\DeclareSourcemap{%
  \maps[datatype=bibtex]{%
    \map{%
      \step[fieldsource=author, match=Doe, final]%
      \step[fieldset=keywords, fieldvalue=doe]%
    }%
  }%
}
\begin{filecontents}{\jobname.bib}
@Book{p1,
  author =       "A. U. Thor and John Doe",
  title =        "A Scientific Article 1",
  year =         "1975"  
}
@Book{p2,
  author =       "John Doe",
  title =        "A Scientific Article 2",
  year =         "1985"  
}
@Book{p3,
  author =       "Joe Bar",
  title =        "A Scientific Article 3",
  year =         "1995"  
}
@Book{p4,
  author =       "Jane Baz",
  title =        "A Scientific Article 4",
  year =         "2005"  
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
% Requirement 1: should make citations of Doe bold
In \parencite{p4, p1, p2, p3}, ``TD75'' and ``Doe85'' should appear in
bold (the semicolon should remain plain).

% Requirement 2: separating bibliographies. IT WORKS.
\section{Co-authored Publications}
\nocite{*}
\printbibliography[keyword=doe,heading=none]

\section{Other Publications}
\nocite{*}
\printbibliography[notkeyword=doe,heading=none] 
\end{document}
3
  • How differently would you like them to be typeset? And would you also be OK using the keyword field instead of auto-detection of names? Anyway, biblatex: filter out publications from a specific author in the references dynamically seems to be a pretty good fit (there you can even get automatic name recognition).
    – moewe
    Jan 7, 2016 at 17:46
  • @moewe Say in bold or emphasized, perhaps with a different color. Thanks for the link, I had overlooked this one but it indeed works. So a good half of my requirements are met :-) Jan 8, 2016 at 8:08
  • OK. The change required for that will heavily depend on the style you use. (It is probably necessary to change the cite bibmacro, though with some styles there might be other solutions.) So in order to be of any help we would need to see which one you use, this is best done in an MWE.
    – moewe
    Jan 8, 2016 at 8:53

1 Answer 1

3

With the solution from biblatex: separating publications of a specific author in the bibliography that sets the keywords you only need

\DeclareFieldFormat{prefixnumber}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}
\DeclareFieldFormat{labelalpha}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}
\DeclareFieldFormat{extraalpha}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}

to get what you want.

MWE

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber,style = alphabetic]{biblatex}
\usepackage[colorlinks=true, breaklinks, allcolors = blue]{hyperref}
\DeclareSourcemap{%
  \maps[datatype=bibtex]{%
    \map{%
      \step[fieldsource=author, match=Doe, final]%
      \step[fieldset=keywords, fieldvalue=doe]%
    }%
  }%
}
\begin{filecontents}{\jobname.bib}
@Book{p1,
  author =       "A. U. Thor and John Doe",
  title =        "A Scientific Article 1",
  year =         "1975"  
}
@Book{p2,
  author =       "John Doe",
  title =        "A Scientific Article 2",
  year =         "1985"  
}
@Book{p3,
  author =       "Joe Bar",
  title =        "A Scientific Article 3",
  year =         "1995"  
}
@Book{p4,
  author =       "Jane Baz",
  title =        "A Scientific Article 4",
  year =         "2005"  
}
\end{filecontents}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{prefixnumber}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}
\DeclareFieldFormat{labelalpha}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}
\DeclareFieldFormat{extraalpha}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}

\nocite{*}
\begin{document}
In \parencite{p4, p1, p2, p3}, ``TD75'' and ``Doe85'' should appear in
bold (the semicolon should remain plain).

\section{Co-authored Publications}
\printbibliography[keyword=doe,heading=none]

\section{Other Publications}
\printbibliography[notkeyword=doe,heading=none] 
\end{document}

Just because it is fancy to use name hashes, here is a version of Audrey's answer to biblatex: filter out publications from a specific author in the references dynamically.

You can find the name hash you need to use in the .bbl file (as described in more detail in Highlight an author in bibliography using biblatex allowing bibliography style to format it).

This solution uses categories instead of keywords so we have to adjust the code a bit, but the basic idea is the same.

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber,style = alphabetic]{biblatex}
\usepackage[colorlinks=true, breaklinks, allcolors = blue]{hyperref}
\begin{filecontents}{\jobname.bib}
@Book{p1,
  author =       "A. U. Thor and John Doe",
  title =        "A Scientific Article 1",
  year =         "1975"  
}
@Book{p2,
  author =       "John Doe",
  title =        "A Scientific Article 2",
  year =         "1985"  
}
@Book{p3,
  author =       "Joe Bar",
  title =        "A Scientific Article 3",
  year =         "1995"  
}
@Book{p4,
  author =       "Jane Baz",
  title =        "A Scientific Article 4",
  year =         "2005"  
}
\end{filecontents}
\addbibresource{\jobname.bib}

\DeclareBibliographyCategory{byname}

\DeclareIndexNameFormat{byname}{%
  \iffieldequalstr{hash}{bd051a2f7a5f377e3a62581b0e0f8577}
    {\addtocategory{byname}{\thefield{entrykey}}}
    {}%
}

\AtDataInput{%
  \indexnames[byname]{author}}


\DeclareFieldFormat{prefixnumber}{\ifcategory{byname}{\mkbibbold{#1}}{#1}}
\DeclareFieldFormat{labelalpha}{\ifcategory{byname}{\mkbibbold{#1}}{#1}}
\DeclareFieldFormat{extraalpha}{\ifcategory{byname}{\mkbibbold{#1}}{#1}}

\nocite{*}
\begin{document}
In \parencite{p4, p1, p2, p3}, ``TD75'' and ``Doe85'' should appear in
bold (the semicolon should remain plain).

\section{Co-authored Publications}
\printbibliography[category=byname,heading=none]

\section{Other Publications}
\printbibliography[notcategory=byname,heading=none] 
\end{document}

Both MWEs give

example output for both MWEs

5
  • Thank you, but actually, I'd like the bibliography itself to be typeset in normal style. Only citations of Doe's works should be bold. Do you know how to do this? Jan 11, 2016 at 8:47
  • @Grayswandyr You could wrap the \DeclareFieldFormat in \AtEveryCite: \AtEveryCite{% \DeclareFieldFormat{prefixnumber}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}% \DeclareFieldFormat{labelalpha}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}% \DeclareFieldFormat{extraalpha}{\ifkeyword{doe}{\mkbibbold{#1}}{#1}}} (modulo line breaks).
    – moewe
    Jan 11, 2016 at 9:59
  • Citations are indeed bold when citestyle = alphabetic but I can't find a way to achieve the same result with, say, citestyle = authoryear-comp-brackets. Does anyone know a way to do this? Jul 26, 2016 at 9:42
  • @Grayswandyr I don't know the style authoryear-comp-brackets, but the name suggests it is derived from authoryear so a solution would have to be quite different (not necessarily more complicated) than what we used for alphabetic. If you need help for that I suggest you ask a new question (you can link back to this one here if you like). If you decide to ask a new question, make sure to include additionally to the MWE the information where we can find authoryear-comp-brackets as this is not a standard style.
    – moewe
    Jul 26, 2016 at 14:40
  • Thank you. The new question is here. Jul 27, 2016 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .