![Biblatex:组合过滤器](https://linux22.com/image/241915/Biblatex%EF%BC%9A%E7%BB%84%E5%90%88%E8%BF%87%E6%BB%A4%E5%99%A8.png)
我在 comp.text.tex 上发布了完全相同的问题
我不知道我是否遗漏了什么,但我认为 biblatex 的以下功能非常棒:Biblatex 提供了定义所谓的参考书目过滤器的可能性。
有没有办法使用类似这样的语法来组合过滤器:
\defbibfilter{myNewFilter}{filter=AnOldFilter and not ( filter=AnotherFilter )}
?[一个更简单的建议] 有没有办法这样说:
\printbibliography[notfilter=MyFilter]
?我知道\printbibliography[filter=...]
并且\printbibliography[nottype=...]
存在,我想知道是否可以实现“notfilter”选项。
答案1
目前尚未实现过滤器组合。要组合过滤器,您必须创建自己的算法。
我想提出一种方法。因此我定义了命令:
\combinetwobibfilter{Arg 1}{Arg 2}{Arg 3}
带有三个强制参数。第一个参数是新过滤器的名称。第二个和第三个参数是两个预定义过滤器的名称。到目前为止,我还没有实施测试来检查过滤器是否已定义。
\setcounter{errorcontextlines}{999}
\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\usepackage{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\DeclareBibliographyCategory{cat1}
\DeclareBibliographyCategory{cat2}
\DeclareBibliographyCategory{cat3}
\addtocategory{cat1}{A01}
\addtocategory{cat2}{B02}
\addtocategory{cat3}{C03}
\makeatletter
\let\defbibfilter@orig\defbibfilter
\renewrobustcmd*{\defbibfilter}[2]{%
\csgdef{save@bibfilter#1}{#2}%
\defbibfilter@orig{#1}{#2}}
\newrobustcmd{\combinetwobibfilter}[3]{%
\csedef{temp@bibfilter}{%
\csuse{save@bibfilter#2}
or
\csuse{save@bibfilter#3}
}%
\defbibfilter{#1}{\csuse{temp@bibfilter}}%
}
\makeatother
\defbibfilter{FilterOne}{category=cat1}
\defbibfilter{FilterTwo}{category=cat2}
\defbibfilter{FilterThree}{category=cat3}
\combinetwobibfilter{FilterFour}{FilterTwo}{FilterThree}
\begin{document}
\cite{A01}\quad\cite{B02}\quad\cite{C03}
\printbibliography[title={No filter}]
\printbibliography[title={Filter One},filter=FilterOne]
\printbibliography[title={Filter Two},filter=FilterTwo]
\printbibliography[title={Filter Four=combination of filter two and filter three},filter=FilterFour]
\end{document}
结果是: