biblatex-philosophy でフィールドが存在する場合に、フィールドを条件付きで表示するにはどうすればよいですか?

biblatex-philosophy でフィールドが存在する場合に、フィールドを条件付きで表示するにはどうすればよいですか?

参考文献のスタイルを に一致させようとしています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}
}

出力は次のようになります: デフォルト出力 ご覧のとおり、Web サイトのタイトル (ページ タイトル以外) はなく、デフォルトでは、philosophy-modern作成者が存在しない場合は作成者がタイトルに置き換えられます。

上記のコードに次のコードを追加して、フィールド「maintitle」(Web サイトのタイトルとして機能) を bibdriver が認識できるようonlineにし、author フィールドを完全に削除しました。

\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 の回答に示されているように、名前がない場合には名前印刷マクロの実行を抑制できるようになりました。しかし、私は別のアプローチを好みます。名前がない場合にはタイトルにフォールバックしないように名前印刷マクロに指示します。これは、、authorおよびbbx:editorbibmacrosを再定義することで実行できます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グローバル オプションaustralianbiblatexオプションを使用して、オーストラリア式の日付を取得した方法に注目してくださいurldate=comp

関連情報