1

I'm hoping to arrive at a simple bibliography customization where the year appears as the bib label.

Firstly, I consider that the solution could come from creating a .bst file, re-defining the biblabel or a combination of the latter (or maybe something simple I'm overlooking).

I typically use biblatex with biber as a backend.

Desired functionality

The following refers to the formatting of the entries made by \printbibliography. I'm not concerned here with citation style because \nocite{*} is used.

As background, consider a collection .bib items which are less like article citations, instead the content is predominantly limited to title, note, and sometimes month fields.

I would essentially like to replace the biblabel with the year from the bib entry. The body of the bib entry could follow the same logical sequence of a popular style with few exceptions. The year is not needed in the body of the bib entry.

Implementation of this may also require having a generous indent of the body of the bib entry; four characters for the year and then some. All body lines would have the same indent. The bib label text and the first line would be on the same line.

The option to make the biblabel some assembly of the month and year (e.g. <month>, <year>) also has a likely use case. One might also want to specify the indentation of the body on the fly if one jumped from having the year as bib label versus month + year as biblabel between different refsections.

How might this work?

This post explains how to change the position of the year. Perhaps it could shed light on how to remove it?

This post describes the authoryear style for biblatex. Perhaps a year style is already possible?

1

biblatex v3.11 is required for this answer.

Throwing together code for mergedate and the new locallabelwidth option we can arrive at

\documentclass{scrartcl}

\usepackage[labeldateparts, locallabelwidth]{biblatex}

\addbibresource{biblatex-examples.bib}

\defbibenvironment{bibliography}
  {\list
     {\printtext[parens]{\printlabeldate}}
     {\setlength{\labelwidth}{\labeldatewidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{##1\hss}}
  {\endlist}
  {\item}


\renewbibmacro*{date}{%
  \ifboolexpr{
    test {\iflabeldateisdate}
    and
    not test {\ifdateshavedifferentprecision{label}{}}
  }
    {}
    {\printdate}}

\renewbibmacro*{issue+date}{%
  \ifboolexpr{
    test {\iflabeldateisdate}
    and
    not test {\ifdateshavedifferentprecision{label}{}}
    and
    test {\iffieldundef{issue}}
  }
    {}
    {\printtext[parens]{%
       \printfield{issue}%
       \setunit*{\addspace}%
       \printdate}}%
  \newunit}

\makeatletter
\newlength{\labeldatewidth}
\newlength{\locallabeldatewidth}

\preto\blx@bbl@labeldate
  {\blx@getlabeldata
   \blx@setlabwidth{\labeldatewidth}{\printtext[parens]{\printlabeldate}}}
  {}{}
\apptocmd\blx@labelwidth@resetlocal{\locallabeldatewidth0pt\relax}{}{}
\apptocmd\blx@labelwidth@settolocal{\labeldatewidth\locallabeldatewidth\relax}{}{}

\def\blx@lengthitem#1{%
  \blx@ifdata{#1}
    {\begingroup
     \blx@getdata{#1}%
     \blx@bibcheck
     \iftoggle{blx@skipentry}{}{%
       \iftoggle{blx@labelnumber}
         {\blx@bbl@locallabelnumberwidth}
         {}%
       \iftoggle{blx@labelalpha}
         {\blx@bbl@locallabelalphawidth}
         {}%
       \nottoggle{blx@skipbiblist}
         {\blx@bbl@locallabelfields}
         {}
       \blx@setlabwidth{\locallabeldatewidth}{\printtext[parens]{\printlabeldate}}}% 
     \endgroup}
    {}}

\newrobustcmd*{\changedateformat}[2]{%
  \csdef{blx@dateformat@#1date}{#2}%
  \protected\csdef{blx@imc@print#1date}{\csuse{mkdaterange#2}{#1}}%
  \protected\csdef{blx@imc@print#1dateextra}{\csuse{mkdaterange#2extra}{#1}}}
\makeatletter

\begin{document}
\nocite{sigfridsson, worman, knuth:ct:a, knuth:ct:b, knuth:ct:c, nussbaum, vizedom:related, baez/online, itzhaki, markey, wassenberg}

\printbibliography

\changedateformat{label}{long}

\printbibliography
\end{document}

enter image description here

  • moewe, as to the deleted answer, I left a message there, but I suppose you didn't get it before I deleted. I said then I hadn't forgotten the date parentheses, but was just offering a general idea. But, still, as I wouldn't have much time today to see it through and as you had provided a more thorough solution I'd leave that one be. Even though in principle the answer could be kept in those (partial) terms, I do think your answer is superior and sort of encompasses what I had proposed, so I saw no reason to keep it. No grudges here, on the contrary, thank you for the pointer on mergedate. – gusbrs Mar 12 '18 at 11:35
  • @gusbrs Still I would ask you to (re)consider undeleting your answer. As I said, the idea is actually quite clever. It is more accessible and uses fewer internal macros than mine, so in that respect your answer is better. – moewe Mar 12 '18 at 11:52
  • Ok! I guess if simplicity is a criterion, there's something there then. :) – gusbrs Mar 12 '18 at 12:04
1

Perhaps it is possible to adapt the alphabetic style to use the year as labelalpha. Proof of concept:

\documentclass{article}

\usepackage[style=alphabetic]{biblatex}

\addbibresource{biblatex-examples.bib}

\DeclareLabelalphaTemplate{
  \labelelement{
    \field[strwidth=4,strside=right]{year}
  }
}

\defbibenvironment{bibliography}
  {\list
     {\printtext[labelalphawidth]{%
        \printfield{labelprefix}%
        \printfield{labelalpha}}}
     {\setlength{\labelwidth}{\labelalphawidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{##1\hss}}
  {\endlist}
  {\item}

\DeclareFieldFormat{labelalphawidth}{\mkbibparens{#1}}

\begin{document}

\nocite{*}

\printbibliography

\end{document}

enter image description here

Update: If you'd also like to remove the year from the references in cases in which the date is comprised only of the year, you can go with (courtesy of moewe):

\documentclass{article}

\usepackage[style=alphabetic]{biblatex}

\addbibresource{biblatex-examples.bib}

\DeclareLabelalphaTemplate{
  \labelelement{
    \field[strwidth=4,strside=right]{year}
  }
}

\defbibenvironment{bibliography}
  {\list
     {\printtext[labelalphawidth]{%
        \printfield{labelprefix}%
        \printfield{labelalpha}}}
     {\setlength{\labelwidth}{\labelalphawidth}%
      \setlength{\leftmargin}{\labelwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \addtolength{\leftmargin}{\labelsep}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{##1\hss}}
  {\endlist}
  {\item}

\renewbibmacro*{date}{%
    \ifboolexpr{
        test {\iffieldundef{month}}
        and
        test {\iffieldundef{season}}
        }
    {}
    {\printdate}}

\renewbibmacro*{issue+date}{%
    \ifboolexpr{
        test {\iffieldundef{month}}
        and
        test {\iffieldundef{season}}
        and
        test {\iffieldundef{issue}}
        }
    {}
    {\printtext[parens]{%
     \printfield{issue}%
     \setunit*{\addspace}%
     \printdate}}%
     \newunit}

\DeclareFieldFormat{labelalphawidth}{\mkbibparens{#1}}

\begin{document}

\nocite{*}

\printbibliography

\end{document}
  • You probably want to do something about the empty issue-date parentheses for @articles. The easiest way is probably a check similar to those done for mergedate. – moewe Mar 12 '18 at 8:01
  • @moewe, I didn't forget about it, I just offered a general idea. But, as I'll have little time for this today and as you offered something more thorough, I'll probably leave this one be. – gusbrs Mar 12 '18 at 10:05
  • I think you only need something along the lines of \renewbibmacro*{date}{% \ifboolexpr{ test {\iffieldundef{year}} and test {\iffieldundef{season}} } {} {\printdate}} (modulo line breaks) – moewe Mar 12 '18 at 15:10
  • and \renewbibmacro*{issue+date}{% \ifboolexpr{ \iffieldundef{year}} and test {\iffieldundef{season}} and test {\iffieldundef{issue}} } {} {\printtext[parens]{% \printfield{issue}% \setunit*{\addspace}% \printdate}}% \newunit}. But you need to drop the \AtEveryBibitem{\clearfield{year}}. – moewe Mar 12 '18 at 15:10
  • That will cause the year to reappear if there is a more precise date, i.e. (March 1999) instead of only (March). But the latter would need more fiddling. – moewe Mar 12 '18 at 15:12

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.