我定义了一个条目集,并使用命令\clearfield
删除了条目中的月份。它适用于普通条目,但在条目集中仍显示月份。如何删除条目集中条目的月份字段?
梅威瑟:
\documentclass[10pt]{article}
\usepackage[hyperref,backend=biber, maxnames=2,style=nature,%
articletitle=false,
isbn=false]{biblatex}
\AtEveryBibitem{\clearfield{month}}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{key1,
author = {Author, A.},
year = {2001},
month = {3},
title = {Title},
publisher = {Publisher},
}
@article{key2,
author = {Author, B.},
year = {2002},
month = {2},
title = {Title},
publisher = {Publisher},
}
@article{key3,
author = {Author, C.},
year = {2003},
month = {1},
title = {Title},
publisher = {Publisher},
}
\end{filecontents}
\begin{document}
\defbibentryset{set1}{key1,key2}
\cite{set1}
\cite{key3}
\printbibliography
\end{document}
答案1
您可以改用源映射:
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldset=month,null]
}
}
}
在全:
\documentclass[10pt]{article}
\usepackage[hyperref,backend=biber,maxnames=2,style=nature,articletitle=false,
isbn=false]{biblatex}
\usepackage{hyperref}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{key1,
author = {Author, A.},
year = {2001},
month = {3},
title = {Title},
publisher = {Publisher},
}
@article{key2,
author = {Author, B.},
year = {2002},
month = {2},
title = {Title},
publisher = {Publisher},
}
@article{key3,
author = {Author, C.},
year = {2003},
month = {1},
title = {Title},
publisher = {Publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldset=month,null]
}
}
}
\begin{document}
\defbibentryset{set1}{key1,key2}
\cite{set1}
\cite{key3}
\printbibliography
\end{document}
答案2
gusbrs 已经给出了更可取的答案,所以让我解释一下导致这种行为的原因,并提供一个替代的(但较差的)解决方案。源映射解决方案是可取的,因为它在到达之前就删除了字段信息biblatex
,而\clearfield
Biber 会读取和处理字段,并且只在最后一刻打印时抑制字段。如果清除的字段与排序、唯一性、标签...字段解析或其他高级功能相关,这可能会导致输出差异。如果使用源映射,则在任何上述函数启动之前都会有效地删除该字段,但是如果您使用\clearfield
这些函数,则所有函数都会尊重并根据字段的存在采取行动。该month
字段可用于排序,在这种情况下,至关重要的是 Biber 会将其删除,以便文档不会随机对同一年的条目进行排序。另一个示例是,如果不存在其他日期,则urldate
可以将其用作后备,如果您想抑制它,它不应该凭借作为的来源潜入您的参考书目,这只能通过在源映射中删除该字段来防止。labeldate
urldate
labeldate
请看以下示例。正如您所看到的,红色 X 的存在\AtEveryBibitem
会在参考书目中每个项目的开头执行一次,此时标记为灰色的条目键处于范围内并正在处理中。特别是,红色 X 不会对集合的所有成员重复出现。
您将会看到,对于集合,范围内的条目是set1
,因此如果在那里发出,则只会删除元条目的\clearfield{month}
(已经不存在的)字段,而不是其元素。month
set1
集合由特殊驱动程序@set
和命令处理\entryset
。\entryset
通过调用各自的驱动程序,循环对集合成员进行排版。我们可以将 添加\clearfield{month}
到预代码中\entryset
,以删除集合成员的月份。在正确的范围内(参见黄色 Y 后的蓝色输入键),对每个集合成员(参见下面的黄色 Y)执行一次预代码。
对于条目,我们可以观察到类似的效果related
:在\AtEveryBibitem
对主条目执行时,所有related
条目都不会受到影响。
\documentclass[10pt]{article}
\usepackage{xcolor}
\usepackage[backend=biber, maxnames=2,style=nature, articletitle=false, isbn=false]{biblatex}
\AtEveryBibitem{%
\textcolor{red}{X}% only for demonstration
\textcolor{gray}{\thefield{entrykey}}% only for demonstration
\clearfield{month}}
\DeclareBibliographyDriver{set}{%
\entryset
{\clearfield{month}%
\textcolor{yellow}{Y}% for illustrative purposes only
\textcolor{gray}{\thefield{entrykey}}% for illustrative purposes only
\ifbool{bbx:subentry}
{\printfield[bibentrysetcount]{entrysetcount}%
\printunit*{\addnbspace}}
{}}
{}%
\newunit\newblock
\usebibmacro{setpageref}%
\finentry}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{key1,
author = {Author, A.},
year = {2001},
month = {3},
title = {Title},
publisher = {Publisher},
}
@article{key2,
author = {Author, B.},
year = {2002},
month = {2},
title = {Title},
publisher = {Publisher},
}
@article{key3,
author = {Author, C.},
year = {2003},
month = {1},
title = {Title},
publisher = {Publisher},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\defbibentryset{set1}{key1,key2}
\cite{set1}
\cite{key3}
\printbibliography
\end{document}