我想确保参考书目中的所有条目都按年份排序。此外,每年都应生成一个单独的标题。整个过程应尽可能自动运行,即我不想手动为每一年创建“键”。我的第一个想法是这样的:
\foreach \year in {2013,...,2018} {\printbibliography[year=\year, title=\year]}
不幸的是,biblatex 没有提供选项year=...
(这将是一个不错的功能)。到目前为止,我所取得的成就是,为每一年创建了一个标题,并且所有条目都正确排序在相应的年份下。但是,在没有出版物的年份,错误地创建了一个标题,但标题下没有条目。下面您可以看到我的 MWE。我不明白为什么\printbibliography[check=publicationInThisYear]
“执行”了,即使在当前年份没有引用的情况下检查应该会失败。在循环之外,\printbibliography[type=thesis]
有不同的行为。正如预期的那样,它没有生成条目(而“thesis-bibentry”Bar2017b 被注释掉并且检查失败)。错误在哪里?
\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}
答案1
只需挖掘该网站,我就能烹饪出一些我相信可以满足您要求的东西(尽管从您的问题来看,最终想要的结果并不十分清楚)。
但使用 moewe 的答案Biblatex:按年份划分子部分的参考文献列表(降序)奥黛丽的回答是biblatex:反向编号(即倒数),与适当的 biblatex 选项组合,似乎可以完成工作。
\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}