1

I am trying to change the et~al. that appears in the bibliography in the case that inside the extra (et~al) authors there is an author that I am trying to make bold in the bibliography using the answer of @LawrenceCrosby here

My code is:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{MyBibliography.bib}
  @article{cite1,
    author={Konstantinos Leledakis},
    title={An Article},
    year={2019},
    journal={Some Journal}
  }
  @article{cite2,
    author={Another Author and Konstantinos Leledakis},
    title={A Book},
    year={2017},
    journal={A publisher}
  }
  @book{cite3,
    author={Another SomeAuthor and One AnotherAuthor and SomeOther UnKnownAuthor and Konstantinos Leledakis},
    title={A Book},
    year={1988},
    publisher={Someone}
    }
  @book{cite4,
    author={Another Author and An UnknownAuthor and SomeOther UnKnownAuthor},
    title={A Book},
    year={2015},
    publisher={A publisher}
  }
\end{filecontents}

\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,maxnames=2, minnames=2]{biblatex}
\usepackage{etoolbox}


\DefineBibliographyStrings{english}{andothers={\ifthenelse{\boolean{bold}}{et~al(including Leledakis, K.)}{et~al}\adddot}}


\newboolean{bold}
\newcommand{\makeauthorbold}[1]{%
  \setboolean{bold}{false}
  \DeclareNameFormat{author}{%
    \ifthenelse{\value{listcount}=1}
    {%
      {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\namepartfamily\addcomma\addspace \namepartgiveni}}{\namepartfamily\addcomma\addspace \namepartgiveni}}
      %
    }{\ifnumless{\value{listcount}}{\value{liststop}}
        {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni}}
        {\expandafter\ifstrequal\expandafter{\namepartfamily}{#1}{\setboolean{bold}{true}\mkbibbold{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}{\addcomma\addspace \namepartfamily\addcomma\addspace \namepartgiveni\addcomma\isdot}}%
      }
    \ifthenelse{\value{listcount}<\value{liststop}}
    {\addcomma\space}
  }
}

%\makeauthorbold{Leledakis}


\DefineBibliographyStrings{english}{andothers={et~al}} % To translate "et al."

\ExecuteBibliographyOptions{firstinits=true, uniquename=init}

\addbibresource{MyBibliography.bib}
\renewcommand*{\nameyeardelim}{\addcomma\addspace} % Should add the comma, but somehow doesn't work

\begin{document}
\nocite{*}

\printbibliography
\end{document}

This has two problems:

  1. If I comment in (I mean enable) the commented out command %\makeauthorbold{Leledakis} and enable it. Te result from:

enter image description here

(that contains some et~al).becomes:

enter image description here

Where the name is already highlighted but the et~al. part is missing at all.

PS: I tested the code without my changes too, but it still misses the et. al. part.

koleygr
  • 20,105

1 Answers1

1

The \DeclareNameFormat{author} is a modification of the original name format that leaves a few things to be desired.

  1. It can't deal with "von" parts and "Jr." parts.
  2. It can't deal with "et al.", because it is missing a call to the standard \usebibmacro{name:andothers}.
  3. On a modern biblatex version it will even produce an error due to a syntax error. (The last \ifthenelse is missing a false branch. See also https://github.com/plk/biblatex/issues/874.)

I suggest you use one of the more robust versions to make your name bold suggested in Make specific author bold using biblatex. As far as I can see none of the solution bolds the "et al." if it "contains" the relevant name out of the box, but we can add that.

As basis I'm using my answer that uses hashes, but allows for a convenient interface to retrieve them. The tricky bit is to check whether or not the "et al." also contains a name to be highlighted. We do this by looping over all remaining names in an \indexnames that otherwise prints nothing.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[style=authoryear-comp,
            maxnames=2, minnames=2,
            giveninits=true, uniquename=init]{biblatex}

\makeatletter
% setup for auxiliary bib file
\def\hlblx@bibfile@name{\jobname -boldnames.bib}
\newwrite\hlblx@bibfile
\immediate\openout\hlblx@bibfile=\hlblx@bibfile@name

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

