1

For some (stupid) report, I have to put a bibliography with some authors in bold and some authors underlined.

Thanks to some posts/answer here, I succeed to make a specific one bold. However, all other tricks tested here to make other underlined failed (either not compiling or not producing anything).

Here is a MWE for the bold. Let say I would like Billy Bob and Jane Doe underlined.

\documentclass[a4paper,11pt]{article}

\usepackage[T1]{fontenc} \usepackage{hyperref} \usepackage{ulem}

\usepackage[style=alphabetic, maxnames=99, sorting=ydnt, backend=bibtex]{biblatex}

\begin{filecontents}{\jobname.bib} @article{article1, author={Smith, John and Doe, Jane and Foo, Bar}, title={Title}, journal={Journal} } @article{article2, author={Smith, John and Billy, Bob}, title={Title2}, journal={Journal2} } \end{filecontents}

\addbibresource{\jobname.bib}

\DeclareBibliographyDriver{article}{% \printfield{title} % \par \newblock% \printnames{author}% \par% \newblock% {% \footnotesize\itshape% \usebibmacro{journal}% } \par\vspace{0.3\baselineskip} }

\newcommand*{\boldname}[3]{% \def\lastname{#1}% \def\firstname{#2}% \def\firstinit{#3}}

\renewcommand{\mkbibnamegiven}[1]{% \ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} } {\mkbibbold{#1}}{#1}% }

\renewcommand{\mkbibnamefamily}[1]{% \ifboolexpr{ ( test {\ifdefequal{\firstname}{\namepartgiven}} or test {\ifdefequal{\firstinit}{\namepartgiven}} ) and test {\ifdefequal{\lastname}{\namepartfamily}} } {\mkbibbold{#1}}{#1}% }

\boldname{Smith}{John}{}

\begin{document} \nocite{*} \printbibliography[type={article}] \end{document}

Olf
  • 113

1 Answers1

2

You can use the approach from Bold certain authors and dagger other authors, which parametrises my answer to Make specific author bold using biblatex.

This approach requires Biber instead of BibTeX. Note that breakable underlining is very tricky in LaTeX. The best solution for underlining that I'm aware of is Marcel Krüger's lua-ul package (see e.g. Underline part of a word while preserving kerning), which requires LuaLaTeX.

\documentclass{article}
\usepackage{lua-ul}
\usepackage[style=alphabetic, maxnames=99, sorting=ydnt, backend=biber]{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}[2]{% \ifcsundef{nhblx@#1list} {\csdef{nhblx@#1list}{}} {}% \stepcounter{nhblx@name}% \edef\nhblx@tmp@nocite{% \noexpand\AfterPreamble{% \noexpand\setbox0\noexpand\vbox{% \noexpand\def\noexpand\nhblx@listname{nhblx@#1list}% \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{#2}}, % options = {dataonly=true},}% }% }

\AtEndDocument{% \closeout\nhblx@bibfile}

\addbibresource{\nhblx@bibfile@name}

\DeclareNameFormat{nhblx@hashextract}{% \xifinlistcs{\thefield{hash}}{\nhblx@listname} {} {\listcsxadd{\nhblx@listname}{\thefield{hash}}}}

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

\newcommand{\markname}[1]{\forcsvlist{\nhblx@writenametobib{#1}}} \newcommand{\resetmark}[1]{\csdef{nhblx@#1list}{}}

\newcommand*{\ifnamemarked}[1]{% \xifinlistcs{\thefield{hash}}{nhblx@#1list}} \makeatother

\newcommand*{\nameformatter}[1]{% \ifnamemarked{bold} {\mkbibbold{#1}} {\ifnamemarked{underline} {\underLine{#1}} {#1}}}

\DeclareNameWrapperFormat{nameformatter}{% \renewcommand*{\mkbibcompletename}{\nameformatter}% #1}

\DeclareNameWrapperAlias{sortname}{default} \DeclareNameWrapperAlias{default}{nameformatter}

\markname{bold}{John Smith} \markname{underline}{Jane Doe}

\begin{filecontents}{\jobname.bib} @article{article1, author = {Smith, John and Doe, Jane and Foo, Bar}, title = {Title}, journal = {Journal}, } @article{article2, author = {Smith, John and Billy, Bob}, title = {Title2}, journal = {Journal2}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \nocite{*}

\printbibliography \end{document}

References with bold and underlined names.

moewe
  • 175,683
  • Great thanks! Could you explain a bit the first part of the file? To understand more to use it with an external bib file for example. Also, why biber is mandatory here.

    Also, it does not seems compatible with driver I gave in my post (at least with the printnames{authors} :(

    – Olf Mar 24 '23 at 08:12
  • 1
    @Olf Explanations can be found in https://tex.stackexchange.com/a/416416/35864, but if you have more specific questions, ask away. Biber is required because only Biber can reliably calculate name hashes. BibTeX can't do that properly. The code can be used in combination with your driver (see https://gist.github.com/moewew/997e22007917c60f5e34a4c778f8b20c). I chose not to include the driver redefinition in my answer because it is very non-standard and does some non-idiomatic (and possibly problematic) things. – moewe Mar 24 '23 at 19:54