0

I have defined an "extendedof" relation type for my biblatex file, used to relate extended versions of works to their original published version. To do so, I added the lines below to the preamble of my latex file:

\NewBibliographyString{extendedof}
\DefineBibliographyStrings{english}{extendedof={Extended version of},}
\DeclareFieldFormat{relatedstring:extendedof}{#1\addcolon\addspace}
\DeclareFieldFormat{related:extendedof}{\mkbibparens{#1}}
\newbibmacro*{related:extendedof}[1]{\entrydata*{#1}{\iffieldundef{journaltitle}{\iffieldundef{maintitle}{\printfield[title:hook]{booktitle}}{\printfield[title:hook]{maintitle}}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\printfield{edition}\newunit\iffieldundef{volume}{}{\printfield{volume}\printfield{part}}\newunit\newblock\usebibmacro{series+number}\newunit\newblock\printfield{note}\newunit\newblock\usebibmacro{publisher+location+date}\newunit\newblock\usebibmacro{chapter+pages}}{\usebibmacro{author/editor}\newunit\newblock\usebibmacro{title}\newunit\newblock\renewbibmacro*{journal}{\printfield[title:hook]{journaltitle}}\usebibmacro{journal+issuetitle}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\usebibmacro{note+pages}}}}

It works. The catch is that I use a single master library/biblatex file across all of my papers, and I would rather not have to manually add the above to each latex document I edit. Is there any way to include the above directly into the biblatex file to make it portable? I tried wrapping each line in @Preamble{"..."} and adding it to the biblatex file as so:

@Preamble{"\NewBibliographyString{extendedof}"}
@Preamble{"\DefineBibliographyStrings{english}{extendedof={Extended version of},}"}
@Preamble{"\DeclareFieldFormat{relatedstring:extendedof}{#1\addcolon\addspace}"}
@Preamble{"\newbibmacro*{related:extendedof}[1]{\entrydata*{#1}{\iffieldundef{journaltitle}{\iffieldundef{maintitle}{\printfield[title:hook]{booktitle}}{\printfield[title:hook]{maintitle}}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\printfield{edition}\newunit\iffieldundef{volume}{}{\printfield{volume}\printfield{part}}\newunit\newblock\usebibmacro{series+number}\newunit\newblock\printfield{note}\newunit\newblock\usebibmacro{publisher+location+date}\newunit\newblock\usebibmacro{chapter+pages}}{\usebibmacro{author/editor}\newunit\newblock\usebibmacro{title}\newunit\newblock\renewbibmacro*{journal}{\printfield[title:hook]{journaltitle}}\usebibmacro{journal+issuetitle}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\usebibmacro{note+pages}}}}"}

This has most of the desired effect, except that the bibliography string extendedof does not seem to take effect. I do, however, get the following in the .bbl file:

\preamble{%
\NewBibliographyString{extendedof}%
\DefineBibliographyStrings{english}{extendedof={Extended version of},}%
\DeclareFieldFormat{relatedstring:extendedof}{#1\addcolon\addspace}%
\newbibmacro*{related:extendedof}[1]{\entrydata*{#1}{\iffieldundef{journaltitle}{\iffieldundef{maintitle}{\printfield[title:hook]{booktitle}}{\printfield[title:hook]{maintitle}}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\printfield{edition}\newunit\iffieldundef{volume}{}{\printfield{volume}\printfield{part}}\newunit\newblock\usebibmacro{series+number}\newunit\newblock\printfield{note}\newunit\newblock\usebibmacro{publisher+location+date}\newunit\newblock\usebibmacro{chapter+pages}}{\usebibmacro{author/editor}\newunit\newblock\usebibmacro{title}\newunit\newblock\renewbibmacro*{journal}{\printfield[title:hook]{journaltitle}}\usebibmacro{journal+issuetitle}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\usebibmacro{note+pages}}}}%
}

1 Answer 1

1

With @Preamble you write the code to the .bbl file, so the code only becomes available after the .bbl file is read. This happens early on when the document is started (much earlier than in classical BibTeX, where the .bbl file is read exactly at the point where the bibliography is printed), but not early enough. The language options and strings are already defined at that point and the document language has also been selected.

\DefineBibliographyStrings may only be used in the preamble, because it works by injecting some code into the .lbx loading routine. This means that it must be used before the .lbx files are loaded. Calling it in the .bbl is too early for the \@onlypreamble detection to raise an error, but too late for the .lbx loading.

You can define a macro that performs the bibstring assignments so that they are directly usable. You will furthermore have to re-select the main document language again after \begin{document} because string changes only become active after a language switch.

The following MWE compiles to the desired output

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

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

\newrobustcmd*{\ManuallyDefineBibliographyStringsLater}[3]{%
  \csgappto{abx@strings@#1}{%
    \csdef{abx@lstr@#2}{#3}%
    \csletcs{abx@sstr@#2}{abx@lstr@#2}}}

\begin{filecontents}{\jobname.bib}
@Preamble{"\NewBibliographyString{extendedof}"}
@Preamble{"\DefineBibliographyStrings{english}{extendedof={Extended version of},}"}
@Preamble{"\ManuallyDefineBibliographyStringsLater{english}{extendedof}{Extended version of}"}
@Preamble{"\DeclareFieldFormat{relatedstring:extendedof}{#1\addcolon\addspace}"}
@Preamble{"\newbibmacro*{related:extendedof}[1]{\entrydata*{#1}{\iffieldundef{journaltitle}{\iffieldundef{maintitle}{\printfield[title:hook]{booktitle}}{\printfield[title:hook]{maintitle}}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\printfield{edition}\newunit\iffieldundef{volume}{}{\printfield{volume}\printfield{part}}\newunit\newblock\usebibmacro{series+number}\newunit\newblock\printfield{note}\newunit\newblock\usebibmacro{publisher+location+date}\newunit\newblock\usebibmacro{chapter+pages}}{\usebibmacro{author/editor}\newunit\newblock\usebibmacro{title}\newunit\newblock\renewbibmacro*{journal}{\printfield[title:hook]{journaltitle}}\usebibmacro{journal+issuetitle}\newunit\newblock\usebibmacro{byeditor+others}\newunit\newblock\usebibmacro{note+pages}}}}"}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  date    = {1980},
  related = {sigfridsson},
  relatedtype = {extendedof},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}


\begin{document}
\selectlanguage{english}
\cite{appleby}
\printbibliography
\end{document}

Appleby, Humphrey (1980). On the Importance of the Civil Service. Extended version of: Sigfridsson, Emma and Ulf Ryde (1998). “Comparison of methods for deriving atomic charges from the electrostatic potential and moments”. Journal of Computational Chemistry 19.4, pp. 377–395.

I really don't think @preamble was meant to handle such complex code. It was a clever way to make small definitions in BibTeX, but I haven't seen it used all that often with biblatex.

If you want your definitions to be available in all your biblatex documents, you can put them into biblatex.cfg. (See for example Biblatex.cfg vs .cls vs .sty. I'm not a big fan of biblatex.cfg because I think it is too easy to forget that it is active, but for a modification like this it may be alright. Of course it is not as portable as having all the code in the .bib file.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.