这是我目前拥有的系统:
\defbibcheck{yr2016}{
\iffieldint{year}
{\ifnumequal{\thefield{year}}{2016}
{\skipentry}
{}}
{\skipentry}
}
这应该排除除 2016 年条目之外的任何内容。然后我将它用于:
\printbibliography[check=yr2016]
我想知道是否可以为我想列出的年份范围创建变量,这样我就可以在需要时更改范围。我想在序言中做一些事情,例如:
\defbibcheck{{year-init},{year-final}}{
\iffieldint{year}
{\ifnumrange{\thefield{year}}{{year-init},{year-final}}
{\skipentry}
{}}
{\skipentry}
}
然后在文档中添加:
\printbibliography[check={year-init}={2012},{year-final}={2015}]
所以如果我想将范围更改为:
\printbibliography[check={year-init}={2012},{year-final}={2018}]
我不需要改变或者更新序言中的代码。
答案1
Bibchecks 并非设计用于接受参数,更不能以任意格式接受参数。您可以通过在 bibcheck 定义中使用占位符宏并在应用检查之前使用第二个宏设置这些占位符来解决此限制。
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, backend=biber]{biblatex}
\makeatletter
\def\mblx@yearfrom{-1000}
\def\mblx@yearto{3000}
\newrobustcmd*{\setcheckfromtorange}[2]{%
\def\mblx@yearfrom{#1}%
\def\mblx@yearto{#2}%
}
\defbibcheck{fromto}{%
\iffieldint{year}
{\ifnumless{\thefield{year}}{\mblx@yearfrom}
{\skipentry}
{\ifnumgreater{\thefield{year}}{\mblx@yearto}
{\skipentry}
{}}}
{\skipentry}}
\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby0,
author = {Humphrey Appleby},
title = {On the Importance of the Civil Service},
date = {1980},
}
@book{appleby1,
author = {Humphrey Appleby},
title = {On the Ablative in Greek},
date = {1981},
}
@book{appleby2,
author = {Humphrey Appleby},
title = {On Honours},
date = {1982},
}
@book{appleby3,
author = {Humphrey Appleby},
title = {Theory on Brontosauruses},
date = {1983},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\nocite{*}
\begin{document}
\printbibliography[check=fromto,title={All}]
\setcheckfromtorange{1981}{1982}
\printbibliography[check=fromto,title={1981--1982}]
\end{document}
请记住,fromto
设置不会自动重置,它们是简单的本地分配。