I am trying to do my CV and would like to build bibliography using Biblatex. In the CV, I have different sections to list my published books, and journal articles, while in each section I want to sort all items by year starting from the most recent.
I was able to sort the entries by year descending following the answer of @moewe: https://tex.stackexchange.com/a/434393/173148. However, when printing bibliography by sections, the years of all publication were shown instead of only the years for the current section.
Edit: Also, as this is in the CV, I need to print the bibliography for different types at various places, instead of printing out all of them at once.
The code I used to produce this result:
\documentclass{article}
\usepackage[style=authoryear,sorting=ydnt]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{book1,
author = {author1},
date = {1862},
title = {Book1},
}
@book{book2,
author = {author1 and author2},
date = {1831},
title = {Book2},
}
@article{article1,
title={title1},
author={author1 and author2},
journal={journal1},
volume={1},
number={1},
pages={1},
year={1841}
}
@article{article2,
title={title2},
author={author2},
journal={journal2},
volume={2},
number={2},
pages={2},
year={1842}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\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_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
\begin{document}
\section{Books}
\nocite{*}
\printbibbyyear[type=book]
\section{Articles}
\nocite{*}
\printbibbyyear[type=article]
\end{document}