Biblatex:按类型显示参考书目组,同时按年份降序排序

Biblatex:按类型显示参考书目组,同时按年份降序排序

我正在尝试制作我的简历,并希望使用 Biblatex 建立参考书目。在简历中,我有不同的部分列出我出版的书籍和期刊文章,而在每个部分中,我希望按年份从最近的年份开始对所有项目进行排序。

我可以按照@moewe 的回答按年份降序对条目进行排序:https://tex.stackexchange.com/a/434393/173148。然而,当按章节打印书目时,会显示所有出版的年份,而不是仅显示当前章节的年份。

编辑:此外,由于这是简历中的内容,我需要在不同的地方打印不同类型的参考书目,而不是一次全部打印出来。

示例图片

我用来产生此结果的代码:

\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}

答案1

\g__blxbibbyyear_yearlist_seq代码需要进行一些修改才能按类型进行划分。基本上,我们需要一个列表来收集出版年份( ),而不是一个列表来收集出版年份( ),每个类型都需要一个列表( ,以及一个类型列表)。代码的总体思路可以保留,大多数内容都可以从/类型参数g__bblxbibbyyear_yearlist_<type>_seq切换到。Nnc

现在有两个命令。\printbibbytypeyear按类型和年份拆分整个书目。仅按年份\printbibtypebyyear{<type>}拆分类型的条目。<type>

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

\usepackage{xparse}

\ExplSyntaxOn
\seq_new:N \g__blxbibbyyear_typelist_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, cV, cx }


\prg_new_conditional:Npnn \blx_field_if_undef:n #1 { 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:Npnn \blx_field_if_int:n #1 { T, F , TF }
  {
    \iffieldint { #1 } { \prg_return_true: } { \prg_return_false: }
  }
\prg_new_protected_conditional:Npnn \blx_field_if_eq_str:nn #1 #2 { T, F , TF }
  {
    \iffieldequalstr { #1 } { #2 } { \prg_return_true: } { \prg_return_false: }
  }

\AtDataInput
  {
    \seq_if_exist:cF { g__bblxbibbyyear_yearlist_\thefield{entrytype}_seq }
      {
        \seq_new:c { g__bblxbibbyyear_yearlist_\thefield{entrytype}_seq }
        \__blxbibbyyear_seq_gput_right_once:Nx \g__blxbibbyyear_typelist_seq
          { \thefield{entrytype} }
      }  
    \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:cx
                      { g__bblxbibbyyear_yearlist_\thefield{entrytype}_seq }
                      { \thefield{\thefield{labeldatesource}} }
                  }
              }
          }
          {
            \__blxbibbyyear_seq_gput_right_once:cx
              { g__bblxbibbyyear_yearlist_\thefield{entrytype}_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_generate_variant:Nn \blxbibbyyear_seq_sort_descending:N { c }

\cs_new_nopar:Npn \blxbibbyyear_print_yeartypebib:nnn #1 #2 #3 #4
  {
    \defbibcheck{thisyear}
      {
        \blx_field_if_int:nTF { labelyear }
          {
            \int_compare:nNnF { \thefield{labelyear} } = { #2 }
              { \skipentry }
          }
          { \skipentry }
      }
    \printbibliography[heading=subbibliography, title=#3, type=#1, check=thisyear, #4]
  }


\DeclareDocumentCommand{\printbibbytypeyear}{O{}}
  {
    \seq_map_inline:Nn \g__blxbibbyyear_typelist_seq
      { 
        \blxbibbyyear_seq_sort_descending:c { g__bblxbibbyyear_yearlist_##1_seq }
        \seq_map_inline:cn { g__bblxbibbyyear_yearlist_##1_seq }
          {
            \blxbibbyyear_print_yeartypebib:nnn { ##1 } { ####1 } { ##1~from~####1 } { #1 }
          }
      }
  }

\DeclareDocumentCommand{\printbibtypebyyear}{O{}m}
  {
    \blxbibbyyear_seq_sort_descending:c { g__bblxbibbyyear_yearlist_#2_seq }
    \seq_map_inline:cn { g__bblxbibbyyear_yearlist_#2_seq }
      {
        \blxbibbyyear_print_yeartypebib:nnn { #2 } { ##1 } { ##1 } { #1 }
      }
  }
\ExplSyntaxOff


\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{book1,
  author = {author1},
  date = {1862},
  title = {Book1},
}
@book{book2,
  author = {author1 and author2},
  date = {1831},
  title = {Book2},
}
@book{book3,
  author = {author1 and author2},
  date = {1842},
  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}
}
@article{article3,
  title={title2},
  author={author2},
  journal={journal2},
  volume={2},
  number={2},
  pages={2},
  year={1842}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

\printbibtypebyyear{book}

\printbibtypebyyear{article}

\printbibbytypeyear
\end{document}

按类型和年份分开书目

相关内容