Como os campos podem aparecer condicionalmente à presença de campos na filosofia biblatex?

Como os campos podem aparecer condicionalmente à presença de campos na filosofia biblatex?

Estou tentando combinar um estilo de bibliografia com biblatex-philosophy. O formato dos recursos online é o seguinte:

Online com autor: On-line com o autor Online sem autor (mesmos detalhes para simplificar): Imgur

Por padrão, usando este código (já com alguns ajustes na formatação):

\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}

Com este .bibarquivo:

@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}
}

O resultado é o seguinte: Saída padrão Como você pode ver, não há título do site (além do título da página) e, por padrão, as philosophy-modernconfigurações substituem o autor pelo título quando o autor não está presente.

Adicionei o seguinte código acima para tornar o campo "maintitle" (servindo como título do site) reconhecível pelo onlinebibdriver, além de cortar completamente o campo do autor:

\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'}}

O que resulta nisso: Tentar

Ótimo, exceto, obviamente, como removi a macro do autor da execução, não recebo nenhum autor, mesmo quando um é especificado.

Minha dúvida é: como executo o xpatchtrecho acima condicionalmente, somente quando o autor está ausente (indefinido?), para corresponder à formatação exigida?

Ainda estou entendendo xpatcho comando, então duvido que minha tentativa seja ideal de qualquer maneira. Por favor, deixe-me saber como o código pode ser melhorado.

Responder1

Acho que entendi o que você quer dizer. Mas, de qualquer forma, a maneira de proceder não é "realizar um patch condicionalmente", mas sim "realizar um patch com a condicional incluída".

Se entendi corretamente, isso deve funcionar (observe que estou testando a presença de "autor", "editor" ou "tradutor", dada a macro em questão):

\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}

insira a descrição da imagem aqui

Responder2

O título é usado como substituto nas macros author, editore translationpara que você nunca acabe com um 'título de nome' vazio caso nenhum nome seja fornecido.

Agora você pode suprimir a execução da macro de impressão de nome caso não haja nome, conforme mostrado na resposta do gusbrs. Mas prefiro uma abordagem diferente: diga ao nome das macros de impressão para não recorrer ao título se não houver nome. Isso pode ser feito redefinindo as macros author, bbx:editore bbx:translatorbibmacros.

\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}

insira a descrição da imagem aqui

Observe como obtive as datas no estilo australiano usando babela opção global australiane a biblatexopção urldate=comp.

informação relacionada