在 biblatex 哲學中,欄位如何有條件地出現?

在 biblatex 哲學中,欄位如何有條件地出現?

我正在嘗試將參考書目風格與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當作者不存在時,設定會用標題取代作者。

我在上面添加了以下程式碼,以使 bibdriver 可以識別“maintitle”欄位(用作網站標題)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,editortranslation巨集中的後備,這樣在根本沒有給出名稱的情況下,您永遠不會得到一個空的“名稱標題”。

如果沒有名稱,您現在可以抑制名稱列印巨集的執行,如 gusbrs 的答案所示。但我更喜歡另一種方法:告訴名稱列印巨集在沒有名稱的情況下不要依靠標題。這可以透過重新定義author,bbx:editor和bibmacros來完成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請注意我如何使用global 選項australianbiblatexoption獲取澳洲風格的日期urldate=comp

相關內容