¿Cómo pueden aparecer los campos condicionalmente a la presencia de campos en la filosofía biblatex?

¿Cómo pueden aparecer los campos condicionalmente a la presencia de campos en la filosofía biblatex?

Estoy intentando hacer coincidir un estilo de bibliografía con biblatex-philosophy. El formato de los recursos en línea es el siguiente:

En línea con autor: En línea con el autor En línea sin autor (mismos detalles para simplificar): Imgur

De forma predeterminada, usando este código (ya con un par de ajustes en el formato):

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

Con este .bibarchivo:

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

El resultado es esto: Salida predeterminada Como puede ver, no hay ningún título del sitio web (además del título de la página) y, de forma predeterminada, la philosophy-modernconfiguración reemplaza el autor con el título cuando el autor no está presente.

Agregué el siguiente código al anterior para que el campo "título principal" (que sirve como título del sitio web) sea reconocible para el onlinebibdriver, además de eliminar completamente el campo de 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'}}

Lo que produce esto: Intentar

Genial, excepto que, obviamente, eliminé la ejecución de la macro de autor y no obtengo ningún autor incluso cuando se especifica uno.

Mi pregunta es, ¿cómo ejecuto el xpatchfragmento anterior de forma condicional, solo cuando el autor está ausente (¿indefinido?), para que coincida con el formato requerido.

Todavía estoy entendiendo xpatchel comando, así que dudo que mi intento sea óptimo de todos modos. Déjame saber cómo se podría mejorar el código.

Respuesta1

Creo que entiendo lo que quieres decir. Pero, de todos modos, la forma de proceder no es "realizar un parche condicionalmente" sino "realizar un parche con el condicional incluido".

Si lo entiendo correctamente, esto debería funcionar (tenga en cuenta que estoy probando la presencia de "autor", "editor" o "traductor", dada la macro en cuestión):

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

ingrese la descripción de la imagen aquí

Respuesta2

El título se utiliza como alternativa en las authormacros editory translationpara que nunca termine con un 'encabezado de nombre' vacío en caso de que no se proporcione ningún nombre.

Ahora puede suprimir la ejecución de la macro de impresión de nombres en caso de que no haya ningún nombre como se muestra en la respuesta de gusbrs. Pero prefiero un enfoque diferente: decirle a las macros de impresión de nombres que no recurran al título si no hay ningún nombre. Esto se puede hacer redefiniendo las macros authory 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}

ingrese la descripción de la imagen aquí

Observe cómo obtuve las fechas al estilo australiano usando babella opción global australiany la biblatexopción urldate=comp.

información relacionada