BibLaTeX (authoryear) は日付が空の場合に空の括弧を挿入します

BibLaTeX (authoryear) は日付が空の場合に空の括弧を挿入します

まだ出版日が決まっていない「準備中」の出版物(日付フィールドが空)に、 BibLaTeX のフィールドを使用したいと思いますpubstate。たとえば、authoryear スタイルの次のフィールドです。

@Article{Test,
author       = {Author, A.},
journaltitle = {A Journal},
title        = {A Title},
pubstate     = {inpreparation},
}

ただし、ジャーナル名の後に空の括弧が残ります。

\documentclass{article}
\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{Bib2.bib}

\begin{document}
Test \parencite{Test}.

\printbibliography
\end{document}

ここに画像の説明を入力してください

これを削除するにはどうすればいいですか?

答え1

ここでの根本的な問題は、他のコマンドとは異なり、\print(field|list|names|date)コマンドは\printtext何かを印刷するかどうかを事前に知らないことです。そのため、後で何も印刷されないことが判明した場合でも、常に書式設定引数が適用されます。ここでは、空の括弧のペアが作成されることになります。

これを回避する 1 つの方法は、 を呼び出す前に何かを印刷するかどうかを確認することです\printtext

biblatexいくつかのコードでは を使用していますが、\ifthenelseほとんどの新しいコードでは を使用していますetoolbox\ifboolexprの内部には のbiblatexフィールドがないのでdate、 の存在をテストしたい場合は をdateテストする方がよいことに注意してください。year

\renewbibmacro*{issue+date}{%
  \ifboolexpr{test {\iffieldundef{issue}} and test {\iffieldundef{year}}}
    {}
    {\printtext[parens]{%
       \printfield{issue}%
       \setunit*{\addspace}%
       \usebibmacro{date}}%
     \newunit}}

参照https://github.com/plk/biblatex/issues/793

最近、何かを印刷するかどうかを自動的にチェックし、印刷しない場合はフォーマットを抑制するbiblatex-apaバージョンの実装に興味を持つ人もいるかもしれません。\printtexthttps://github.com/plk/biblatex-apa/pull/99このコマンドに悪影響がないことが判明した場合、これをコアに移動することを検討する必要があるかもしれませんbiblatexが、さらにテストが必要です (実装は不正行為のように感じられます)。

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\renewbibmacro*{issue+date}{%
  \printtexte[parens]{%
    \printfield{issue}%
    \setunit*{\addspace}%
    \usebibmacro{date}}%
  \newunit}

% implement \printtexte
\makeatletter
% Optional parens/brackets
% Thanks to egreg from https://tex.stackexchange.com/questions/53068/how-to-check-if-a-macro-value-is-empty-or-will-not-create-text-with-plain-tex-co
% for this test for expanded emptiness so that we can easily opt to not print parens around nothing
% Without this, it is very messy - you have to test all potential fields for defness first and this
% is messy because the fields in the additional info vary betwee entrytypes
\def\foreverunspace{%
  \ifnum\lastnodetype=11
    \unskip\foreverunspace
  \else
    \ifnum\lastnodetype=12
      \unkern\foreverunspace
    \else
      \ifnum\lastnodetype=13
        \unpenalty\foreverunspace
      \fi
    \fi
  \fi
}

% we need a way to save the state of the punctuation buffer
% cf. \blx@initunit in biblatex.sty for what we need to copy

% this uses the internal implementation of etoolbox toggles
% fingers crossed no one messes with it
\newrobustcmd*{\apablx@savetoggle}[1]{%
  \csletcs{apablx@savedtoggle@#1}{etb@tgl@#1}}

\newrobustcmd*{\apablx@restoretoggle}[1]{%
  \csletcs{etb@tgl@#1}{apablx@savedtoggle@#1}}

\newrobustcmd*{\apablx@savepunctstate}{%
  \apablx@savetoggle{blx@block}%
  \apablx@savetoggle{blx@unit}%
  \apablx@savetoggle{blx@insert}%
  \apablx@savetoggle{blx@lastins}%
  \apablx@savetoggle{blx@keepunit}%
  \let\apablx@savd@unitpunct\blx@unitpunct
  \let\apablx@savd@puncthook\abx@puncthook}

\newrobustcmd*{\apablx@restorepunctstate}{%
  \global\apablx@restoretoggle{blx@block}%
  \global\apablx@restoretoggle{blx@unit}%
  \global\apablx@restoretoggle{blx@insert}%
  \global\apablx@restoretoggle{blx@lastins}%
  \global\apablx@restoretoggle{blx@keepunit}%
  \global\let\blx@unitpunct\apablx@savd@unitpunct
  \global\let\abx@puncthook\apablx@savd@puncthook}

% printtext that checks if it would print anything
\newrobustcmd{\printtexte}[2][]{%
  \apablx@savepunctstate
  \setbox0=\hbox{#2\foreverunspace}%
  \apablx@restorepunctstate
  \ifdim\wd0=0pt
  \else
    \ifblank{#1}
      {\printtext{#2}}
      {\printtext[#1]{#2}}%
  \fi}
\makeatother


\begin{filecontents}{\jobname.bib}
@article{test,
  author       = {Author, A.},
  journaltitle = {A Journal},
  title        = {A Title},
  pubstate     = {inpreparation},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
\autocite{test}
\printbibliography
\end{document}

著者、A. (nd)。「タイトル」。ジャーナルに掲載。準備中。

答え2

解決策を見つけました:

\renewbibmacro*{issue+date}{%
\ifthenelse{\ifentrytype{article}\AND\iffieldundef{date}\AND\iffieldundef{issue}}
    {}
    {\ifthenelse{\iffieldundef{issue}}
        {}
        {\printtext[parens]{%
        \printfield{issue}%
        \setunit*{\addspace}%
        \usebibmacro{date}}}}%
\newunit}

関連情報