
私は、biblatexを使用して、booktitleフィールドの単語を略語に自動的に置き換えようとしています(例:ProceedingsをProc.に、SymposiumをSymp.になど)。私のアプローチは、マクロを使用することです\DeclareFieldFormat
(置換マクロは複数部分文字列の置換):
\newcommand{\shorten}[1]{%
\saveexpandmode\noexpandarg
\def\x{#1}%
\xStrSubstitute{\x}{Proceedings}{Proc.}[\x]%
\x%
\message{\x}
\restoreexpandmode
}
\newcommand*{\xStrSubstitute}{%
\expandafter\StrSubstitute\expandafter
}
\DeclareFieldFormat[inproceedings]{booktitle}{\shorten{#1}}
問題は、 がDeclareFieldFormat
実行されたときに、引数がまだ実際のデータ値に拡張されていないため、 に渡される引数はshorten
実際には次のようになることです\printfield [titlecase]{booktitle}\setunit {\addperiod }\printfield [titlecase]{booksubtitle}
(呼び出しによって出力されますmessage
)。
マクロを実行できるように、biblatex から実際の書籍タイトルを取得する方法について何かアイデアはありますか?
答え1
フォーマットを直接適用する必要があります。booktitle
マクロは次のようになります。
\newbibmacro*{booktitle}{%
\ifboolexpr{
test {\iffieldundef{booktitle}}
and
test {\iffieldundef{booksubtitle}}
}
{}
{\printtext[booktitle]{%
\printfield[titlecase]{booktitle}%
\setunit{\subtitlepunct}%
\printfield[titlecase]{booksubtitle}}%
\newunit}%
\printfield{booktitleaddon}}
したがって、booktitle
コマンドは実際には の外側にあり\printtext
、 の内側に直接あるわけではありません\printfield
。
新しいフォーマットを定義してそれを使用する
\DeclareFieldFormat{shortenbooktitle}{#1}
\DeclareFieldFormat[inproceedings]{shortenbooktitle}{\shorten{#1}}
\renewbibmacro*{booktitle}{%
\ifboolexpr{
test {\iffieldundef{booktitle}}
and
test {\iffieldundef{booksubtitle}}
}
{}
{\printtext[booktitle]{%
\printfield[shortenbooktitle]{booktitle}%
\setunit{\subtitlepunct}%
\printfield[shortenbooktitle]{booksubtitle}}%
\newunit}%
\printfield{booktitleaddon}}
Biber を使用して交換することもでき、他のことは心配する必要はありません。
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pertype{inproceedings}
\step[fieldsource=booktitle,
match=\regexp{Proceedings},
replace=\regexp{Proc.}]
\step[fieldsource=booktitle,
match=\regexp{Symposium},
replace=\regexp{Symp.}]
}
}
}