# Biblatex: bold dates if within past 5 years

For official reporting we're often requested to set in bold our name in the references section, as well as the publication date if within the past 5 years.

I've manually edited the author lists replacing my name with a macro \baptiste which I define in the preamble,

\newcommand{\baptiste}{\textbf{B. LastName}}


For the dates however, I'm a bit stuck.

\begin{filecontents}{\jobname.bib}
@book{Labov1972,
Author = {William Labov},
Publisher = {University of Pennsylvania Press},
Title = {Sociolinguistic Patterns},
Year = {2018}}

@book{Chomsky1957,
Author = {Noam Chomsky},
Publisher = {Mouton},
Title = {Syntactic Structures},
Year = {1957}}
}
\end{filecontents}

\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\begin{document}
Some famous linguists wrote a couple of books \autocite{Labov1972,Chomsky1957}.
\printbibliography
\end{document}


I'll only address the question about the date. Bold names have been dealt with extensively elsewhere: Make specific author bold using biblatex.

We can define a \iflastnyears{<n>} that checks if the year field is among the last <n> (complete) years, so that currently (i.e. in 2020) \iflastnyears{5} would be true for the years 2015 up to and including 2020. Of course you can adjust the logic in the definition to your liking.

Note that we had to include the clunky \ifdateera{bce} because biblatex doesn't save the sign of the year in the year field, so that it actually contains \abs{year}. \ifdateera{bce} is true for dates before our year 0 (so for negative dates).

\documentclass{article}
\usepackage[style=authoryear]{biblatex}

\makeatletter
% \year should hold the current year, but there are classes
% (and maybe packages) that redefine it :-(
\newcommand*{\iflastnyears}[1]{%
\ifdateera{bce}
{\@secondoftwo}
{\iffieldint{year}
{\ifnumgreater{\thefield{year}}{\year-#1-1}}
{\@secondoftwo}}}
\makeatother

\DeclareFieldFormat{date}{%
\iflastnyears{5}
{\mkbibbold{#1}}
{#1}%
}

\begin{filecontents}{\jobname.bib}
@book{Labov2018,
Author    = {William Labov},
Publisher = {University of Pennsylvania Press},
Title     = {Sociolinguistic Patterns},
Year      = {2018},
}
@book{Chomsky1957,
Author    = {Noam Chomsky},
Publisher = {Mouton},
Title     = {Syntactic Structures},
Year      = {1957},
}
\end{filecontents}

\begin{document}
Some famous linguists wrote a couple of books \autocite{Labov2018,Chomsky1957}.
\printbibliography
\end{document}


If you want to highlight the years in the citations as well, add

\DeclareFieldFormat{labeldate}{%
\ifboolexpr{test {\iflabeldateisdate} and test {\iflastnyears{5}}}
{\mkbibbold{#1}}
{#1}%
}

• Fantastic, thank you! The highlight feature for the name sounds interesting but for now my workaround is good enough. – baptiste Feb 19 at 21:10