1

I am trying to get the year to be printed bold in the reference list. For other fields such as the author, I can do this by adding \textbf{mytext} to the .bib file. But for the year field this will not work.

I have found this question: How to write the year in the reference list in bold when using natbib? but it does not contain an answer other than "edit the .bst file".

I think I found the relevant function definition, but I have no idea how to change it, it doesn't seem to contain any string template where I might drop in the \textfb{} code:

FUNCTION {format.date}
{ year duplicate$ empty$
    { "empty year in " cite$ * warning$
       pop$ "" }
    'skip$
  if$
  month empty$
    'skip$
    { month
      " " * swap$ *
    }
  if$
  extra.label *
}
  • Thanks for accepting! If you want to note the possibility of making just the year bold you could add this in a comment, my choice to make the full date field bold was intentional. – Marijn Aug 28 at 16:57
  • Thanks for your answer, but in that case you did not answer the question. It refers specifically to the year. – TheChymera Aug 28 at 18:49
1

BibTeX has the concept of a stack, where the fields from the .bib file are pushed onto according to the definitions of the .bst file. The top element of the stack can be used for tests and conditionals, and usually after this element is processed it is popped from the stack into the output. The element on top of the stack can also be swapped to put another element on top, in order to change the order of the pop sequence for the output or in order to do something with the other element first before further processing.

In the format.date function the date string is on top of the stack. To make the year bold, you can put \textbf{ on top of the stack, swap it to put it on second place in the stack (with the date on top again) and add a closing }. This is done at the end of the function where the date string is fully formatted.

You didn't specify which natbib style you use, so in the MWE below I adapted abbrvnat.

.bst:

FUNCTION {format.date}
{ year duplicate$ empty$
    { "empty year in " cite$ * warning$
       pop$ "" }
    'skip$
  if$
  month empty$
    'skip$
    { month
      " " * swap$ *
    }
  if$
  extra.label *
  "\textbf{" swap$ * "}" *
}

.tex:

\documentclass{article}
\begin{filecontents}{\jobname.bib}
@article{myarticle,
  author = {Mary Jones},
  title = {First Things},
  journal = {Journal of Things},
  year = {2017}
}

@inproceedings{myproceedings,
  author = {Joe Peterson},
  title = {Briefly Explained},
  booktitle = {Conference of Briefness},
  year = {2017}
}
\end{filecontents}
\begin{document}
See \cite{myarticle,myproceedings}.

\bibliographystyle{xabbrvnat}
\bibliography{\jobname}
\end{document}

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.