8

I am new here, so please bear with me. I would like to make the last name of the first author only in the bibliography boldface, i.e., in the MWE I want "Fox" in the bibliography only (not the citation) to be bold.

MWE:

\documentclass[a4paper,twoside,hidelinks]{article}
\usepackage[backend=biber,
        natbib=true,
        uniquename=false,
        uniquelist=false,
        firstinits=true,
        style=authoryear,
        sorting=nyt,
        maxcitenames=2,
        minbibnames=1,
        maxbibnames=100,
        block=none]{biblatex}

\bibliography{sample.bib}
\begin{document}
   Here is some sample text \parencite{Fox2011}.
\printbibliography
\end{document}

\RequirePackage{filecontents}
\begin{filecontents}{sample.bib}
   @ARTICLE{Fox2011,
   author = {Peter Fox and Richard Rabbit and Franc Bird},
      title = {Animals are the better humans},
      journal = {Horse and Hound},
      year = {2011},
      volume = {10},
      pages = {11--15}
}
\end{filecontents}
lockstep
  • 250,273
ashaels
  • 93

2 Answers2

8

We redefine one bibmacro. The changes are actually very small: the insertion of a sprinking of \mkbibbold.

\renewbibmacro*{name:last-first}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \usebibmacro{name:hook}{#3#1}%
     \ifblank{#3}{}{%
       \ifcapital
         {\mkbibbold{\mkbibnameprefix{\MakeCapital{#3}}\isdot}}
         {\mkbibbold{\mkbibnameprefix{#3}\isdot}}%
       \ifpunctmark{'}{}{\bibnamedelimc}}%
     \mkbibbold{\mkbibnamelast{#1}\isdot}%
     \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}%
     \ifblank{#2}{}{\revsdnamepunct\bibnamedelimd\mkbibnamefirst{#2}\isdot}}
    {\usebibmacro{name:delim}{#1}%
     \usebibmacro{name:hook}{#1}%
     \mkbibbold{\mkbibnamelast{#1}\isdot}%
     \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}%
     \ifblank{#2#3}{}{\revsdnamepunct}%
     \ifblank{#2}{}{\bibnamedelimd\mkbibnamefirst{#2}\isdot}%
     \ifblank{#3}{}{\bibnamedelimd\mkbibnameprefix{#3}\isdot}}}

enter image description here

Paul Stanley
  • 18,151
  • I'm getting an error message (using Texmaker pdflatex): ! Undefined control sequence. \revsdnamepunct \end{document} The control sequence at the end of the top line of your error message was never \def'ed.

    Tried deleting old compilation files, no change.

    – ashaels Mar 23 '14 at 11:09
  • That's very peculiar. What is the undeffed cs? \revsdnampunct is a standard biblatex feature; and this compiles fine for me inserted into the preamble of your example: it's not even part of the macro that I changed! – Paul Stanley Mar 23 '14 at 11:17
  • @ashaels Do you happen to run an outdated version of biblatex (the newest is 2.8a)? – moewe Mar 23 '14 at 14:40
  • +1 That is actually quite a smart redefinition. It will print all last names in "last, first" format bold, though. So if we switch to \DeclareNameAlias{sortname}{last-first}, all last names wil be bolded. – moewe Mar 23 '14 at 16:27
  • @moewe Yes. In such a case one would have to write a new macro (defined as here) and also new name format, exactly like the standard last-first/first-last, or whatever it's called, except with the new macro called in place of name:last-first. – Paul Stanley Mar 23 '14 at 17:24
  • @PaulStanley Yep, something along those lines. My solution changes \mkbibnamelast, though, it seems to take up less code. – moewe Mar 23 '14 at 17:31
  • Ok, the fault was with the way Texmaker was set up. It now works. Thanks! – ashaels Mar 23 '14 at 18:30
8

I think this is best done with a dedicated name format.

The idea is to redefine the macro \mkbibnamefamily that prints the family name only for the first name, and then restore it.

By default authoryear uses family-given/given-family, so we define family-given/given-family-bf.

\DeclareNameFormat{family-given/given-family}{%
  \ifnumequal{\value{listcount}}{1}
    {\renewcommand*{\mkbibnamefamily}[1]{\mkbibbold{##1}}%
     \ifgiveninits
       {\usebibmacro{name:family-given}
         {\namepartfamily}
         {\namepartgiveni}
         {\namepartprefix}
         {\namepartsuffix}}
       {\usebibmacro{name:family-given}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}}%
     \ifboolexpe{%
       test {\ifdefvoid\namepartgiven}
       and
       test {\ifdefvoid\namepartprefix}}
       {}
       {\usebibmacro{name:revsdelim}}}
    {\renewcommand*{\mkbibnamefamily}[1]{##1}%
     \ifgiveninits
       {\usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiveni}
         {\namepartprefix}
         {\namepartsuffix}}
       {\usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}}}%
  \usebibmacro{name:andothers}}

If you prefer all names in family-given

\DeclareNameFormat{family-given-fb}{%
  \ifnumequal{\value{listcount}}{1}
    {\renewcommand*{\mkbibnamefamily}[1]{\mkbibbold{##1}}}
    {\renewcommand*{\mkbibnamefamily}[1]{##1}}%
  \ifgiveninits
    {\usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {\usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}}%
  \usebibmacro{name:andothers}}

Or given-family

\DeclareNameFormat{given-family-fb}{%
  \ifnumequal{\value{listcount}}{1}
    {\renewcommand*{\mkbibnamefamily}[1]{\mkbibbold{##1}}}
    {\renewcommand*{\mkbibnamefamily}[1]{##1}}%
  \ifgiveninits
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {\usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}}%
  \usebibmacro{name:andothers}}

Then use one of the formats above via \DeclareNameAlias{sortname}{format}, for example

\DeclareNameAlias{sortname}{family-given-fb}

MWE

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

\DeclareNameAlias{sortname}{family-given-fb}
\DeclareNameFormat{family-given-fb}{%
  \ifnumequal{\value{listcount}}{1}
    {\renewcommand*{\mkbibnamefamily}[1]{\mkbibbold{##1}}}
    {\renewcommand*{\mkbibnamefamily}[1]{##1}}%
  \ifgiveninits
    {\usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiveni}
      {\namepartprefix}
      {\namepartsuffix}}
    {\usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}}%
  \usebibmacro{name:andothers}}

\bibliography{biblatex-examples.bib}

\begin{document}
   Here is some sample text \parencite{baez/article}.

  \printbibliography
\end{document}

enter image description here

Edited for biblatex >= 3.3, the old version can be found in the edit history. Incidentally, it should not be necessary to restore the old definition of \mkbibnamefamily in future versions (i.e. > 3.11) since the names should be grouped https://github.com/plk/biblatex/pull/731.

moewe
  • 175,683