![在 biblatex 中仅打印之前未打印过的参考文献](https://linux22.com/image/347063/%E5%9C%A8%20biblatex%20%E4%B8%AD%E4%BB%85%E6%89%93%E5%8D%B0%E4%B9%8B%E5%89%8D%E6%9C%AA%E6%89%93%E5%8D%B0%E8%BF%87%E7%9A%84%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE.png)
为一个自然样式文档,我想在章节后打印参考文献,但前提是它们之前没有打印过。我目前使用这种技术:
\documentclass{article}
\usepackage[american,english]{babel}
\usepackage[babel]{csquotes}
\usepackage[style=nature,hyperref,autocite=superscript]{biblatex}
\usepackage{hyperref}
\addbibresource{biblatex-examples.bib}
\begin{document}
\begin{refsegment}
Main text\autocite{angenendt,bertram}.
\end{refsegment}
\printbibliography[heading=bibintoc,segment=1]
Other info\autocite{bertram,gillies}.
\defbibfilter{not_printed_before}{ ( not segment=1 ) and segment=0 }
\printbibliography[heading=none,filter=not_printed_before]
\end{document}
这正确地避免了bertram
第二次打印。但是,如果涉及更多段,这会变得很麻烦。有没有一种自动方法来检查参考文献是否之前已经打印过?
答案1
哦哦。我想我几乎可以做到这一点!请注意,你需要一个refsegment
for all 才能使我打印迄今为止最大段的方法起作用。
\documentclass{article}
\usepackage[style=nature,autocite=superscript]{biblatex}
\addbibresource{biblatex-examples.bib}
\pagestyle{empty}
\makeatletter
\def\blx@skipprinted{}% define a list to hold entries to be skipped
\def\addskipprinted#1{% macro to add an entry to our list
\edef\X{%
\noexpand\iffieldequalstr{entrykey}{#1}
{\noexpand\toggletrue{blx@skipentry}}
{}}%
\expandafter\g@addto@macro\expandafter\blx@skipprinted\expandafter{\X}}
\AtEveryBibitem{\addskipprinted{\thefield{entrykey}}}% add every item to the list
\defbibcheck{skipprinted}{% a check for our list
\blx@skipprinted}
\AtBeginBibliography{%
% run our check in the bibliography
\blx@key@bibcheck{skipprinted}%
% print bibliography for max segment so far
\blx@key@segment{\the\csname blx@maxsegment@\the\c@refsection\endcsname}}
\makeatother
\begin{document}
\begin{refsegment}
Main text\autocite{angenendt,bertram}.
\end{refsegment}
\printbibliography[heading=bibintoc]
\begin{refsegment}
Other info\autocite{bertram,gillies}.
\end{refsegment}
\printbibliography[heading=none]
\begin{refsegment}
Other info\autocite{gillies,glashow}.
\end{refsegment}
\printbibliography[heading=none]
\end{document}