
Ich versuche, mit biblatex Wörter im Feld booktitle automatisch durch ihre Abkürzungen zu ersetzen (z. B. Proceedings zu Proc., Symposium zu Symp. usw.). Mein Ansatz besteht darin, das \DeclareFieldFormat
Makro zu verwenden (mit einem Substitutionsmakro mit freundlicher Genehmigung vonErsetzen mehrerer Teilzeichenfolgen):
\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}}
Das Problem besteht darin, dass das Argument beim DeclareFieldFormat
Ausführen noch nicht auf den tatsächlichen Datenwert erweitert wurde, sodass das übergebene Argument shorten
tatsächlich lautet: \printfield [titlecase]{booktitle}\setunit {\addperiod }\printfield [titlecase]{booksubtitle}
(vom message
Aufruf gedruckt).
Irgendwelche Ideen, wie ich den tatsächlichen Buchtitel aus Biblatex herausbekomme, damit ich mein Makro darauf ausführen kann?
Antwort1
Sie müssen das Format direkt anwenden. Das booktitle
Makro sieht wie folgt aus
\newbibmacro*{booktitle}{%
\ifboolexpr{
test {\iffieldundef{booktitle}}
and
test {\iffieldundef{booksubtitle}}
}
{}
{\printtext[booktitle]{%
\printfield[titlecase]{booktitle}%
\setunit{\subtitlepunct}%
\printfield[titlecase]{booksubtitle}}%
\newunit}%
\printfield{booktitleaddon}}
Der booktitle
Befehl steht also tatsächlich im Äußeren \printtext
und nicht direkt im \printfield
.
Definieren Sie ein neues Format und verwenden Sie es
\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}}
Auch den Austausch können Sie bequem über Biber erledigen und müssen sich um nichts weiter kümmern.
\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.}]
}
}
}