TeX - LaTeX Asked by jlconlin on April 18, 2021
I am writing my CV in LaTeX. I am using biblatex
and want my name (and only my name) to be bold for every reference. Is there a magic way to do this?
A similar question Make one author's name bold every time it shows up in the bibliography was asked, but that answer used BibTeX. While I use the BibTeX backend, I use biblatex
.
Any suggestions?
You can patch the name:last
, name:first-last
and name:last-first
macros defined in biblatex.def
. These are used by all of the default name formatting directives and take four arguments:
{<last name>}{<first name>}{<name prefix>}{<name affix>}
or
{<last name>}{<first name (initials)>}{<name prefix>}{<name affix>}
In the following we match only on the first and last name parts.
documentclass{article}
usepackage{biblatex}
usepackage{xpatch}% or use http://tex.stackexchange.com/a/40705
makeatletter
newbibmacro*{name:bold}[2]{%
edefblx@tmp@name{expandonce#1, expandonce#2}%
defdo##1{ifdefstring{blx@tmp@name}{##1}{bfserieslistbreak}{}}%
dolistloop{boldnames}}
newcommand*{boldnames}{}
makeatother
xpretobibmacro{name:family}{begingroupusebibmacro{name:bold}{#1}{#2}}{}{}
xpretobibmacro{name:given-family}{begingroupusebibmacro{name:bold}{#1}{#2}}{}{}
xpretobibmacro{name:family-given}{begingroupusebibmacro{name:bold}{#1}{#2}}{}{}
xpretobibmacro{name:delim}{begingroupnormalfont}{}{}
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}
addbibresource{biblatex-examples.bib}
forcsvlist{listaddboldnames}
{{Herrmann, Wolfgang~A.}, {Herrmann, W.~A.}, {Herrmann, Wolfgangbibnamedelima A.},
{Herrmann, Wbibinitperiodbibinitdelim Abibinitperiod}}
setlength{parindent}{0pt}
setlength{parskip}{baselineskip}
begin{document}
fullcite{herrmann}
forcsvlist{listaddboldnames}
{{{"{O}}fele, Karl}, {{"{O}}fele, K.}, {{"{O}}fele, Kbibinitperiod}}
fullcite{herrmann}
renewcommand*{boldnames}{}
forcsvlist{listaddboldnames}
{{Hoffmann, Stephan~D.}, {Hoffmann, S.~D.}, {Hoffmann, Stephanbibnamedelima D.},
{Hoffmann, Sbibinitperiodbibinitdelim Dbibinitperiod}}
fullcite{herrmann}
end{document}
Note that the name parts in the boldnames
etoolbox
internal list should follow the format of the bbl
file, which is backend-dependent. The example here covers both biber and BibTeX. With biber you can also perform matching using the hash
field:
iffieldequalstr{hash}{<hash string>}
where <hash string>
can also be found in the bbl
file.
If your name is consistently formatted in the bib
file an alternative approach is to normalize name punctuation before matching. This example allows you to specify your name in BibTeX's format regardless of the backend.
documentclass{article}
usepackage{biblatex}
usepackage{xpatch}% or use http://tex.stackexchange.com/a/40705
defmakenamesetup{%
defbibnamedelima{~}%
defbibnamedelimb{ }%
defbibnamedelimc{ }%
defbibnamedelimd{ }%
defbibnamedelimi{ }%
defbibinitperiod{.}%
defbibinitdelim{~}%
defbibinithyphendelim{.-}}
newcommand*{makename}[3]{begingroupmakenamesetupxdef#1{#2, #3}endgroup}
newbibmacro*{name:bold}[2]{%
makename{currname}{#1}{#2}%
makename{findname}{lastname}{firstname}%
makename{findinit}{lastname}{firstinit}%
ifboolexpr{ test {ifdefequal{currname}{findname}}
or test {ifdefequal{currname}{findinit}} }{bfseries}{}}
newcommand*{boldname}[3]{%
deflastname{#1}%
deffirstname{#2}%
deffirstinit{#3}}
boldname{}{}{}
xpretobibmacro{name:family}{begingroupusebibmacro{name:bold}{#1}{#2}}{}{}
xpretobibmacro{name:given-family}{begingroupusebibmacro{name:bold}{#1}{#2}}{}{}
xpretobibmacro{name:family-given}{begingroupusebibmacro{name:bold}{#1}{#2}}{}{}
xpretobibmacro{name:delim}{begingroupnormalfont}{}{}
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}
addbibresource{biblatex-examples.bib}
boldname{Herrmann}{Wolfgang~A.}{W.~A.}
setlength{parindent}{0pt}
setlength{parskip}{baselineskip}
begin{document}
fullcite{herrmann}
boldname{{"O}fele}{Karl}{K.}
fullcite{herrmann}
boldname{Hoffmann}{Stephan~D.}{S.~D.}
fullcite{herrmann}
end{document}
This answer was updated to work with versions >= 3.3 of
biblatex
. See the edit history for older versions ofbiblatex
. -- moewe
Correct answer by Audrey on April 18, 2021
Since biblatex
3.4/biber
2.5, there is a general "annotation" functionality to do things like this, for example:
documentclass{article}
usepackage{biblatex}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@MISC{test,
AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3},
AUTHOR+an = {2=highlight},
}
end{filecontents}
addbibresource{jobname.bib}
renewcommand*{mkbibnamegiven}[1]{%
ifitemannotation{highlight}
{textbf{#1}}
{#1}}
renewcommand*{mkbibnamefamily}[1]{%
ifitemannotation{highlight}
{textbf{#1}}
{#1}}
begin{document}
nocite{*}
printbibliography
end{document}
You can also annotate at the name part level and the top-level field level. See the biblatex PDF manual for details.
Answered by PLK on April 18, 2021
As I couldn't use https://tex.stackexchange.com/a/73246/7561 as well, and in case others stumble into this looking for a solution, I'm updating the answers. As pointed by Adam Liter, in the comments of that answer, the options used in the previous answer are deprecated and doesn't work (at least for me).
Instead, I redefined the mkbibnamegiven
and mkbibnamefamily
, and used the same ideas as before.
Basically, you use the boldname
to the define the name you want to mark as bold, like: boldname{Lastname}{Givenname}{G.}
.
newcommand*{boldname}[3]{%
deflastname{#1}%
deffirstname{#2}%
deffirstinit{#3}}
boldname{}{}{}
Then, we redefine the macros that generate the given and family names. The main idea is to search for the named defined above, and if it is found (including the given and family name) it makes it bold (using mkbibbold
), if not it leaves it as is.
% Patch new definitions
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}%
}
A full example:
% !BIB program = biber
documentclass{article}
usepackage[backend=biber,maxbibnames=99,defernumbers=true,sorting=ydnt,giveninits=true]{biblatex}
begin{filecontents}{jobname.bib}
@InProceedings{identifier1,
Title = {Some Awesome Title},
Author = {Some Author and Another Author},
Booktitle = {Some Book about the Future},
Year = {2042},
Pages = {1--42}
}
@InProceedings{identifier2,
Title = {Some So-So Title},
Author = {First Author and Second Author},
Booktitle = {An okay Booktitle},
Year = {2000},
Pages = {1--100}
}
@Book{test1,
author = {Goossens, Michel and Mittelbach, Frank
and Samarin, Alexander},
title = {The LaTeX Companion},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
@Book{test2,
author = {Mittelbach, F. and Goossens, Michel
and Samarin, Alexander},
title = {The LaTeX Companion},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
@Book{test3,
author = {Mittelbach, Frank and Samarin, Alexander
and Goossens, Michel},
title = {The LaTeX Companion},
publisher = {Addison-Wesley},
location = {Reading, Mass.},
year = {1994},
}
end{filecontents}
addbibresource{jobname.bib}
defmakenamesetup{%
defbibnamedelima{~}%
defbibnamedelimb{ }%
defbibnamedelimc{ }%
defbibnamedelimd{ }%
defbibnamedelimi{ }%
defbibinitperiod{.}%
defbibinitdelim{~}%
defbibinithyphendelim{.-}}
newcommand*{makename}[2]{begingroupmakenamesetupxdef#1{#2}endgroup}
newcommand*{boldname}[3]{%
deflastname{#1}%
deffirstname{#2}%
deffirstinit{#3}}
boldname{}{}{}
% Patch new definitions
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{Author}{Some}{S.}
begin{document}
nocite{*}
printbibliography
boldname{Goossens}{Michel}{M.}
printbibliography
boldname{Mittelbach}{Frank}{F.}
printbibliography
end{document}
Added support for checking given and family names before bolding the name.
Answered by adn on April 18, 2021
There is still an issue with the last answer by adn: The sub macros that use the Strings in boldname{Goossens}{Michel}{M.}
only search for these strings (i.e., "Goossens", "Michel", and "M.") independently of each other. That is: any occurrence of "M." will be bold, no matter whether it belongs to a different author (like "M." for "Martin"). Improving the search scripts to only make the respective names bold if they are detected in a sequence would solve this behavior. In its current form, its usefulness is quite limited given there are more than just a couple of references.
Here a MWE that shows the problem:
documentclass{article}
usepackage[backend=biber,maxbibnames=99,defernumbers=true,sorting=ydnt,giveninits=true]{biblatex}
begin{filecontents}{jobname.bib}
@InProceedings{identifier1,
Title = {Some Awesome Title},
Author = {Some Author and Another Author},
Booktitle = {Some Book about the Future},
Year = {2042},
Pages = {1--42}
}
@InProceedings{identifier2,
Title = {Some So-So Title},
Author = {First Author and Second Author},
Booktitle = {An okay Booktitle},
Year = {2000},
Pages = {1--100}
}
end{filecontents}
addbibresource{jobname.bib}
defmakenamesetup{%
defbibnamedelima{~}%
defbibnamedelimb{ }%
defbibnamedelimc{ }%
defbibnamedelimd{ }%
defbibnamedelimi{ }%
defbibinitperiod{.}%
defbibinitdelim{~}%
defbibinithyphendelim{.-}}
newcommand*{makename}[2]{begingroupmakenamesetupxdef#1{#2}endgroup}
newcommand*{boldname}[3]{%
deflastname{#1}%
deffirstname{#2}%
deffirstinit{#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{Author}{Some}{S.}
begin{document}
nocite{*}
printbibliography
end{document}
It produces the following PDF, in which:
(a) all occurrences of "S." are bold, although one stands for "Second", which does not belong to the name "Some Author" and
(b) all occurrences of "Author" are bold (i.e., all four authors!), although just one matches the desired author "Some Author"
I hence propose another solution, which does solve this problem (however, there are other problems with it - and I would be glad if someone would present a solution for it). The solution was mentioned in Make one author's name bold every time it shows up in the bibliography (this link is also given in the very first post here one that page). However, (a) it does work with biblatex
, although jlconlin says that it only works with bibtex
and (b) I have extended it a bit to provide some further functionalities that you would not get without it (but that are provided by the previous answer, given by adn).
That solution simply uses a macro in the bibtex
files instead of the actual authors' names. Then, the textbf{}
macro does work, while the document would not compile if textbf{}
would be inserted directly in the .bib file.
documentclass{article}
usepackage[backend=biber,maxbibnames=99,defernumbers=true,sorting=ydnt,giveninits=true]{biblatex}
usepackage{filecontents}
begin{filecontents}{jobname.bib}
@InProceedings{identifier1,
Title = {Some Awesome Title},
Author = {MyName[someKey]{S. Author} and Another Author},
Booktitle = {Some Book about the Future},
Year = {2042},
Pages = {1--42}
}
@InProceedings{identifier2,
Title = {Some So-So Title},
Author = {First Author and Second Author},
Booktitle = {An okay Booktitle},
Year = {2000},
Pages = {1--100}
}
end{filecontents}
addbibresource{jobname.bib}
begin{document}
newcommand{MyName}[2][empty]{ % empty is default for the opt. argument
ifthenelse{equal{#1}{empty}} % test the opt. argument
{hspace*{-.75mm}#2} % it's empty! just show mand. argument
{hspace*{-.75mm}textbf{#2}} % it's not empty! make mand. argument (the name) bold
}
nocite{*}
printbibliography
end{document}
It produces the following PDF:
As can be seen: the problem is solved, as exactly those authors are shown bold that use the macro. To be more precise: the is now an optional argument, which can be instantiated by any String of the user's choice. This "key" can be used in the definition of MyName
to define more specific behavior. For instance, I use biblatex
to use keywords (given in an extra keywords fields - not given here) in order to give several reference sections, divided by the keywords. If making an author's name bold should depend on that keyword (which is the case for me), that logic can be put into the if-then statement. (In my example, the name in the MyName
macro is shown bold if there is any keyword given and non-bold, otherwise. This can be extended -- obviously -- to match any specific key.
It is important to know that this solution does not support to abbreviate the authors' names given in the macro. You will see that I passed "S. Author" to MyName
instead of "Some Author", because latex/bibtex cannot produce "S. Author" from it. However, this does not make this solution any less practical, I think.
Its problem: All names which are put into the MyName
macro appear more to the right than without using the macro. That is, there is a space of approx. 2mm on the left of any such name. This occurs independently of the matching if case, i.e., no matter whether it is bold or not. This is the reason why I have added a negative hspace
in front of it. However,
(a) this quiet dirty. Isn't there a (la)tex macro that eliminates the additional space? and
(b) it is impossible to find the correct space that needs to be subtracted, because it is different for different bibtex
entries (sometimes this automatically inserted space is larger, sometimes it is smaller)
Answered by Prof.Chaos on April 18, 2021
Combining solution by adn, and suggestion by Audrey to use the "hash" field generated by biber, this works (texlive 2017.20170818-1):
documentclass{article}
usepackage[backend=biber,maxbibnames=99,defernumbers=true,sorting=ydnt,giveninits=true]{biblatex}
addbibresource{biblatex-examples.bib}
% Run biber once, find the hash you want in the generated .bbl file
% (here, M. Goossens) and paste here:
edefauthorhash{detokenize{0743efb276e9219ee664a9b3dbd60619}}
renewcommand{mkbibnamegiven}[1]{%
iffieldequals{hash}{authorhash}{mkbibbold{#1}}{#1}}
renewcommand{mkbibnamefamily}[1]{%
iffieldequals{hash}{authorhash}{mkbibbold{#1}}{#1}}
renewcommand{mkbibnameprefix}[1]{%
iffieldequals{hash}{authorhash}{mkbibbold{#1}}{#1}}
renewcommand{mkbibnamesuffix}[1]{%
iffieldequals{hash}{authorhash}{mkbibbold{#1}}{#1}}
begin{document}
nocite{companion}
printbibliography
end{document}
Edit: Following moewe's good advices, fixes and verifications (thanks !) :
Patching name:
as suggested by Audrey would indeed be more efficient but apparently it does not work anymore for some reason (see comment Make specific author bold using biblatex).
Answered by fmeyna on April 18, 2021
This is more or less a copy of my answer to Highlight an author in bibliography using biblatex allowing bibliography style to format it.
The following implements Audrey's solution for name hashes. The advantage of using hashes is that you only have to give one version of the name, all normalisation will be performed by Biber. The great disadvantage of hashes is that they are not easy to handle for humans. biblatex
can't create the hashes on the fly, so that they need to be looked up in the .bbl
file. The following solution automates hash lookup from the .bbl
, so that you can use it more easily.
The solution works by writing all names you want in bold to a separate .bib
file called (jobname -boldnames.bib
Warning That file will be overwritten without warning. In the unlikely event you already have a file of that name, you can rename the file by changing hlblx@bibfile@name
.). The hash can then be extracted using a dummy cite command.
Usage is very simple. Use addboldnames
to add a list of names to be highlighted. addboldnames
accepts a comma-separated list of names in the same format as you would write them to the .bib
file. If a name contains a comma, the entire name must be wrapped in curly braces.
addboldnames{{Silva, Carlos F. M.},{Silva, Jr., José Mairton B.}}
or
addboldnames{Emma Sigfridsson}
addboldnames
can be used in the preamble and the document body.
To reset the list of names to be highlighted, use resetboldnames
.
documentclass{article}
usepackage[T1]{fontenc}
usepackage[backend=biber,style=numeric]{biblatex}
addbibresource{biblatex-examples.bib}
makeatletter
defnhblx@bibfile@name{jobname -nhblx.bib}
newwritenhblx@bibfile
immediateopenoutnhblx@bibfile=nhblx@bibfile@name
immediatewritenhblx@bibfile{%
@comment{Auto-generated file}blx@nl}
newcounter{nhblx@name}
setcounter{nhblx@name}{0}
newcommand*{nhblx@writenametobib}[1]{%
stepcounter{nhblx@name}%
edefnhblx@tmp@nocite{%
noexpandAfterPreamble{%
noexpandsetbox0noexpandvbox{%
noexpandnhblx@getmethehash{nhblx@name@thevalue{nhblx@name}}}}%
}%
nhblx@tmp@nocite
immediatewritenhblx@bibfile{%
@misc{nhblx@name@thevalue{nhblx@name}, author = {unexpanded{#1}}, %
options = {dataonly=true},}%
}%
}
AtEndDocument{%
closeoutnhblx@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}{forcsvlistnhblx@writenametobib}
newcommand*{resetboldnames}{defnhblx@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}
addboldnames{{Sigfridsson, Emma},{Vizedom, Monika B.}}
begin{document}
fullcite{sigfridsson}
fullcite{knuth:ct:a}
fullcite{vizedom:related}
resetboldnamesaddboldnames{Donald E. Knuth}
fullcite{knuth:ct:a}
resetboldnamesaddboldnames{Philipp Jaff{'e}}
fullcite{jaffe}
end{document}
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
.
Answered by moewe on April 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP