Biblatex: divide list of references in subparts by year (descending order)
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
add a comment |
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
1
Related: tex.stackexchange.com/q/346564/35864
– moewe
May 31 '18 at 19:24
add a comment |
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
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
biblatex
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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}
moewe, a curiosity. Is there a reason whybiblatex
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 inexpl3
, it uses normal LaTeX2e andetoolbox
(also by Philip Lehman), soexpl3
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 whenbiblatex
development started (according to the changelog inbiblatex.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 towardsexpl3
(given the state of the project back then).
– moewe
Jan 30 at 22:09
... It has been suggested once or twice thatbiblatex
could benefit fromexpl3
, but I'm not sure how good an idea it is to mix the current LaTeX2e base withexpl3
and re-implementing everything inexpl3
seems a huge task.
– moewe
Jan 30 at 22:12
|
show 5 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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}
moewe, a curiosity. Is there a reason whybiblatex
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 inexpl3
, it uses normal LaTeX2e andetoolbox
(also by Philip Lehman), soexpl3
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 whenbiblatex
development started (according to the changelog inbiblatex.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 towardsexpl3
(given the state of the project back then).
– moewe
Jan 30 at 22:09
... It has been suggested once or twice thatbiblatex
could benefit fromexpl3
, but I'm not sure how good an idea it is to mix the current LaTeX2e base withexpl3
and re-implementing everything inexpl3
seems a huge task.
– moewe
Jan 30 at 22:12
|
show 5 more comments
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}
moewe, a curiosity. Is there a reason whybiblatex
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 inexpl3
, it uses normal LaTeX2e andetoolbox
(also by Philip Lehman), soexpl3
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 whenbiblatex
development started (according to the changelog inbiblatex.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 towardsexpl3
(given the state of the project back then).
– moewe
Jan 30 at 22:09
... It has been suggested once or twice thatbiblatex
could benefit fromexpl3
, but I'm not sure how good an idea it is to mix the current LaTeX2e base withexpl3
and re-implementing everything inexpl3
seems a huge task.
– moewe
Jan 30 at 22:12
|
show 5 more comments
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}
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}
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 whybiblatex
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 inexpl3
, it uses normal LaTeX2e andetoolbox
(also by Philip Lehman), soexpl3
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 whenbiblatex
development started (according to the changelog inbiblatex.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 towardsexpl3
(given the state of the project back then).
– moewe
Jan 30 at 22:09
... It has been suggested once or twice thatbiblatex
could benefit fromexpl3
, but I'm not sure how good an idea it is to mix the current LaTeX2e base withexpl3
and re-implementing everything inexpl3
seems a huge task.
– moewe
Jan 30 at 22:12
|
show 5 more comments
moewe, a curiosity. Is there a reason whybiblatex
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 inexpl3
, it uses normal LaTeX2e andetoolbox
(also by Philip Lehman), soexpl3
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 whenbiblatex
development started (according to the changelog inbiblatex.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 towardsexpl3
(given the state of the project back then).
– moewe
Jan 30 at 22:09
... It has been suggested once or twice thatbiblatex
could benefit fromexpl3
, but I'm not sure how good an idea it is to mix the current LaTeX2e base withexpl3
and re-implementing everything inexpl3
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
|
show 5 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Related: tex.stackexchange.com/q/346564/35864
– moewe
May 31 '18 at 19:24