%20%E3%81%AF%E6%97%A5%E4%BB%98%E3%81%8C%E7%A9%BA%E3%81%AE%E5%A0%B4%E5%90%88%E3%81%AB%E7%A9%BA%E3%81%AE%E6%8B%AC%E5%BC%A7%E3%82%92%E6%8C%BF%E5%85%A5%E3%81%97%E3%81%BE%E3%81%99.png)
まだ出版日が決まっていない「準備中」の出版物(日付フィールドが空)に、 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
バージョンの実装に興味を持つ人もいるかもしれません。\printtext
https://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}
答え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}