
Я пытаюсь сопоставить стиль библиографии с 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
заменяют автора заголовком, если автор отсутствует.
Я добавил следующий код к приведенному выше, чтобы сделать поле «maintitle» (служащее заголовком веб-сайта) распознаваемым для bibdriver 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
, editor
и translation
, чтобы вы никогда не получили пустой «заголовок имени» в случае, если имя вообще не указано.
Теперь вы можете подавить выполнение макроса печати имени в случае отсутствия имени, как показано в ответе gusbrs. Но я предпочитаю другой подход: указать макросам печати имени не возвращаться к заголовку, если имени нет. Это можно сделать, переопределив author
, bbx:editor
и bbx:translator
bibmacros.
\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
глобальную опцию australian
и biblatex
опцию urldate=comp
.