1

I would like to ensure that all entries in the bibliography are sorted by year. In addition, a separate heading should be generated for each year. The whole should run as automatically as possible, i.e. I don't want to manually create "keys" for each year. My first thought was something like that:

\foreach \year in {2013,...,2018} {\printbibliography[year=\year, title=\year]}

Unfortunately biblatex does not offer an option year=... (That would be a nice feature). What I have achieved so far is that for each year a heading is created, and all entries are sorted correctly under the corresponding year. However, in the years in which there was no publication, a heading is erroneously created with no entries under it. Below you can see my MWE. I don't understand why \printbibliography[check=publicationInThisYear] is "executed" even though the check should fail for the case that there was no citation in the current year. Outside the loop, \printbibliography[type=thesis] has a different behaviour. As expected, it does not generate an entry (while the "thesis-bibentry" Bar2017b is commented out and the check fails). Where's the mistake?

\documentclass{article}
\usepackage{filecontents}
\usepackage{pgffor}
\usepackage[sorting=ynt]{biblatex}
\begin{filecontents*}{\jobname.bib}

@inproceedings{Bar2014,
    author = {F. Bar and B. Foo},
    booktitle = {The conference 2014 on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2014}
}

@article{Bar2015a,
    author = {F. Bar and B. Foo},
    booktitle = {The conference 2015 on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = 2015
}

@inproceedings{Bar2015b,
    author = {F. Bar},
booktitle = {International Conference on Information 2015},
pages = {3--4},
title = {{Advanced functionality and performance or nothing }},
year = {2015}
}

@book{Bar2017,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2017}
}

@inproceedings{Bar2018,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing 2018},
pages = {1--2},
title = {{A meaningless title}},
    year = {2018}
    }

%@thesis{Bar2017b,
%author = {F. Bar},
%title = {Bar Thesis},
%type = {Dissertation},
%year = {2017},
%}
    \end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\def\yrlist{2013,...,2018}

\foreach \yr in \yrlist{
\defbibcheck{publicationInthisYear}{
        \ifnumequal{\thefield{year}}{\yr}{}{\skipentry}
  }
        \printbibliography[check=publicationInthisYear, title=\yr]

}
\printbibliography[type=thesis]
\end{document}

enter image description here

Nico
  • 1,694
  • 1
    maybe https://tex.stackexchange.com/a/434393/36296 can help – samcarter_is_at_topanswers.xyz Jan 30 '19 at 17:01
  • It seems to be a very similar problem. But the solution provided does not work with biblatex-option style=numeric. – Nico Jan 30 '19 at 17:47
  • The answer uses labelyear, which is not generated by default for numeric. You could explicitly ask for it with option labeldateparts=true. (Or adapt the code not to rely on labeldate and co.) – gusbrs Jan 30 '19 at 18:11
  • Thank you, now it works. Should I provide it as an answer, although I took the main part of the code by another answer? – Nico Jan 30 '19 at 18:18
  • @Nico Let's wait and see if anyone else has something to add to this. If not, I think we might consider marking this question as a duplicate of that one. What do you think? – gusbrs Jan 30 '19 at 18:20
  • @gusbrs Yes that would make sense. In addition, the numbering of the entries is still not correct. – Nico Jan 30 '19 at 18:22
  • 1
    @Nico It is "correct", it is just not what you want. You probably want option defernumbers=true though. – gusbrs Jan 30 '19 at 18:24
  • @gusbrs It’s just the opposite that I want. I want the latest entry to have the highest number and then a chronological descent to 1. For me a numbering like 5,4,2,3,1 is not „correct“. Do you know how to fix this? – Nico Jan 30 '19 at 18:54

1 Answers1

3

Just digging the site, I was able to cook something that I believe does what you want (though it is not quite clear what the end desired result really is, from your question).

But using moewe's answer at Biblatex: divide list of references in subparts by year (descending order) and Audrey's answer at biblatex: Reverse numbering (i.e., count down), alongside with the proper set of biblatex options, seems to get the job done.

\documentclass{article}
\usepackage[style=numeric, sorting=ydnt, labeldateparts=true, defernumbers=true]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@inproceedings{Bar2014,
  author = {F. Bar and B. Foo},
  booktitle = {The conference 2014 on nothing},
  pages = {1--2},
  title = {{A meaningless title}},
  year = {2014}
}

@article{Bar2015a,
  author = {F. Bar and B. Foo},
  booktitle = {The conference 2015 on nothing},
  pages = {1--2},
  title = {{A meaningless title}},
  year = 2015
}

@inproceedings{Bar2015b,
  author = {F. Bar},
  booktitle = {International Conference on Information 2015},
  pages = {3--4},
  title = {Advanced functionality and performance or nothing},
  year = {2015}
}

@book{Bar2017,
  author = {F. Bar and B. Foo},
  booktitle = {The conference on nothing},
  pages = {1--2},
  title = {{A meaningless title}},
  year = {2017}
}

@inproceedings{Bar2018,
  author = {F. Bar and B. Foo},
  booktitle = {The conference on nothing 2018},
  pages = {1--2},
  title = {A meaningless title},
  year = {2018}
}

@thesis{Bar2017b,
  author = {F. Bar},
  title = {Bar Thesis},
  type = {Dissertation},
  year = {2017},
}
\end{filecontents}


\addbibresource{\jobname.bib}

\usepackage{xparse}

% from moewe’s answer at https://tex.stackexchange.com/a/434393/105447

\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_sort: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

% Audrey’s approach to reverse numbering
% at https://tex.stackexchange.com/a/22770/105447

% Count total number of entries in each refsection
\AtDataInput{%
  \csnumgdef{entrycount:\therefsection}{%
    \csuse{entrycount:\therefsection}+1}}

% Print the labelnumber as the total number of entries in the
% current refsection, minus the actual labelnumber, plus one
\DeclareFieldFormat{labelnumber}{\mkbibdesc{#1}}
\newrobustcmd*{\mkbibdesc}[1]{%
  \number\numexpr\csuse{entrycount:\therefsection}+1-#1\relax}

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

enter image description here

gusbrs
  • 13,740
  • Thank you very much for your answer. Even though it may not have exactly emerged from my question, it is exactly as I wanted it to be. Since I always like to learn, could you give a short comment on my first attempt and explain to me why the headings were created for each year? – Nico Feb 01 '19 at 08:44
  • @Nico Unfortunately, I don't know why the headings were created for each year in your first attempt. – gusbrs Feb 01 '19 at 09:10