我正在尝试将参考书目样式与 相匹配biblatex-philosophy
。在线资源的格式如下:
有作者的在线作品: 没作者的在线作品(为简单起见,详细信息相同):
默认情况下,使用此代码(已对格式进行了一些调整):
\documentclass[11pt, parskip=false]{scrartcl}
% Bibliography preamble
\usepackage[giveninits=true, style=philosophy-modern, yearleft=true, dateabbrev=false]{biblatex}
\addbibresource{testbib.bib}
\DeclareFieldFormat[online]{title}{#1}
\renewcommand{\postsep}{% Add comma to end of author section
\addcomma
\null\par\nobreak\vskip\postnamesep%
\hskip-\bibhang\ignorespaces}
\DeclareFieldFormat{urldate}{% Reformats urldate field to read "accessed", replacing "(visted on)"
accessed %
\thefield{urlday}\addspace
\mkbibmonth{\thefield{urlmonth}}\addspace%
\thefield{urlyear}\isdot}
\renewbibmacro*{url+urldate}{% Makes URL begin on a new line, adds comma after URL, before URLdate
\printunit{\newline}\usebibmacro{url}%
\iffieldundef{urlyear}
{}
{\setunit*{\addcomma\addspace}%
\usebibmacro{urldate}}}
\begin{document}
Sentence containing citation \parencite{blogWithoutAuthor, blogWithAuthor}.
\printbibliography
\end{document}
使用此.bib
文件:
@online{blogWithoutAuthor,
date = {2018},
title = {Historians in the News},
maintitle = {History Matters},
organization = {The University of Sydney},
url = {http://blogs.usyd.edu.au/historymatters/2018/02/historians_in_the_news_2018.html},
urldate = {2018-02-23}
}
@online{blogWithAuthor,
date = {2018},
title = {Historians in the News},
maintitle = {History Matters},
organization = {The University of Sydney},
url = {http://blogs.usyd.edu.au/historymatters/2018/02/historians_in_the_news_2018.html},
urldate = {2018-02-23},
author = {McDonnell, Mike}
}
输出内容:
如您所见,没有网站标题(除了页面标题),并且philosophy-modern
当作者不存在时,默认设置会用标题替换作者。
我在上面添加了以下代码,以使字段“maintitle”(作为网站标题)可以被 bibdriver 识别online
,并完全删除作者字段:
\usepackage{xpatch}% Modifies online bibdriver to remove author field, and add maintitle field after title
\xpatchbibdriver{online}
{\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}}
{\usebibmacro{date+extradate}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}%
\newunit\newblock
\usebibmacro{maintitle}%
\newunit}
{}
{\typeout{failed to remove author field, add maintitle field to driver for 'online'}}
输出如下内容:
很好,但显然我已经从运行中删除了作者宏,即使指定了一个作者,我也得不到任何作者。
我的问题是,如何有条件地运行xpatch
上述代码片段,仅当作者缺席(未定义?)时,以匹配所需的格式?
我还只是在理解xpatch
命令,所以我怀疑我的尝试是否是最佳的。请告诉我如何改进代码。
答案1
我想我明白你的意思了。但是,无论如何,处理方式不是“有条件地执行修补”,而是“执行包含条件的修补”。
如果我理解正确的话,这应该可以工作(请注意,考虑到所讨论的宏,我正在测试是否存在“作者”、“编辑”或“翻译”):
\documentclass[11pt, parskip=false]{scrartcl}
% Bibliography preamble
\usepackage[giveninits=true, style=philosophy-modern, yearleft=true, dateabbrev=false]{biblatex}
\addbibresource{testbib.bib}
\DeclareFieldFormat[online]{title}{#1}
\renewcommand{\postsep}{% Add comma to end of author section
\addcomma
\null\par\nobreak\vskip\postnamesep%
\hskip-\bibhang\ignorespaces}
\DeclareFieldFormat{urldate}{% Reformats urldate field to read "accessed", replacing "(visted on)"
accessed %
\thefield{urlday}\addspace
\mkbibmonth{\thefield{urlmonth}}\addspace%
\thefield{urlyear}\isdot}
\renewbibmacro*{url+urldate}{% Makes URL begin on a new line, adds comma after URL, before URLdate
\printunit{\newline}\usebibmacro{url}%
\iffieldundef{urlyear}
{}
{\setunit*{\addcomma\addspace}%
\usebibmacro{urldate}}}
\usepackage{xpatch}% Modifies online bibdriver to remove author field, and add maintitle field after title
\xpatchbibdriver{online}
{\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}}
{\ifboolexpr{
test {\ifnameundef{author}}
and
test {\ifnameundef{editor}}
and
test {\ifnameundef{translator}}
}
{\usebibmacro{date+extradate}}
{\usebibmacro{author/editor+others/translator+others}}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}%
\newunit\newblock
\usebibmacro{maintitle}%
\newunit}
{}
{\typeout{failed to remove author field, add maintitle field to driver for 'online'}}
\begin{document}
Sentence containing citation \parencite{blogWithoutAuthor, blogWithAuthor}.
\printbibliography
\end{document}
答案2
author
标题在、editor
和宏中用作后备translation
,这样在没有给出名称的情况下,您就不会得到空的“名称标题”。
现在,如果没有名称,您可以抑制名称打印宏的执行,如 gusbrs 的答案所示。但我更喜欢另一种方法:告诉名称打印宏,如果没有名称,不要依赖标题。这可以通过重新定义和bibmacrosauthor
来实现。bbx:editor
bbx:translator
\documentclass[australian, 11pt, parskip=false]{scrartcl}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[giveninits=true, style=philosophy-modern, yearleft=true, dateabbrev=false, urldate=comp, uniquename=init]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{blogWithoutAuthor,
date = {2018},
title = {Historians in the News},
maintitle = {History Matters},
organization = {The University of Sydney},
url = {http://blogs.usyd.edu.au/historymatters/2018/02/historians_in_the_news_2018.html},
urldate = {2018-02-23}
}
@online{blogWithAuthor,
date = {2018},
title = {Historians in the News},
maintitle = {History Matters},
organization = {The University of Sydney},
url = {http://blogs.usyd.edu.au/historymatters/2018/02/historians_in_the_news_2018.html},
urldate = {2018-02-23},
author = {McDonnell, Mike}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\DeclareFieldFormat[online]{title}{#1}
\renewcommand{\postsep}{%
\addcomma
\null\par\nobreak\vskip\postnamesep
\hskip-\bibhang\ignorespaces}
\DefineBibliographyStrings{english}{
urlseen = {accessed},
}
\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space#1}
\renewbibmacro*{url+urldate}{%
\printunit{\newline}\newblock
\usebibmacro{url}%
\iffieldundef{urlyear}
{}
{\setunit*{\addcomma\addspace}%
\usebibmacro{urldate}}}
\makeatletter
\DeclareDelimFormat[bib,biblist]{nametitledelim}{\addcomma\space}
\renewbibmacro*{author}{%
\ifboolexpr{
test \ifuseauthor
and
not test {\ifnameundef{author}}
}
{\usebibmacro{bbx:dashcheck}
{}%
{\usebibmacro{bbx:savehash}%
\printnames{author}%
\iffieldundef{nameaddon}
{}%
{\setunit{\addspace}%
\printfield{nameaddon}}%
\postsep}%
\usebibmacro{date+extradate}%
\iffieldundef{authortype}
{}%
{\usebibmacro{authorstrg}%
\printtext{\printdelim{nametitledelim}}}}%
{\global\undef\bbx@lasthash
\usebibmacro{date+extradate}}}
\renewbibmacro*{bbx:editor}[1]{%
\ifboolexpr{%
test \ifuseeditor
and
not test {\ifnameundef{editor}}
}%
{\usebibmacro{bbx:dashcheck}%
{}%
{\printnames{editor}%
\postsep%
\usebibmacro{bbx:savehash}}%
\usebibmacro{date+extradate}%
\usebibmacro{#1}%
\clearname{editor}%
\printtext{\printdelim{nametitledelim}}}%
{\global\undef\bbx@lasthash
\usebibmacro{date+extradate}}}%
\renewbibmacro*{bbx:translator}[1]{%
\ifboolexpr{%
test \ifusetranslator
and
not test {\ifnameundef{translator}}
}%
{\usebibmacro{bbx:dashcheck}%
{}%
{\printnames{translator}%
\postsep%
\usebibmacro{bbx:savehash}}%
\usebibmacro{date+extradate}%
\usebibmacro{#1}%
\clearname{translator}%
\printtext{\printdelim{nametitledelim}}}%
{\global\undef\bbx@lasthash
\usebibmacro{date+extradate}}}%
\makeatother
\usepackage{xpatch}% Modifies online bibdriver to add maintitle field after title
\xpatchbibdriver{online}
{\usebibmacro{title}}
{\usebibmacro{title}%
\newunit\newblock
\usebibmacro{maintitle}}
{}
{\typeout{failed to add maintitle field to driver for 'online'}}
\begin{document}
Sentence containing citation \parencite{blogWithoutAuthor, blogWithAuthor, westfahl:frontier, westfahl:space}.
\printbibliography
\end{document}
babel
请注意我是如何通过全局选项australian
和biblatex
选项获得澳大利亚风格的日期的urldate=comp
。