如何为不同的条目声明不同的字符串?例如,对于普通的 url,urldate 将被打印为“Accessed: urldate”,而对于 Wikipedia,urldate 将被打印为“Last modified: urldate”。
我尝试了类似 \iffieldequalstr 的方法,但似乎不起作用。下面是一个 MWE
\documentclass{article}
\usepackage[style=ieee,backend=bibtex]{biblatex}
\usepackage{xpatch}
\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
title = {What is {MEMS}?},
organization = {MEMSnet},
url = {http://www.memsnet.org/mems/what_is.html},
urldate = {2013-12-01},
}
@ELECTRONIC{WikiMEMS,
author = {Wikipedia},
title = {Microelectromechanical systems},
organization = {Wikipedia.org},
url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
timestamp = {09:59},
urldate = {28 November 2013}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\xpatchbibdriver{online}
{\printtext[parens]{\usebibmacro{date}}}
{\iffieldundef{year}
{}
{\printtext[parens]{\usebibmacro{date}}}}
{}
{\typeout{There was an error patching biblatex-ieee (ieee.bbx's @online driver)}}
\AtEveryBibitem{
\ifentrytype{online}{
\iffieldequalstr{author}{Wikipedia}{
\DefineBibliographyStrings{english}{%
urlseen = {Last modified}
}
\DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1\addcomma\space\printfield{timestamp}}}
}{
\DefineBibliographyStrings{english}{%
urlseen = {Accessed}
}
\DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1}}
}
}{}
}
\begin{document}
\nocite{MEMSnet,WikiMEMS,wilde,markey}
\printbibliography
\end{document}
答案1
一个非常接近您想要的解决方案是执行以下操作,通过以下方式声明一个新的bibstring
,恰当命名的lastmodified
\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
lastmodified = {last modified}
}
为了能够比较名称,author
我们需要一个宏\wikitestname
。不幸的是,目前还没有简单的方法来检查名称*与字符串是否一致,所以我们需要使用\ifnameequals
宏来检查;名称格式非常具体,但是您可以在文件中查找它.bbl
。
\def\wikitestname{{}{{{}{Wikipedia}{W.}{}{}{}{}{}{}}}}
然后我们检查当前处理的条目是否是 Wiki 条目
\AtEveryBibitem{
\ifentrytype{online}{
\ifnameequals{author}{\wikitestname}
{\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{lastmodified}\space#1}}}
{\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\space#1}}}
}
}
urldate
并根据需要更改前面的字符串。
\documentclass{article}
\usepackage[style=ieee,backend=bibtex]{biblatex}
\usepackage{xpatch}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
title = {What is {MEMS}?},
organization = {MEMSnet},
url = {http://www.memsnet.org/mems/what_is.html},
urldate = {2013-12-01},
}
@ELECTRONIC{WikiMEMS,
author = {Wikipedia},
title = {Microelectromechanical systems},
organization = {Wikipedia.org},
url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
timestamp = {09:59},
date = {2013-11-28},
urldate = {2013-12-25},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\xpatchbibdriver{online}
{\printtext[parens]{\usebibmacro{date}}}
{\iffieldundef{year}
{}
{\printtext[parens]{\usebibmacro{date}}}}
{}
{\typeout{There was an error patching biblatex-ieee (ieee.bbx's @online driver)}}
\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
lastmodified = {last modified}
}
\def\wikitestname{{}{{{}{Wikipedia}{W.}{}{}{}{}{}{}}}}
\AtEveryBibitem{
\ifentrytype{online}{
\ifnameequals{author}{\wikitestname}
{\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{lastmodified}\space#1}}}
{\DeclareFieldFormat{urldate}{\mkbibparens{\bibstring{urlseen}\space#1}}}
}
}
\begin{document}
\nocite{MEMSnet,WikiMEMS,wilde,markey}
\printbibliography
\end{document}
*
biblatex
区分name
s、field
s 和list
s。例如,author
是 a name
、series
afield
和organization
a list
。有不同的宏来检查这些字段之间是否相等。您不能用来\iffieldequalstr
检查 a 是否name
等于给定的字符串。由于名称可以说是biblatex
必须处理的最复杂的部分,因此它们也具有最复杂的身份条件。毕竟,人们不希望文件中给出的名称.bib
与Peter Smith
字符串匹配Smith
,但您希望Peter Smith
和都Smith, Peter
匹配,Peter Smith
因为这两种输入格式在文件中同样有效.bib
。因此,biblatex
只接受与应该已经包含.bbl
文件中给出的正确名称语法的宏进行比较。在我们的例子中{}{{{}{Wikipedia}{W.}{}{}{}{}{}{}}}
。
换个角度来说,在这种情况下,为这个任务定义一个专用的条目类型(有人可能会称之为@wiki
)可能非常合适。
由于您似乎使用 BibTeX 作为后端而不是(至少在我看来)更优越的 biber,让我们首先探索使用 BibTeX 的可能性,然后继续看看我们可以用 biber 做得更好。
biblatex
默认情况下,有六种用于自定义修改的条目类型:这些是customa
。customf
这里我们将使用customa
。
从现在开始,如果您想引用 wiki 条目,请不要使用@online
/ @electronic
,而是使用@customa
。
@customa{WikiMEMS,
author = {Wikipedia},
title = {Microelectromechanical systems},
url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
organization = {Wikipedia, The Free Encyclopedia},
date = {2013-11-28},
urldate = {2013-12-25},
}
这些字段与预期一致;请注意,正如人们所期望的那样,它urldate
采用资源上次访问的日期和date
资源上次修改的日期。
我们再次
\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
lastmodified = {last modified}
}
最后我们有了驱动程序,即打印参考书目条目的代码片段
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
\iffieldundef{year}%
{}
{\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
\setunit{\adddot\addspace}%
\usebibmacro{title}%
\setunit{\adddot\addspace}%
\printlist{language}%
\setunit{\adddot\addspace}%
\usebibmacro{byauthor}%
\setunit{\adddot\addspace}%
\usebibmacro{byeditor+others}%
\setunit{\adddot\addspace}%
\printfield{version}%
\setunit{\adddot\addspace}%
\printfield{note}%
\newunit\newblock
\printlist{organization}%
\setunit{\adddot\addspace}%
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock
\usebibmacro{url+urldate}%
\setunit{\adddot\addspace}%
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}%
}
ieee.bbx
此驱动程序几乎是驱动程序的一比一副本,除了在打印“上次修改”的区域@online
稍作修改外。date
平均能量损失
\documentclass{article}
\usepackage[style=ieee,backend=bibtex]{biblatex}
\usepackage{xpatch}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
title = {What is {MEMS}?},
organization = {MEMSnet},
url = {http://www.memsnet.org/mems/what_is.html},
urldate = {2013-12-01},
}
@customa{WikiMEMS,
author = {Wikipedia},
title = {Microelectromechanical systems},
url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
organization = {Wikipedia, The Free Encyclopedia},
date = {2013-11-28},
urldate = {2013-12-25},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\xpatchbibdriver{online}
{\printtext[parens]{\usebibmacro{date}}}
{\iffieldundef{year}
{}
{\printtext[parens]{\usebibmacro{date}}}}
{}
{\typeout{There was an error patching biblatex-ieee (ieee.bbx's @online driver)}}
\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
lastmodified = {last modified}
}
\DeclareBibliographyDriver{customa}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
\iffieldundef{year}%
{}
{\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
\setunit{\adddot\addspace}%
\usebibmacro{title}%
\setunit{\adddot\addspace}%
\printlist{language}%
\setunit{\adddot\addspace}%
\usebibmacro{byauthor}%
\setunit{\adddot\addspace}%
\usebibmacro{byeditor+others}%
\setunit{\adddot\addspace}%
\printfield{version}%
\setunit{\adddot\addspace}%
\printfield{note}%
\newunit\newblock
\printlist{organization}%
\setunit{\adddot\addspace}%
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock
\usebibmacro{url+urldate}%
\setunit{\adddot\addspace}%
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}%
}
\begin{document}
\nocite{MEMSnet,WikiMEMS,wilde,markey}
\printbibliography
\end{document}
我们可以通过像上面那样定义驱动程序来biber
定义一个新类型@wiki
wiki
\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
lastmodified = {last modified}
}
\DeclareBibliographyDriver{wiki}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
\iffieldundef{year}%
{}
{\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
\setunit{\adddot\addspace}%
\usebibmacro{title}%
\setunit{\adddot\addspace}%
\printlist{language}%
\setunit{\adddot\addspace}%
\usebibmacro{byauthor}%
\setunit{\adddot\addspace}%
\usebibmacro{byeditor+others}%
\setunit{\adddot\addspace}%
\printfield{version}%
\setunit{\adddot\addspace}%
\printfield{note}%
\newunit\newblock
\printlist{organization}%
\setunit{\adddot\addspace}%
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock
\usebibmacro{url+urldate}%
\setunit{\adddot\addspace}%
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}%
}
文件.bib
符合预期
@wiki{WikiMEMS,
author = {Wikipedia},
title = {Microelectromechanical systems},
url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
organization = {Wikipedia, The Free Encyclopedia},
date = {2013-11-28},
urldate = {2013-12-25},
}
数学家协会
\documentclass{article}
\usepackage[style=ieee,backend=biber]{biblatex}
\usepackage{xpatch}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
title = {What is {MEMS}?},
organization = {MEMSnet},
url = {http://www.memsnet.org/mems/what_is.html},
urldate = {2013-12-01},
}
@wiki{WikiMEMS,
author = {Wikipedia},
title = {Microelectromechanical systems},
url = {http://en.wikipedia.org/wiki/Microelectromechanical_systems},
organization = {Wikipedia, The Free Encyclopedia},
date = {2013-11-28},
urldate = {2013-12-25},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\xpatchbibdriver{online}
{\printtext[parens]{\usebibmacro{date}}}
{\iffieldundef{year}
{}
{\printtext[parens]{\usebibmacro{date}}}}
{}
{\typeout{There was an error patching biblatex-ieee (ieee.bbx's @online driver)}}
\NewBibliographyString{lastmodified}
\DefineBibliographyStrings{english}{%
lastmodified = {last modified}
}
\DeclareBibliographyDriver{wiki}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\addperiod\addspace}%or \setunit{\adddot\addspace}
\iffieldundef{year}%
{}
{\printtext[parens]{\bibstring{lastmodified}\space\usebibmacro{date}}}%
\setunit{\adddot\addspace}%
\usebibmacro{title}%
\setunit{\adddot\addspace}%
\printlist{language}%
\setunit{\adddot\addspace}%
\usebibmacro{byauthor}%
\setunit{\adddot\addspace}%
\usebibmacro{byeditor+others}%
\setunit{\adddot\addspace}%
\printfield{version}%
\setunit{\adddot\addspace}%
\printfield{note}%
\newunit\newblock
\printlist{organization}%
\setunit{\adddot\addspace}%
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock
\usebibmacro{url+urldate}%
\setunit{\adddot\addspace}%
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}%
}
\begin{document}
\nocite{MEMSnet,WikiMEMS,wilde,markey}
\printbibliography
\end{document}
以上两个 MWE 均产生
使用 biber,现在可以非常轻松地添加自定义字段;例如,许可证字段,描述条目的使用条款@wiki
。这可以按照如何在参考书目中包含价格?。