我想要一个书目条目,其中多个项目用圆括号括起来。我有点成功了,但需要微调格式。
首先,这是 MWE:
% xelatex - biber - xelatex - xelatex
\documentclass{article}
\usepackage[style=nature,maxbibnames=99]{biblatex}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% to create a file when first processed
% \begin{filecontents}[<options>]{<filename>}
% possible options: overwrite, nosearch, noheader
\begin{filecontents}{bib_2ndtry.bib}
@misc{A2020,
author = {Author, A. and Author, B. and Author C.},
title = {Title of some conference talk},
eventtitle = {Conference title},
date = {2011},
venue = {Conference location},
}
@misc{B2021,
author = {Buthor, A.},
year = {2021},
title = {Bravo},
}
\end{filecontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addbibresource{bib_2ndtry.bib}
\DeclareBibliographyDriver{misc}{%
\usebibmacro{title}%
\newunit
\printfield{eventtitle}%
\newunit
\mkbibparens{%
\printfield{venue}%
\newunit
\usebibmacro{date}%
}%
\usebibmacro{finentry}%
}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
生成以下文件:
我需要
- 在左括号前添加一个空格
- 删除左括号后的点
- 删除左括号后的空格
- 替换后面的点会议地点用逗号
我有点不知道如何实现这一点,如果能得到任何提示我将非常感激。
答案1
你可能想熟悉biblatex
标点符号缓冲/跟踪功能。它们在手册(第 4.7 条)标点和间距和 §4.11.7使用标点符号追踪器)这个网站上也有一些例子(\setunit 和 \newunit 起什么作用?,biblatex:\DeclareCiteCommand 在 \printfield 和 \printnames 之间添加分号,但只是有时,Biblatex 中的 If 语句,\setunit*{<punct>} 和 \setunit{\add<punct>} 之间有什么区别)。
通常,将标点符号和格式化命令直接放在驱动程序和 bibmacros 中是不好的\mkbibparens
。标点符号最好用标点符号缓冲区来处理。格式化命令最好用\DeclareFieldFormat
和朋友来处理。
通常,您只需要几个\newunit
s/ \setunit
s 就可以了。如果您想在同一个括号内打印多个字段,则需要做更多工作,因为您需要同时检查这些字段是否存在。在您的示例中,我们可以按如下方式执行此操作
\documentclass{article}
\usepackage[style=nature,maxbibnames=99]{biblatex}
\usepackage{hyperref}
\DeclareBibliographyDriver{misc}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{title}%
\newunit
\ifboolexpr{
test {\iffieldundef{venue}}
and
test {\iffieldundef{year}}
}
{}
{\printtext[parens]{%
\printfield{venue}%
\setunit*{\addcomma\space}%
\printdate}}%
\usebibmacro{finentry}%
}
\begin{filecontents}{\jobname.bib}
@misc{A2020,
author = {Author, A. and Author, B. and Author C.},
title = {Title of some conference talk},
eventtitle = {Conference title},
date = {2011},
venue = {Conference location},
}
@misc{B2021,
author = {Buthor, A.},
year = {2021},
title = {Bravo},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
请注意,标准biblatex
有一个名为的宏event+venue+date
定义为(standard.bbx
,第 3.18 版第 828-843 行)
\newbibmacro*{event+venue+date}{%
\printfield{eventtitle}%
\newunit
\printfield{eventtitleaddon}%
\ifboolexpr{
test {\iffieldundef{venue}}
and
test {\iffieldundef{eventyear}}
}
{}
{\setunit{\addspace}%
\printtext[parens]{%
\printfield{venue}%
\setunit*{\addcomma\space}%
\printeventdate}}%
\newunit}
它将打印几乎与我们打印的信息相同,只是它使用eventdate
而不是date
。但是,此宏丢失了biblatex-nature
(nature.bbx
,v1.3d 中的第 152-166 行)。
答案2
好的,我几乎成功了,使用以下方法:
\DeclareBibliographyDriver{misc}{%
\usebibmacro{title}%
\printfield{eventtitle}%
\setunit{\space}
\mkbibparens{%
\setunit{}%
\printfield{venue}%
\printunit{\addcomma\addspace}%
\usebibmacro{date}%
}%
\usebibmacro{finentry}%
}
由此得出以下参考书目:
如您所见,第一项没有问题。但是,第二项存在一些问题:如果venue
是空的,则存在不需要的空格,我需要以某种方式将其删除...有什么想法吗?
更新:
读了一些资料后,我发现有一种方法可以检查某个项目是否存在。因此,我将上面列出的代码更改为如下形式:
\DeclareBibliographyDriver{misc}{%
\usebibmacro{title}%
\printfield{eventtitle}%
\setunit{\space}
\mkbibparens{%
\setunit{}%
\iffieldundef{venue}{%
\usebibmacro{date}%
}{%
\printfield{venue}%
\printunit{\addcomma\addspace}%
\usebibmacro{date}%
}%
}%
\usebibmacro{finentry}%
}
现在不需要的空白消失了。但是,我不确定我的方法/解决方案有多好...