
저는 이력서를 작성하려고 하는데 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
및 유형 목록)에 대해 하나의 목록이 필요합니다. 코드의 전반적인 아이디어는 그대로 유지될 수 있으며 대부분의 항목은 N
/ n
유형 인수에서 c
.
이제 두 가지 명령이 있습니다. \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}