biblatex:如何向主样式添加例外?

biblatex:如何向主样式添加例外?

我正在使用@moewe 编写的优秀模板biblatex:如何匹配金融期刊书目样式?

不幸的是,我刚刚注意到工作稿techreports)需要与常规文章有一点不同的风格。

具体来说,他们应该遵循所有的常规文章的惯例(已在 moewe 的脚本中指定)除了 techreports 的标题不应该用斜体。

以下是一个例子(只需将这两个 bib 项目与模板一起使用):

@article{johndoe_article,
  title={good morning everyone},
  author={Doe, John},
  journal={Journal of Stackoverlow},
  volume={13},
  number={1},
  pages={27--61},
  year={2014},
}


@techreport{johndoe_techreport,
title = {good morning everyone},
author = {Dow, John},
year = {2017},
institution = {Stackoverflow University},
type = {working paper},
}

给出:

在此处输入图片描述

如你看到的

  • 技术报告title是斜体,而不是正常
  • , (工作title论文type)和institution(stackoverflow university)用逗号分隔,.而不是逗号,

我该如何调整代码来获得这两个小变化techreports?谢谢!

答案1

条目类型techreport是类型的别名report。因此,您需要的正确字段格式命令是:

\DeclareFieldFormat[report]{title}{#1}

为了用逗号分隔元素,您需要修补类型的书目驱动程序report。我使用xpatch包来做到这一点。该xpatch包提供了专门用于更改biblatex宏的各种命令,包括类型\bibmacro\BibliographyDriver类型(以及其他)。对于这个解决方案,我找到了类型的书目驱动程序的位置report(在standard.bbx,大多数加载的核心代码.bbx),然后使用该\xpatchbibdriver命令。

该命令的语法如下:

\xpatchbibdriver{<driver name>}{<search code>}{<replace code}{<success>}{<failure>}

在这种情况下,需要做的是\addcomma\addspace 在打印之前将标点符号设置为type字段之前将标点符号设置为institution

这是一个完整的例子:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{johndoe_article,
  title={good morning everyone},
  author={Doe, John},
  journal={Journal of Stackoverlow},
  volume={13},
  number={1},
  pages={27--61},
  year={2014},
}


@techreport{johndoe_techreport,
title = {good morning everyone},
author = {Dow, John},
year = {2017},
institution = {Stackoverflow University},
type = {working paper},
}
\end{filecontents}
\usepackage[style=authoryear, 
backend=biber, 
giveninits=true,
uniquelist = false, 
uniquename=init,
isbn=false, 
maxcitenames=3, 
maxbibnames=999,
doi=false,
url=false]{biblatex}

\usepackage{xpatch}
\addbibresource{\jobname.bib}

\DeclareDelimFormat{nameyeardelim}{\addcomma\space}

%\setlength{\bibhang}{0pt}

\DeclareNameAlias{sortname}{family-given}

\renewcommand*{\labelnamepunct}{\addspace}


\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,thesis,unpublished,report]
  {title}{#1}

\DeclareFieldFormat{titlecase}{\MakeSentenceCase*{#1}}


\renewbibmacro*{in:}{%
  \ifentrytype{article}
    {\setunit{\addcomma\space}}
    {\printtext{\bibstring{in}\intitlepunct}}}

\DeclareFieldFormat{journaltitlecase}{#1}

\renewbibmacro*{journal}{%
  \ifboolexpr{
    test {\iffieldundef{journaltitle}}
    and
    test {\iffieldundef{journalsubtitle}}
  }
    {}
    {\printtext[journaltitle]{%
       \printfield[journaltitlecase]{journaltitle}%
       \setunit{\subtitlepunct}%
       \printfield[journaltitlecase]{journalsubtitle}}}}

\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit{\addcomma\space}%
  \printfield{eid}}


\xpatchbibdriver{report}{\newunit\newblock\printfield{type}}
    {\setunit{\addcomma\addspace}\newblock\printfield{type}}{}{}
\xpatchbibdriver{report}{\newunit\newblock\usebibmacro{institution+location+date}}
    {\setunit{\addcomma\addspace}\newblock\usebibmacro{institution+location+date}}{}{}

\DeclareFieldFormat[article,periodical]{volume}{\mkbibbold{#1}}% volume of a journal

\DeclareFieldFormat{pages}{#1}

\begin{document}
\textcite{johndoe_article,johndoe_techreport}


\printbibliography
\end{document}

[![output of code][1]][1]

相关内容