更改一种 BibLaTeX 引用样式而不影响其余部分

更改一种 BibLaTeX 引用样式而不影响其余部分

@online我已经改变了BibLaTeX 条目的格式。

在线条目显示的符合我的要求,但是却导致条目格式@book错误。

我希望条目@book的格式为

Surname, B. (2005) Book title in italics followed by full stop.
    Place of publication: Name of the publisher

此处的名称格式为Surname, Initials。因此Jeff Buckley将表示为Buckley, J.等等。

我不确定为什么[online] url要将其强行放在书的参考文献末尾,或者如何在不干扰为在线条目创建的格式的情况下删除它。

以下是 MWE。


这是main.tex文件

\documentclass{book}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PACKAGES 

\usepackage[style=authoryear]{biblatex}
\usepackage[T1]{fontenc} % font encoding, copied 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BIBLIOGRAPHY INFORMATION

% \addbibresource{main.bib}
\addbibresource{refs.bib}

\NewBibliographyString{onlinesource}

\DefineBibliographyStrings{english}{%
  urlseen = {accessed on},
  urlfrom = {available from},
  onlinesource = {online},
}

\DeclareFieldFormat{urldate}{%
\mkbibbrackets{%
  \thefield{urlday}\adddot\addspace%
  \mkbibmonth{\thefield{urlmonth}}\adddot\addspace%
  \thefield{urlyear}\isdot}}

% This puts the <> braces about the url field
\DeclareFieldFormat{url}{\space\bibsentence\bibstring{urlfrom}\addcolon\space<\url{#1}>}

\newbibmacro*{url+urldate}{%
  \printtext{\bibstring[\mkbibbrackets]{onlinesource}}%
  \setunit{\addspace}%
  \iffieldundef{urlyear}
    {}
  \usebibmacro{url}%
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BEGIN DOCUMENT

\begin{document}

This citation is working correctly \autocite{ford} 

But others don't seem to work as a result of the adjustments for web
\autocite{Chomsky1957}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BIBLIOGRAPHY INCLUDE

\printbibliography
\end{document}

这是refs.bib文件

@book{Chomsky1957,
    Address   = {The Hague},
    Author    = {A Book},
    Publisher = {Mouton},
    Title     = {Book Book Book},
    Year      = {1957}
}

@online{ford,
    author  = {Fordy, Rebecca},
    title   = {Earthquake: Twitter Users Learned},
    date    = {2011-08},
    url     = {http://www.hollywoodreporter.com/news/earthquake-twitter-users-learned-tremors-226481},
    urldate = {2012-05-16}
}

当前格式如下:

在此处输入图片描述

答案1

该宏url+urldate通常由所有条目类型调用。因此,如果它排版文本如“[Online]”,则该文本将显示在所有条目类型中。如果您想隐藏除 之外的所有条目类型的 URL @online,您可以使用该选项url=false,这样可以避免调用url+urldate所有其他类型,因此不会排版“[Online]”。但如果您仍然希望能够拥有其他条目类型的 URL,则更安全的做法是重新定义宏url+urldate以添加检查是否打印“[Online]”字符串。

此外,您的定义中有一个小的语法错误url+urldate

  \iffieldundef{urlyear}
    {}
  \usebibmacro{url}%
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}

不是有效的条件。这会导致不需要的字符串“url”出现在@book条目中。我只能假设\usebibmacro{url}条件的两个分支之间是偶然滑动的。它应该位于块之前或之后。

通常在 s 的开头或结尾不应该有空格或标点符号命令\DeclareFieldFormat\space开头的\DeclareFieldFormat{url}会造成不必要的双空格。字段之间的标点符号应该用 和\setunit来处理,而不是用\DeclareFieldFormat

我强烈建议不要使用 重新定义日期格式\DeclareFieldFormat{urldate}。由于您在评论中提到您的文档是英式英语,因此最好的解决方案是使用 选项urldate=longbabel使用 选项加载british

综合起来,我们得到

\documentclass[british]{article}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[style=authoryear, urldate=long]{biblatex}

\NewBibliographyString{onlinesource}

\DefineBibliographyStrings{english}{%
  urlseen = {accessed on},
  urlfrom = {available from},
  onlinesource = {online},
}

\DeclareFieldFormat{urldate}{\mkbibbrackets{#1}}

\DeclareFieldFormat{url}{\bibsentence\bibstring{urlfrom}\addcolon\space<\url{#1}>}

\renewbibmacro*{url+urldate}{%
  \ifentrytype{online}
    {\bibstring[\mkbibbrackets]{onlinesource}}
    {}%
  \setunit{\addspace}%
  \usebibmacro{url}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Chomsky1957,
  address   = {The Hague},
  author    = {A Book},
  publisher = {Mouton},
  title     = {Book Book Book},
  year      = {1957}
}

@online{ford,
  author  = {Fordy, Rebecca},
  title   = {Earthquake: Twitter Users Learned},
  date    = {2011-08},
  url     = {http://www.hollywoodreporter.com/news/earthquake-twitter-users-learned-tremors-226481},
  urldate = {2012-05-16}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
This citation is working correctly \autocite{ford} 

But others don't seem to work as a result of the adjustments for web
\autocite{Chomsky1957}

\printbibliography
\end{document}

Book, A (1957)。Book Book Book。海牙:Mouton。//Fordy, Rebecca (2011 年 8 月)。地震:Twitter 用户了解到的情况。[在线] 可从以下网址获取:<http://www.hollywoodreporter.com/news/earthquake-twitter-users-learned-tremors-226481> [2012 年 5 月 16 日]。

相关内容