% write names to auxiliary bib file and push hash to bold list
\newcommand*{\hlblx@writenametobib}[1]{%
  \stepcounter{hlblx@name}%
  \edef\hlblx@tmp@nocite{%
    \noexpand\AfterPreamble{%
      \noexpand\setbox0\noexpand\vbox{%
        \noexpand\hlblx@getmethehash{hlblx@name@\the\value{hlblx@name}}}}%
  }%
  \hlblx@tmp@nocite
  \immediate\write\hlblx@bibfile{%
    @misc{hlblx@name@\the\value{hlblx@name}, author = {\unexpanded{#1}}, %
          options = {dataonly=true},}%
  }%
}

\AtEndDocument{%
  \closeout\hlblx@bibfile}

\addbibresource{\hlblx@bibfile@name}

% extract hashes from bib file
\newcommand*{\hlbxl@boldhashes}{}
\DeclareNameFormat{hlblx@hashextract}{%
  \xifinlist{\thefield{hash}}{\hlbxl@boldhashes}
    {}
    {\listxadd{\hlbxl@boldhashes}{\thefield{fullhash}}}}

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

% add and reset list of bold names
\newcommand*{\addboldnames}{\forcsvlist\hlblx@writenametobib}
\newcommand*{\resetboldnames}{\def\hlbxl@boldhashes{}}

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

\newtoggle{boldnameincluded}
\newbibmacro*{name:flagbold}{%
  \def\do##1{\iffieldequalstr{hash}{##1}{\global\toggletrue{boldnameincluded}\listbreak}{}}%
  \dolistloop{\hlbxl@boldhashes}%
}

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

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

\DeclareIndexNameFormat{flagbold}{%
  \usebibmacro{name:flagbold}}

\newcounter{boldflagcount}
\newcommand*{\mkbibboldandothers}[2]{%
  \iftoggle{boldnameincluded}
    {\mkbibbold{#2#1}}
    {#2}}

\renewbibmacro*{name:andothers}{%
  \ifboolexpr{
    test {\ifnumequal{\value{listcount}}{\value{liststop}}}
    and
    test \ifmorenames
  }
    {\ifnumgreater{\value{liststop}}{1}
       {\finalandcomma}
       {}%
     \global\togglefalse{boldnameincluded}%
     \ifnumgreater{\value{listtotal}}{\value{listcount}}
       {\defcounter{boldflagcount}{\value{listcount}+1}%
        \expandafter\def\expandafter\hlblx@currname\expandafter{\currentname}%
        \indexnames[flagbold][\the\value{boldflagcount}-\the\value{listtotal}]{\hlblx@currname}}%
       {}%
     \printdelim{andothersdelim}%
     \bibstring[\mkbibboldandothers{ (incuding K.~Leledakis)}]{andothers}}
    {}}
\makeatother


\addboldnames{Konstantinos Leledakis}


\begin{filecontents}{\jobname.bib}
@article{cite1,
  author  = {Konstantinos Leledakis},
  title   = {An Article},
  year    = {2019},
  journal = {Some Journal},
}
@article{cite2,
  author  = {Another Author and Konstantinos Leledakis},
  title   = {A Book},
  year    = {2017},
  journal = {A publisher},
}
@book{cite3,
  author    = {Another SomeAuthor and One AnotherAuthor
               and SomeOther UnKnownAuthor and Konstantinos Leledakis},
  title     = {A Book},
  year      = {1988},
  publisher = {Someone},
}
@book{cite4,
  author    = {Another Author and An UnknownAuthor
               and SomeOther UnKnownAuthor},
  title     = {A Book},
  year      = {2015},
  publisher = {A publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

Author, A. and **K. Leledakis** (2017). “A Book”. In: A publisher.//Author, A., A. UnknownAuthor, et al. (2015). A Book. A publisher.//**Leledakis, K.** (2019). “An Article”. In: Some Journal.//SomeAuthor, A., O. AnotherAuthor, **et al. (incuding K. Leledakis)** (1988). A Book. Someone.

If you are looking to format a list of publications for your CV, you may want to have a look at biblatex-publist.

edited to use a more elegant version to format complete names. \DeclareNameWrapperFormat and \mkbibcompletename are only available in biblatex v3.12 (2018-10-30) and v3.13 (2019-08-17), respectively. Please refer to the edit history if you are using an older version of biblatex.

moewe
  • 175,683
  • Thank you very much @moewe... I had already fixed the issue of the linked answer (That could not print "et al") and felt that I could do it to use the addition I was looking for (exactly your output! -that for a moment thought is not clear in my question-) but possibly I was still away from that. I am going to post an answer in that question when finish in order at least to print the missing for now "at al." part. Thank you for the suggested package too. I will have a look. – koleygr Mar 19 '19 at 13:54