4

I would like to create a list of references ordered from the most recent to the oldest.

The MWE bellow gives a basic solution:

\documentclass{article}
\usepackage[style=authoryear,sorting=ydnt]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{Rabelais1532,
  author = {Rabelais, Fran\c{c}ois},
  date = {1532},
  title = {Pantagruel},
  keywords = {1532},
}
@book{Hugo1862,
  author = {Hugo, Victor},
  date = {1862},
  title = {Les Mis\'{e}rables},
  keywords = {1862},
}
@book{Hugo1831,
  author = {Hugo, Victor},
  date = {1831},
  title = {Notre-Dame de Paris},
  keywords = {1831},
}
@book{Zola1885,
  author = {Zola, \'{E}mile},
  date = {1885},
  title = {Germinal},
  keywords = {1885},
}
@book{Balzac1831,
  author = {de Balzac, Honor\'{e}},
  date = {1831},
  title = {The Skin of Sorrow},
  keywords = {1831},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography[title=References (default)]
\end{document}

However I would like to create some parts in the list, each part corresponding to a year, something like this:

\printbibliography[keyword=1885, title=1885]
\printbibliography[keyword=1862, title=1862]
\printbibliography[keyword=1831, title=1831]
\printbibliography[keyword=1532, title=1532]

I have tried to define filters in the preamble, modified from the biblatex documentation (§3.7.9, p. 89):

\defbibfilter{1885}{%
    date=1885
}%

and to add the following code:

\printbibliography[filter=1885, title=1885]

but the log file indicates:

Package biblatex Error: Invalid filter expression.

Package biblatex Error: Filter '1885' not found.

Is it possible, using filter commands for example, to automate the process with references ordered by year decreasing?

4

I assume it would be nicer if the year lists would be generated automatically, so you don't have to write \printbibliography[keyword=1885, title=1885] etc.

The problem with your filter was that date=1885 is not a valid filter expression. A filter can only have (not)type, (not)subtype, (not)keyword and (not)field (pure existence) expressions. For more complicated beasts you need a bibcheck. Indeed, this is what we use below. The bibcheck thisyear checks if an entry dates to a certain year.

Here I'm using LaTeX3 code to sort the list of all years easily.

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

\usepackage{xparse}

\ExplSyntaxOn
\seq_new:N \g__blxbibbyyear_yearlist_seq

\cs_new:Npn \__blxbibbyyear_seq_gput_right_once:Nn #1 #2
  {
    \seq_if_in:NnF #1 {#2}
      { \seq_gput_right:Nn #1 {#2} }
  }

\cs_generate_variant:Nn \__blxbibbyyear_seq_gput_right_once:Nn { NV, Nx }


\prg_new_conditional:Nnn \blx_field_if_undef:n { p, T, F , TF }
  {
    \use:c { iffieldundef } { #1 } { \prg_return_true: } { \prg_return_false: }
  }

% unfortunately, \iffieldint is not expandable, so no p version for us, boo
\prg_new_protected_conditional:Nnn \blx_field_if_int:n { T, F , TF }
  {
    \iffieldint { #1 } { \prg_return_true: } { \prg_return_false: }
  }

\AtDataInput
  {
    \blx_field_if_undef:nF { labeldatesource }
      { 
        \blx_field_if_undef:nTF { \thefield{labeldatesource}year }
          {
            \blx_field_if_undef:nF { \thefield{labeldatesource} }
              {
                \blx_field_if_int:nT { \thefield{labeldatesource} }
                  {
                    \__blxbibbyyear_seq_gput_right_once:Nx \g__blxbibbyyear_yearlist_seq
                      { \thefield{\thefield{labeldatesource}} }
                  }
              }
          }
          {
            \__blxbibbyyear_seq_gput_right_once:Nx \g__blxbibbyyear_yearlist_seq
              { \thefield{\thefield{labeldatesource}year} }
          }
      }
  }

\cs_new:Npn \blxbibbyyear_seq_sort_bydirection:NN #1 #2
  {
    \seq_gsort:Nn #2
      {
         \int_compare:nNnTF { ##1 } #1 { ##2 }
          { \sort_return_swapped: }
          { \sort_return_same: }
      }
  }

\cs_new:Nn \blxbibbyyear_seq_sort_descending:N
  {
    \blxbibbyyear_seq_sort_bydirection:NN < #1
  }

\cs_new_nopar:Npn \blxbibbyyear_print_yearbib:nn #1 #2
  {
    \defbibcheck{thisyear}
      {
        \blx_field_if_int:nTF { labelyear }
          {
            \int_compare:nNnF { \thefield{labelyear} } = { #1 }
              { \skipentry }
          }
          { \skipentry }
      }
    \printbibliography[heading=subbibliography, title=#1, check=thisyear, #2]
  }


\DeclareDocumentCommand{\printbibbyyear}{O{}}
  {
    \blxbibbyyear_seq_sort_descending:N \g__blxbibbyyear_yearlist_seq
    \seq_map_inline:Nn \g__blxbibbyyear_yearlist_seq
      { \blxbibbyyear_print_yearbib:nn {##1} {#1} }
  }
\ExplSyntaxOff

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Rabelais1532,
  author = {Rabelais, Fran\c{c}ois},
  date = {1532},
  title = {Pantagruel},
}
@book{Hugo1862,
  author = {Hugo, Victor},
  date = {1862},
  title = {Les Mis\'{e}rables},
}
@book{Hugo1831,
  author = {Hugo, Victor},
  date = {1831},
  title = {Notre-Dame de Paris},
}
@book{Zola1885,
  author = {Zola, \'{E}mile},
  date = {1885},
  title = {Germinal},
}
@book{Balzac1831,
  author = {de Balzac, Honor\'{e}},
  year = {1831},
  title = {The Skin of Sorrow},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibheading
\printbibbyyear
\end{document}

Four bibliographies: One for each year

  • moewe, a curiosity. Is there a reason why biblatex seems to refrain from LaTeX3 syntax? (If it does, but I don't recall ever seeing it in biblatex code). – gusbrs Jan 30 '19 at 17:06
  • I don't get a result compiling your code with the default option style=numeric of biblatex. I use pdfLaTeX, BibTeX (backend biber) and pdfLaTeX again. When I compile it first with style=authoryear and then switch to style=numeric it works at first. But after another compilation with BibTeX and pdfLaTeX no result is shown any more. – Nico Jan 30 '19 at 17:54
  • It should be used together with option labeldateparts=true. So \usepackage[style=numeric, sorting=ydnt, labeldateparts=true]{biblatex} works. This was a hint by gusbrs in another question (tex.stackexchange.com/questions/472588/…) – Nico Jan 30 '19 at 18:15
  • @gusbrs Well, biblatex is not written in expl3, it uses normal LaTeX2e and etoolbox (also by Philip Lehman), so expl3 language does not come naturally to the current code base. As to why LaTeX3 was not used for the code base, I don't know. LaTeX3 was around back in 2006 when biblatex development started (according to the changelog in biblatex.tex), but I'm not sure if it was considered stable enough to be the basis of such a large package. Plus there will have been the preferences of PL, not sure what his stance was towards expl3 (given the state of the project back then). – moewe Jan 30 '19 at 22:09
  • ... It has been suggested once or twice that biblatex could benefit from expl3, but I'm not sure how good an idea it is to mix the current LaTeX2e base with expl3 and re-implementing everything in expl3 seems a huge task. – moewe Jan 30 '19 at 22: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.