2

I would like to set in bold one particular author name when it appears in references throughout the text.

I am following the approach in this answer that proposes to modify the *.bst file for my citation style. More specifically, the answer says to modify the function format.names.

My problem is that with my particular style apalike I cannot figure out how to change format.names. I tried to place highlight.if.custom.author (a custom function that applies \textbf) on different lines within format.names, but this either results in a BibTeX error or makes all author names disappear.

Details about the desired result:

  • In the MWE below I would like to set in bold "Koehn, P." when it resulted from \bibentry.
  • If possible, I do not want to use bold font in regular citations (e.g. with \citep) and my links should still be colored.
  • If possible, I do not want the bibliography at the end to contain bold font either.

MWE

Tex file:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{natbib} \usepackage{bibentry} \usepackage[colorlinks=true, allcolors=blue]{hyperref}

\nobibliography*

\title{MWE}

\begin{document}

\maketitle

\section{MWE}

Here is a sentence with a regular reference \citep{Koehn2017}. \

\noindent Here is a list of all contributions, some by an important author in \textbf{bold}:

\begin{itemize} \item \bibentry{Koehn2017} \item \bibentry{Lison2016} \item \bibentry{koehn2005epc} \end{itemize}

\clearpage

\bibliographystyle{apalike} \bibliography{bibliography}

\end{document}

Bibliography file bibliography.bib:

@InProceedings{Koehn2017,
  author =  {Koehn, Philipp
     and Knowles, Rebecca},
  title = {{Six Challenges for Neural Machine Translation}},
  booktitle = "Proceedings of the First Workshop on Neural Machine Translation",
  year =    "2017",
  publisher =   "Association for Computational Linguistics",
  pages =   "28--39",
  location =    "Vancouver, Canada"
}
@InProceedings{Lison2016,
  author =  {Lison, Pierre and
            Tiedemann, Jörg},
  title = {{OpenSubtitles2016: Extracting Large Parallel Corpora from Movie and TV Subtitles}},
  booktitle = "Proceedings of the 10th International Conference on Language Resources and Evaluation (LREC 2016)",
  year =    "2016",
  publisher =   "European Language Resources Association (ELRA)",
  editor = {Nicoletta Calzolari (Conference Chair) and Khalid Choukri and Thierry Declerck and Sara Goggi and Marko Grobelnik and Bente Maegaard and Joseph Mariani and Helene Mazo and Asuncion Moreno and Jan Odijk and Stelios Piperidis},
  pages = "923--929",
  location = {Portorož, Slovenia}
}

