Biblatex: divide list of references in subparts by year (descending order)












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, Franc{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?










share|improve this question




















  • 1





    Related: tex.stackexchange.com/q/346564/35864

    – moewe
    May 31 '18 at 19:24
















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, Franc{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?










share|improve this question




















  • 1





    Related: tex.stackexchange.com/q/346564/35864

    – moewe
    May 31 '18 at 19:24














4












4








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, Franc{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?










share|improve this question
















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, Franc{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?







biblatex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 31 '18 at 15:54







Vince

















asked May 31 '18 at 15:49









VinceVince

97119




97119








  • 1





    Related: tex.stackexchange.com/q/346564/35864

    – moewe
    May 31 '18 at 19:24














  • 1





    Related: tex.stackexchange.com/q/346564/35864

    – moewe
    May 31 '18 at 19:24








1




1





Related: tex.stackexchange.com/q/346564/35864

– moewe
May 31 '18 at 19:24





Related: tex.stackexchange.com/q/346564/35864

– moewe
May 31 '18 at 19:24










1 Answer
1






active

oldest

votes


















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, Franc{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






share|improve this answer


























  • 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 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 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 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 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 at 22:12











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f434351%2fbiblatex-divide-list-of-references-in-subparts-by-year-descending-order%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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, Franc{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






share|improve this answer


























  • 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 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 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 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 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 at 22:12
















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, Franc{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






share|improve this answer


























  • 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 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 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 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 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 at 22:12














4












4








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, Franc{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






share|improve this answer















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, Franc{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







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 27 at 6:37

























answered May 31 '18 at 20:31









moewemoewe

92.8k10115351




92.8k10115351













  • 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 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 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 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 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 at 22:12



















  • 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 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 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 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 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 at 22:12

















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 at 17:06





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 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 at 17:54







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 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 at 18:15





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 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 at 22:09





@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 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 at 22:12





... 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 at 22:12


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f434351%2fbiblatex-divide-list-of-references-in-subparts-by-year-descending-order%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?