Biblatex:按年份划分子部分的参考文献列表(降序)

Biblatex:按年份划分子部分的参考文献列表(降序)

我想创建一个从最新到最旧的参考文献列表。

下面的 MWE 给出了一个基本的解决方案:

\documentclass{article}
\usepackage[style=authoryear,sorting=ydnt]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{Rabelais1532,
  author = {Rabelais, Fran\c{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}

不过我想在列表中创建一些部分,每个部分对应一年,如下所示:

\printbibliography[keyword=1885, title=1885]
\printbibliography[keyword=1862, title=1862]
\printbibliography[keyword=1831, title=1831]
\printbibliography[keyword=1532, title=1532]

我试图在序言中定义过滤器,并根据文档biblatex(§3.7.9,第 89 页)进行了修改:

\defbibfilter{1885}{%
    date=1885
}%

并添加以下代码:

\printbibliography[filter=1885, title=1885]

但日志文件表明:

Package biblatex Error: Invalid filter expression.

Package biblatex Error: Filter '1885' not found.

例如,是否可以使用过滤命令,按照年份减少的顺序自动执行该过程?

答案1

我认为如果年份列表可以自动生成就更好了,这样你就不必写\printbibliography[keyword=1885, title=1885]等等了。

您的过滤器的问题是 不是date=1885有效的过滤器表达式。过滤器只能有(not)type(not)subtype和(纯存在) 表达式。对于更复杂的过滤器(not)keyword(not)field您需要bibcheck。事实上,这就是我们下面使用的。bibcheck thisyear检查条目是否可追溯到某一年份。

在这里我使用 LaTeX3 代码轻松地对所有年份的列表进行排序。

\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, Fran\c{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}

四个书目:每年一个

相关内容