@inproceedings{koehn2005epc, added-at = {2010-11-10T15:46:05.000+0100}, address = {Phuket, Thailand}, author = {Koehn, Philipp}, biburl = {https://www.bibsonomy.org/bibtex/205e5fa13fd7ba7992aedfe3514379a1f/unhammer}, booktitle = {{Conference Proceedings: the tenth Machine Translation Summit}}, interhash = {abd06b551527865eb50e21508841b6de}, intrahash = {05e5fa13fd7ba7992aedfe3514379a1f}, keywords = {Corpus Europarl MT Master}, organization = {AAMT}, pages = {79--86}, publisher = {AAMT}, timestamp = {2010-11-10T15:46:05.000+0100}, title = {{Europarl: A Parallel Corpus for Statistical Machine Translation}}, url = {http://mt-archive.info/MTS-2005-Koehn.pdf}, year = 2005 }

Changes to apalike.bst:

FUNCTION {custom.author}
{ "Koehn, P." }

FUNCTION {highlight} { duplicate$ empty$ { pop$ "" } { "\textbf{" swap$ * "}" * } if$ }

FUNCTION {highlight.if.custom.author} { duplicate$ purify$ custom.author purify$ = { highlight } 'skip$ if$ }

Overleaf link to MWE

https://www.overleaf.com/read/vmbzpdtqrqnm

1 Answers1

2

Almost there! I modified the format.names function to say

FUNCTION {format.names}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't :=   % last name first
      t highlight.if.custom.author 't :=
      nameptr #1 >
        { namesleft #1 >
            { ", " * t * }
            { numnames #2 >
                { "," * }
                'skip$
              if$
              t "others" =
                { " et~al." * }
                { " and " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

that is, you insert the line t highlight.if.custom.author 't :=

This puts the special author in bold everywhere. Controlling where it does, is best done from within LaTeX. For this, put in your .tex's preamble

\def\specialAuthor#1{#1}

and replace the \textbf in your .bst with \specialAuthor.

Now, for the list where we want the bold formatting, surround it like this:

\def\specialAuthor#1{\textbf{#1}}
\begin{itemize}
    \item \bibentry{Koehn2017}
    \item \bibentry{Lison2016}
    \item \bibentry{koehn2005epc}
\end{itemize}
\def\specialAuthor#1{#1}

Here we temporarily change the style for special authors. If you want the style change to be hooked specifically for \bibentry's, ask me in the comments, but if you're using it like in your MWE, I would prefer the code fragment above.

Hope this answer has helped you! Has it?

EDIT:

More information about bibtex code. Firstly, I must mention the TameTheBest manual, it's all about this weird bibtex language: http://tug.ctan.org/info/bibtex/tamethebeast/ttb_en.pdf, a great resource to start diving in deep.

Bibtex language is a very weird language, with a core concept: the stack. If I say "aa" "bb" * then I've put two strings on the stack. Then * is performed, which consumes the last two elements of the stack, and puts their concatenation on the stack.

You could then assign that concatenated value to something. For example

"aa" "bb" * 'myvar :=

concatenates "aa" and "bb" ("aabb"), then puts a variable myvar on the stack, and then := is performed. The second-to-last element on the stack is then assigned to the last element on the stack.

Now back to this post: The format.names is tasked with putting together a formatted list of the authors. You see for example there is logic about putting in ", " and truncating with " et al.".

In the line before the one I added, t is assigned the author's name, in already formatted form, so "Koehn, P." for example. Now my line:

t highlight.if.custom.author 't :=

I put the value of t on the stack. Then the function highlight.if.custom.author is called, which looks at what was placed on the stack, and replaces it with the extra-formatted string. (I.e. adding \specialAuthor if necessary.)

Then I again put t on the stack, but preceded with an accent; we don't want the value of t on the stack, but the captured variable t itself. This is because we next have :=, which assigns this newly formatted author name to t.

You see later down the line, for example in ", " * t *, t is once again used. We're building up a string of all the authors, and what has currently been built up is the last item on the stack. Hence, ", " * appends ", " to the current built-up string. Next our t is stated, and it is appended too.

Just one more bonus explanation:

nameptr #1 >
{
    ...
}
't
if$

First nameptr #1 > puts the value of a variable on the stack: are we processing the first author (number 1), the second author (number 2), ...? Next, the number '1' is added to the stack. Then, '>' evaluates. It checks if nameptr is greater than 1. If so, then 1 (true), else 0 (false) is put on the stack (and the compare values are consumed).

Next there follow three things, a group {...}, a captured variable 't, and if$. The if function looks back three items. There it finds our 1 or 0 from earlier. In case of 1 it executes the stack item following it (the 'group' here), and in case of 0 it expands our captured 't. Assume the latter case. Then, expansion of our capture evaluates to t being placed on the stack.

For any further names, we are at the second name or further, and we need more complicated logic, like , , and and et al. insertion. This is done by the code in the group, which appends its value to the string we put on the stack for the case nameptr was still 1.

Note the importance of capturing when using an if$: say for example instead of 't there had been skip$ (which means: do nothing), then our bibtex language executes that skip$, and by the time it arrives at if$, it only has two items on its stack! The skip$ has vanished! So either you must group things, or, as a shortcut, capture it by preceding it with an '. In that case the 'skip$ will be put as a function on the stack, and is indeed recognized as the else-clause.

That are quite some explanations, hope it gave you some taste. And refer to the beast, tame the beast, for more! :)