0

I'm trying to implement the example of this answer poster by Audrey as follows:

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{xpatch}% or use http://tex.stackexchange.com/a/40705

\usepackage[style=authoryear, sorting=ynt, backend=biber, maxbibnames=99]{biblatex} \begin{filecontents}{\jobname.bib} @MISC{test1, AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3}, } @MISC{test2, AUTHOR = {Last2, First2 and Last3, First3 and Last1, First1}, } \end{filecontents}

\addbibresource{\jobname.bib} %\addbibresource{publications.bib}

\setlength\bibitemsep{1.5\itemsep}

\newbibmacro{name:bold}[2]{% \edef\blx@tmp@name{\expandonce#1, \expandonce#2}% \def\do##1{\ifdefstring{\blx@tmp@name}{##1}{\bfseries\listbreak}{}}% \dolistloop{\boldnames}} \newcommand{\boldnames}{} \makeatother

\xpretobibmacro{name:family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{} \xpretobibmacro{name:given-family}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{} \xpretobibmacro{name:family-given}{\begingroup\usebibmacro{name:bold}{#1}{#2}}{}{} \xpretobibmacro{name:delim}{\begingroup\normalfont}{}{}

\xapptobibmacro{name:family}{\endgroup}{}{} \xapptobibmacro{name:given-family}{\endgroup}{}{} \xapptobibmacro{name:family-given}{\endgroup}{}{} \xapptobibmacro{name:delim}{\endgroup}{}{}

% just for demonstration \ExecuteBibliographyOptions{maxnames=99,giveninits} \DeclareNameAlias{default}{family-given/given-family}

\begin{document} \nocite{*}

\renewcommand*{\boldnames}{} \forcsvlist{\listadd\boldnames} {{Last2, First2} } \printbibliography[heading=none] \end{document}

However the name of the author does not appear in bold in the pdf output.

What am I doing wrong?

EDIT

I tried the answer given by @moewe but get the following error message

LaTeX Warning: File `try9.bib' already exists on the system.
               Not generating it from this source.

(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/british.lbx (/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/english.lbx))

Package biblatex Warning: Conflicting options. (biblatex) '<namepart>inits' conflicts with 'uniquename=full'. (biblatex) Setting 'uniquename=init' on input line 81.

(./try9.aux) No file try9.bbl.

LaTeX Warning: Citation 'nhblx@name@1' on page 1 undefined on input line 84.

LaTeX Warning: Empty bibliography on input line 85.

(./try9.aux)

LaTeX Warning: There were undefined references.

Package biblatex Warning: Please (re)run Biber on the file: (biblatex) try9 (biblatex) and rerun LaTeX afterwards.

) No pages of output. Transcript written on try9.log.

EDIT 2

I edited the line as follows:

\usepackage[style=authoryear, sorting=ynt, backend=biber, maxbibnames=99, uniquename=init]{biblatex}

ran biber try9 and then pdflatex try9 (where try9.tex is the name of the file) but got the following error message

LaTeX Warning: File `try9.bib' already exists on the system.
               Not generating it from this source.

(/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/british.lbx (/usr/local/texlive/2019/texmf-dist/tex/latex/biblatex/lbx/english.lbx)) (./try9.aux) (./try9.bbl)

! LaTeX Error: Command \mkbibcompletename undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.84 \addboldnames{{Last2, First2}}

?

! LaTeX Error: Command \mkbibcompletename undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.85 \printbibliography[heading=none]

?

! LaTeX Error: Command \mkbibcompletename undefined.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.85 \printbibliography[heading=none]

? [1{/usr/local/texlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./try9.aux) ){/usr/local/texlive/2019/texmf-dist/fonts/enc/dvips/cm-super/cm-s uper-t1.enc}</usr/local/texlive/2019/texmf-dist/fonts/type1/public/cm-super/sfr m1000.pfb> Output written on try9.pdf (1 page, 12913 bytes). Transcript written on try9.log.

ecjb
  • 883

1 Answers1

1

There are two issues here.

  1. The code is missing \makeatletter before the definition of name:bold. It should be

    \makeatletter
    \newbibmacro*{name:bold}[2]{%
      \edef\blx@tmp@name{\expandonce#1, \expandonce#2}%
      \def\do##1{\ifdefstring{\blx@tmp@name}{##1}{\bfseries\listbreak}{}}%
      \dolistloop{\boldnames}}
    \newcommand*{\boldnames}{}
    \makeatother
    
  2. This method of comparing names is string-based. That means that you must give the name you want to highlight in the same format as in the output. Since the code forces given name initials with giveninits, you also need to use the initials form. Note that . is replaced by \bibinitperiod. You need to take that into account when you fill \boldnames.

    \forcsvlist{\listadd\boldnames}{{Last2, F\bibinitperiod}}
    

It will come as no surprise that I'll take this opportunity to plug my answer to Make specific author bold using biblatex. That answer uses a hash-based approach to compare names, which is generally much more reliable and stable than the string-based approach. The code is a bit longer, because we need a way to have Biber generate the hashes for us.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, sorting=ynt, backend=biber, maxbibnames=99]{biblatex}

\makeatletter \def\nhblx@bibfile@name{\jobname -nhblx.bib} \newwrite\nhblx@bibfile \immediate\openout\nhblx@bibfile=\nhblx@bibfile@name

\immediate\write\nhblx@bibfile{% @comment{Auto-generated file}\blx@nl}

\newcounter{nhblx@name} \setcounter{nhblx@name}{0}

\newcommand*{\nhblx@writenametobib}[1]{% \stepcounter{nhblx@name}% \edef\nhblx@tmp@nocite{% \noexpand\AfterPreamble{% \noexpand\setbox0\noexpand\vbox{% \noexpand\nhblx@getmethehash{nhblx@name@\the\value{nhblx@name}}}}% }% \nhblx@tmp@nocite \immediate\write\nhblx@bibfile{% @misc{nhblx@name@\the\value{nhblx@name}, author = {\unexpanded{#1}}, % options = {dataonly=true},}% }% }

\AtEndDocument{% \closeout\nhblx@bibfile}

\addbibresource{\nhblx@bibfile@name}

\newcommand*{\nhblx@boldhashes}{} \DeclareNameFormat{nhblx@hashextract}{% \xifinlist{\thefield{hash}}{\nhblx@boldhashes} {} {\listxadd{\nhblx@boldhashes}{\thefield{hash}}}}

\DeclareCiteCommand{\nhblx@getmethehash} {} {\printnames[nhblx@hashextract][1-999]{author}} {} {}

\newcommand{\addboldnames}{\forcsvlist\nhblx@writenametobib} \newcommand{\resetboldnames}{\def\nhblx@boldhashes{}}

\newcommand*{\mkboldifhashinlist}[1]{% \xifinlist{\thefield{hash}}{\nhblx@boldhashes} {\mkbibbold{#1}} {#1}} \makeatother

\DeclareNameWrapperFormat{boldifhashinlist}{% \renewcommand*{\mkbibcompletename}{\mkboldifhashinlist}% #1}

\DeclareNameWrapperAlias{sortname}{default} \DeclareNameWrapperAlias{default}{boldifhashinlist}

% just for demonstration \ExecuteBibliographyOptions{maxnames=99,giveninits} \DeclareNameAlias{default}{family-given/given-family} \setlength\bibitemsep{1.5\itemsep}

\begin{filecontents}{\jobname.bib} @MISC{test1, AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3}, } @MISC{test2, AUTHOR = {Last2, First2 and Last3, First3 and Last1, First1}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \nocite{*}

\addboldnames{{Last2, First2}} \printbibliography[heading=none] \end{document}

"Last1, F., F. Last2 and F. Last3 (n.d.).//Last2, F., F. Last3 and F. Last1 (n.d.)." with "F. Last2" in the first and "Last2, F." in the second entry highlighted in bold.

moewe
  • 175,683
  • many thanks for your answer @moewe. I tried your code but there is still an error that I dono't understand – ecjb Jun 26 '21 at 14:53
  • @ecjb The conflicting options warning is unrelated, but can be avoided by also executing teh option uniquename=init, (as suggested in the warning message). The other warning just asks you to rerun Biber. Did you do that? The MWE posted at the end of my answer produces the shown output once you've run pdfLaTeX, Biber, pdfLaTeX, pdfLaTeX in that order. – moewe Jun 26 '21 at 15:29
  • many thanks again for your comment @moewe. I tried again but ran again into an error. I edited the question accordingly – ecjb Jun 26 '21 at 16:29
  • @ecjb Your TeX live is outdated (and doesn't define \mkbibcompletename yet, the command was added in v3.13 from 2019-08-17). Any chance you might install a modern TeX live 2021? – moewe Jun 26 '21 at 16:29
  • many thanks @moewe! – ecjb Jun 26 '21 at 16:53