0

I am using the following style:

\usepackage[style=authoryear-comp, 
backend=biber, 
giveninits=true
]{biblatex}

I have the following two exemplary entries in my bib file

@article{HN2018a,
author = {THOMPSON, RAY},
title = {Exemplary Title A},
journal = {The Journal of Bibtex-Examples},
volume = {4343},
number = {2},
pages = {1-2},
year = {2018}
}

@article{HN2018b,
author = {Thompson, RAY},
title = {Exemplary Title B},
journal = {The Journal of Bibtex Second-Entries},
volume = {3},
number = {4},
pages = {1-2},
year = {2018}
}

I use this command: \cite{HN2018a,HN2018b}

I get:

Thompson 2018a,b

Two things I do not like about this outcome. First, there is no space after the comma. Second, it would look better imho to have

Thompson 2018a, 2018b

Is it possible to change this with the used citation style?

1 Answer 1

2

The comma is hard-coded in authoryear-comp.cbx (but it can be customised as extradateonlycompcitedelim – what a catchy name – in biblatex-ext's version of the -comp styles).

In order to generate these compact citations, biblatex needs to remember the year of the last entry. If we can make it forget about that year, we automatically get the desired citation style.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear-comp, 
  backend=biber,
  giveninits=true, uniquename=init,
]{biblatex}

\makeatletter
\AtEveryCitekey{\global\undef\cbx@lastyear}
\makeatother

\addbibresource{biblatex-examples.bib}

\begin{document}
\autocite{knuth:ct:b,knuth:ct:c}
\printbibliography
\end{document}

(Knuth 1986a, 1986b)


The following solution feels conceptually nicer to me, but requires a lot more code. We can redefine the relevant citation bibmacros to remove the test for \cbx@lastyear directly.

\makeatletter
\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}%
        \usebibmacro{cite:labeldate+extradate}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\setunit{\compcitedelim}%
           \usebibmacro{cite:labeldate+extradate}}
          {\printnames{labelname}%
           \setunit{\printdelim{nameyeardelim}}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\renewbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\setunit{\compcitedelim}%
           \usebibmacro{cite:labeldate+extradate}}
          {\usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
    {\iffieldundef{shorthand}
       {\setunit{\compcitedelim}%
        \usebibmacro{cite:labeldate+extradate}}
       {\setunit{\compcitedelim}%
        \usebibmacro{cite:shorthand}}}
    {\ifnameundef{labelname}
       {\iffieldundef{shorthand}
          {\usebibmacro{cite:label}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nonameyeardelim}\bibopenparen}%
           \ifnumequal{\value{citecount}}{1}
             {\usebibmacro{prenote}}
             {}%
           \usebibmacro{cite:labeldate+extradate}}
          {\usebibmacro{cite:shorthand}}}
       {\printnames{labelname}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \iffieldundef{shorthand}
          {\iffieldundef{labelyear}
             {\usebibmacro{cite:label}}
             {\usebibmacro{cite:labeldate+extradate}}}
          {\usebibmacro{cite:shorthand}}}%
     \stepcounter{textcitecount}%
     \savefield{namehash}{\cbx@lasthash}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
    \textcitedelim}}
\makeatother

Compare with the original definitions in authoryear-comp.cbx (ll. 26-114 in v3.14).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .