使用 biblatex 和 Biber,如何创建年份循环,以以下方式逐年打印参考书目:
\section{2016}
\subsection{Article}
\printbibliography of all articles published in 2017
\subsection{inproceedings}
\printbibliography of all papers in proceedings published in 2017
\subsection{in Misc}
\printbibliography of all misc published in 2017
\section{2015}
etc. for all bib entries and all years.
以下是所需结果的示例:https://malti.fr/index.php/publication-list-per-year。
一些进一步的增强可能包括:
- 起始年份自动设置为 bib 文件中较早的输入年份,
- 结束年份自动设置为 bib 文件中最近的输入年份,
- 如果没有发表与给定(子)部分相对应的论文,则该(子)部分就不会出现,(即)没有(子)部分显示为空。
解决了两年之间打印书目的问题这里。 谢谢。
已编辑。以下是借用并修改自的 MWE这里回答@samcarter。
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Article{a,
date = 2001,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{b,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{c,
date = 2004,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{d,
date = 2007,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{e,
date = 2009,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{f,
date = 2011,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{g,
date = 2013,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{h,
date = 2015,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{i,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{l,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@inproceedings{j,
date = 2016,
author = {Author, Amy},
title = {Title 1},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{o,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@patent{m,
year = 2016,
author = {Author, Amy},
title = {Patent 2},
number = 4,
pages = {100-141}}
@Article{n,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
\end{filecontents*}
\usepackage[backend=biber,defernumbers=true,sorting=ydnt]{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=author,match=Amy,final]
\step[fieldset=keywords, fieldvalue={,}, append]
\step[fieldset=keywords, fieldvalue=own, append]
}}}
\defbibcheck{2016}{%There must be a better way to code "different from" 2016
\ifnumless{\thefield{year}}{2016}
{\skipentry}
{\ifnumgreater{\thefield{year}}{2016}
{\skipentry}
{}
}
}
\defbibcheck{2015}{%There must be a better way to code "different from" 2015
\ifnumless{\thefield{year}}{2015}
{\skipentry}
{\ifnumgreater{\thefield{year}}{2015}
{\skipentry}
{}
}
}
\begin{document}
\nocite{*}
\section*{2016}
\printbibliography[check=2016, keyword=own, resetnumbers=true, type=article, heading=subbibliography, title={Articles}]
\printbibliography[check=2016, keyword=own, resetnumbers=true, type=inproceedings, heading=subbibliography, title={Inproceedings}]
\printbibliography[check=2016, keyword=own, resetnumbers=true, type=patent, heading=subbibliography, title={Patent}]
\section*{2015}
\printbibliography[check=2015, keyword=own, resetnumbers=true, type=article, heading=subbibliography, title={Articles}]
\printbibliography[check=2015, keyword=own, resetnumbers=true, type=inproceedings, heading=subbibliography, title={Inproceedings}]
\printbibliography[check=2015, keyword=own, resetnumbers=true, type=patent, heading=subbibliography, title={Patent}]
\end{document}
但是,我得到了带有标题的不想要的输出Inproceedings
,并且Patent
在 2015 年打印了空内容。如果内容为空,我希望没有任何标题。
回到我的请求。如何创建一个从 2016 年到 2001 年的循环,根据类型(文章、会议录、专利、杂项等)逐年打印参考书目?
另一个增强功能是:
- 创建一个内部循环,循环遍历每年的不同类型(文章、诉讼、专利、杂项......)。
已编辑
下面是一个 MWE,其中包含建议的解决方案,但它指出了使用 htlatex/biber/htlatex 时的编译 pb。请参阅下面于 2020 年 2 月 22 日发布的评论。
2020 年 3 月 12 日重新编辑:添加了杂项参考:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Article{b,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@misc{ccc,
date = 2003,
author = {misc, LLL},
title = {MISC},
journaltitle = {Journal-misc},
volume = 10,
number = 4,
pages = {100-141}}
@Article{c,
date = 2003,
author = {Author, BBB},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{d,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{i,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{l,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@inproceedings{j,
date = 2016,
author = {Author, Amy},
title = {Title 1},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{o,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@patent{m,
year = 2016,
author = {Author, Amy},
title = {Patent 2},
number = 4,
pages = {100-141}}
@Article{n,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
\end{filecontents*}
\usepackage[backend=biber,defernumbers=true,sorting=ydnt]{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pertype{article}
\step[fieldset=presort,fieldvalue=article]
}
\map{
\pertype{inproceedings}
\step[fieldset=presort,fieldvalue=inproceedings]
}
\map{
\pertype{patent}
\step[fieldset=presort,fieldvalue=patent]
}
}
}
\DeclareSortingTemplate{rasha}{
\sort[direction=ascending]{
\field{year}}
\sort{\field{presort}}
}
\defbibenvironment{bibliography}
{\begin{enumerate}}
{\end{enumerate}}
{}
\newcounter{myyear}
\setcounter{myyear}{0}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
{\section*{\hspace*{-\leftmargin}\printfield{year}}
\setcounter{myyear}{\thefield{year}}%
\setcounter{enumi}{0}%
\xdef\mylastentrytype{}%
}%
{}%
\iffieldequals{entrytype}{\mylastentrytype}
{}
{ \iffieldequalstr{entrytype}{article}
{\subsection*{\hspace*{-\leftmargin}Journal Articles}}
{ \iffieldequalstr{entrytype}{inproceedings}
{\subsection*{\hspace*{-\leftmargin}Conference Papers}
\setcounter{enumi}{0}%
}
{\iffieldequalstr{entrytype}{patent}
{\subsection*{\hspace*{-\leftmargin}Patents}
\setcounter{enumi}{0}
}
{}
}
}
\xdef\mylastentrytype{\thefield{entrytype}}
}
\item
}
\begin{document}
\nocite{*}
\begin{refcontext}[sorting=rasha]
\printbibliography[title={Publication list by year}]
\end{refcontext}
\end{document}
答案1
这是一个在单个内部循环的解决方案(概念证明)\printbibliography
。
解决方案取决于专门创建的排序模式(这里,我们使用按article
字典顺序排列的在前inproceedings
,按顺序排列的在后patent
)。更强大的方法是定义指定的排序模式(最终是源映射),以便对条目类型进行适当的排序。
此外,为简单起见,该解决方案假设参考书目文件中仅显示article
、inproceedings
和条目(可通过“其他出版物”类别轻松扩展)。patents
第一步是定义排序顺序:
\DeclareSortingScheme{rasha}{
\sort[direction=ascending]{
\field{year}
\field{entrytype}
}
}
然后,我们重新定义bibliography
环境。
\defbibenvironment{bibliography}
{\begin{enumerate}}
{\end{enumerate}}
{}
这里的技巧是\item
从最后一个元素(bib 项上的迭代)中删除。这委托给单个条目。
最后一步是重新定义begentry
宏(在标准书目驱动程序开始时执行)。
\def\mylastentrytype{}
\newcounter{myyear}
\setcounter{myyear}{0}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
{\section*{\hspace*{-\leftmargin}\printfield{year}}
\setcounter{myyear}{\thefield{year}}%
\setcounter{enumi}{0}%
\xdef\mylastentrytype{}%
}%
{}%
\iffieldequals{entrytype}{\mylastentrytype}
{}
{ \iffieldequalstr{entrytype}{article}
{\subsection*{\hspace*{-\leftmargin}Journal Articles}}
{ \iffieldequalstr{entrytype}{inproceedings}
{\subsection*{\hspace*{-\leftmargin}Conference Papers}
\setcounter{enumi}{0}%
}
{\iffieldequalstr{entrytype}{patent}
{\subsection*{\hspace*{-\leftmargin}Patents}
\setcounter{enumi}{0}
}
{}
}
}
\xdef\mylastentrytype{\thefield{entrytype}}
}
\item
}
假设排序模式用作year
第一个参数,初始条件检查年份是否有增量,如果是,则发出一个\section
命令,并将年份的计数器设置为最后处理的条目的年份。
排序模式的第二个参数是entrytype
条目的。因此,我们必须检查当前条目是否与前一个条目的类型相同(存储在中\mylastentrytype
)。如果不是,我们检查条目类型是否是article
、inproceedings
或之一patent
。如果是,则打印相应的部分(重置枚举的计数器)
最后,我们必须指导使用排序方案。
\nocite{*}
\begin{refcontext}[sorting=rasha]
\printbibliography[title={Publication list by year}]
\end{refcontext}
使用 MWE 中给出的参考书目,将产生以下输出(双列格式)
编辑显然\sort{\field{entrytype}}
在排序阶段无法识别。因此,另一种方法是声明一个源映射以presort
使用\pertype
规范填充字段,即:
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pertype{article}
\step[fieldset=presort,fieldvalue=article]
}
\map{
\pertype{inproceedings}
\step[fieldset=presort,fieldvalue=inproceedings]
}
\map{
\pertype{patent}
\step[fieldset=presort,fieldvalue=patent]
}
}
}
并将排序模板(注意\DeclareSortingSchema
现已弃用)更改为
\DeclareSortingTemplate{rasha}{
\sort[direction=ascending]{
\field{year}}
\sort{\field{presort}}
}
经过扩展的 MWE 的输出为: