1

My name is Sponge Bob Squarepants. I want to find my name from the list of bibliographic entries and mark it in bold.

Minimum working example:

\documentclass{article}
\usepackage[style=numeric,citecounter=true,citetracker=true]{biblatex} 
\usepackage{filecontents}
\begin{filecontents*}{myreferences.bib}
    @article{sponge1,
        author = {Sponge Bob Squrepants},
        year = {2000},
        title = {No Title},
    }
@article{sponge2,
author = {Sponge Bob Squrepants and 
    Patrick Star},
year = {2001},
title = {No Title Again},
}

\end{filecontents*} \addbibresource{myreferences.bib}

\begin{document} \cite{sponge1}

\cite{sponge2}

\printbibliography \end{document}

So, my names in both the cases (see the image) should be in bold.

For compatibility with other type of styles, it would be appreciated if the I can detect initial (i.e., S. B. Squarepants).

My attempt: I could find \citename{sponge2}{author} to extract the author names. But I could not find how to search for the string.

Update: Found this solution due to user moewe.

%https://tex.stackexchange.com/a/334333/38244
\def\makenamesetup{%
    \def\bibnamedelima{~}%
    \def\bibnamedelimb{ }%
    \def\bibnamedelimc{ }%
    \def\bibnamedelimd{ }%
    \def\bibnamedelimi{ }%
    \def\bibinitperiod{.}%
    \def\bibinitdelim{~}%
    \def\bibinithyphendelim{.-}}    
\newcommand*{\makename}[2]{\begingroup\makenamesetup\xdef#1{#2}\endgroup}

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

% Patch new definitions \renewcommand{\mkbibnamegiven}[1]{% \makename{\currname}{#1}% \makename{\findname}{\firstname}% \makename{\findinit}{\firstinit}% \ifboolexpr{ test {\ifdefequal{\currname}{\findname}}% or test {\ifdefequal{\currname}{\findinit}} }% {\mkbibbold{#1}}{#1}% }

\renewcommand{\mkbibnamefamily}[1]{% \makename{\currname}{#1}% \makename{\findname}{\lastname}% \ifboolexpr{ test {\ifdefequal{\currname}{\findname}} }% {\mkbibbold{#1}}{#1}% } \boldname{Squarepants}{Bob}{Sponge}

Now I want basically the same thing, but with underline. I tried looking for the underline equivalent of \mkbibbold, but no luck yet.

hola
  • 4,026
  • 3
  • 35
  • 72
  • 3
    There are many different approaches at https://tex.stackexchange.com/q/73136/35864. Have a look at them and choose the one that works best for you. – moewe Nov 10 '20 at 06:12
  • Thanks, https://tex.stackexchange.com/a/334333/38244 works for me. I have edited the question for underline. – hola Nov 10 '20 at 08:42

1 Answers1

2

The code you are currently using has the big disadvantage that it will mark all people with your given name in bold even if they aren't you.

If you use the code suggested in my answer to Make specific author bold using biblatex you can just replace \mkbibbold with \underline to get underlining.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[backend=biber,style=numeric]{biblatex}

\addbibresource{biblatex-examples.bib}

\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} {\underline{#1}} {#1}} \makeatother

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

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

\addboldnames{{Sigfridsson, Emma},{Vizedom, Monika B.}}

\begin{document} \fullcite{sigfridsson}

\fullcite{knuth:ct:a}

\fullcite{vizedom:related}

\resetboldnames\addboldnames{Donald E. Knuth} \fullcite{knuth:ct:a}

\resetboldnames\addboldnames{Philipp Jaff{'e}} \fullcite{jaffe} \end{document}

Underlined names in bibliography entries.

Note that underlining is tricky in LaTeX and that \underline does not break across lines. soul's and ulem's underlining macros (which have some support for line breaking), however, cannot be used in this context, because they break with complex arguments.

moewe
  • 175,683