6

The solution provided here

Make one author's name bold every time it shows up in the bibliography

does unfortunately not work, as soon as the Author's name contains special characters, e.g. Hans M{\"u}ller? How can this problem be solved?

2 Answers2

4

The following modification of this answer seems to work if you use the plain bib style:

\let\originalbibitem\bibitem
\def\bibitem#1#2\par{%
  \noexpandarg
  \originalbibitem{#1}
  \StrSubstitute{#2}{Hans M{\"u}ller}{\textbf{Hans M{\"u}ller}}\par}

Example

\begin{filecontents*}{\jobname.bib}
@article{a,
author={M{\"u}ller, Gerd},
title={Scoring goals},
journal={J. Applied Soccer},
year={1974},
}
@article{b,
author={M{\"u}ller, Hans},
title={Splitting hairs},
journal={J. Abstract Tetrapiloctomy},
year={1255},
}
\end{filecontents*}

\documentclass{article}

\usepackage{xstring}

\let\originalbibitem\bibitem
\def\bibitem#1#2\par{%
  \noexpandarg
  \originalbibitem{#1}
  \StrSubstitute{#2}{Hans M{\"u}ller}{\textbf{Hans M{\"u}ller}}\par}

\begin{document}
\cite{a}

\cite{b}

\bibliographystyle{plain}
\bibliography{\jobname}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Well, the simple example indeed works, but if I use a more complex example, e.g. with the web.sty and URLs, I receive the error message(s): unaway argument? ... ! Paragraph ended before \BR@c@bibitem was complete. \par – Patrick Jöckel Mar 13 '12 at 21:26
  • @PatrickJöckel This is not a forum, but a "question and answers" site. Please, edit the original question, rather than adding "non answers". You need to register, though. A moderator will merge the "different identities". – egreg Mar 13 '12 at 21:29
  • Thank you, @egreg! This is an excellent answer. – Adam Erickson Jan 12 '19 at 05:02
  • @egreg I'm hoping to use this method with the \makebold command (https://tex.stackexchange.com/questions/470783/use-value-from-xparse-key-value-store-in-regular-expressions#comment1186212_470785) instead of StrSubstitute. However, only the last bibliography entry works. Any suggestions? – Adam Erickson Jan 19 '19 at 03:37
  • @AdamErickson You probably are not separating a \bibitem from the next with a blank line. – egreg Jan 19 '19 at 09:34
  • @egreg I have it like this and it does not work unfortunately: \let\originalbibitem\bibitem \def\bibitem#1#2\par{% \originalbibitem{#1} \makebold{#2}\par } – Adam Erickson Jan 19 '19 at 22:01
  • @egreg It appears to be the \makebold command that is causing this behaviour, as \StrSubstitute works as expected. Any ideas? I'd be happy to share my code. – Adam Erickson Jan 20 '19 at 22:14
  • @AdamErickson I'm not clairvoyant. If you have a question related to this one, but you're using a different set of macros, then ask it properly. – egreg Jan 20 '19 at 22:17
  • @egreg New question posted here: https://tex.stackexchange.com/questions/471062/automatic-bold-formatting-of-author-name-in-bibliography – Adam Erickson Jan 20 '19 at 23:14
1

I finally found a straightforward solution by modifying the .bbl-file with sed:

bibtex mydoc

mv my.bbl my.bbl.ori 

cat my.bbl.ori | tr '\n' '\t' | sed 's/\(M{\\\"u}ller, *\t* *H.\)/\\textbf{\1}/g'  | tr '\t' '\n' > my.bbl

The trick is to convert newlines to tabs in order to enable sed to wrap the name into \texbf{...}, even if there is a newline in between.

Thorsten
  • 12,872