6

I'm using this answer to create an annotated bibliography with biblatex, with the following code:

\documentclass{article}

% This just makes a dummy bib file
\begin{filecontents}{\jobname.bib}
@ARTICLE{a,
   author = {Doe, J.},
   title = {The Title},
   journal = {The Journal},
   mynote = {This source is really interesting because it doesn't have a real title}
}

@ARTICLE{b,
   author = {Smith, J.},
   title = {The New Title},
   journal = {The Same Journal},
   mynote = {This second source is also really interesting because it contains words}
}
\end{filecontents}

% This does the work
\usepackage[style=trad-plain]{biblatex}
\addbibresource{\jobname.bib}
\DeclareDatamodelFields[type=field,datatype=literal]{mynote}

\usepackage{xpatch}
\xapptobibmacro{finentry}{\par\printfield{mynote}}{}{}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

However, I get a warning

Package biblatex Warning: Data model macro 'DeclareDatamodelFields' cannot be used in preamble.

and the output is as if no change had been done to the data model:

Image

9
  • You get a warning along the lines of "Data model macro 'DeclareDatamodelFields' cannot be used in preamble." This behaviour has only changed recently (before that data model macros worked properly in the preamble in most cases, but there were problems, I think). Now data model commands cannot be used in the preamble any more, they have to be externalised to a .dbx file.
    – moewe
    Apr 14, 2015 at 16:12
  • 2
    Create a .dbx file called mynote.dbx containing the line \DeclareDatamodelFields[type=field,datatype=literal]{mynote}. Then call biblatex with the additional option datamodel=mynote as in \usepackage[style=trad-plain,datamodel=mynote]{biblatex}.
    – moewe
    Apr 14, 2015 at 16:14
  • @moewe it might be better to edit my answer and close this as a duplicate.
    – StrongBad
    Apr 14, 2015 at 16:38
  • @StrongBad Mhhh, probably - I have just written up the answer, though ;-). I think it might not be too bad of an idea to have a standard "my data model macros don't work any more" question which we can questions such as this duplicate to. Going through all answers that used data model macros and editing them seems quite the task.
    – moewe
    Apr 14, 2015 at 16:42
  • @StrongBad But please, by all means edit your question (preferably with a more or less prominent note of the required change) to make sure people don't get confused about this.
    – moewe
    Apr 14, 2015 at 16:43

1 Answer 1

12

Starting from version 2.9 of biblatex (with this commit) data model macros (like \DeclareDatamodelEntrytypes, DeclareDatamodelFields, \DeclareDatamodelEntryfields, ... a full list can be found in §4.5.3 Data Model Specification, pp. 156-161 of the biblatex documentation) are disabled in the preamble and yield only a warning along the lines of

Data model macro '\DeclareDatamodelFields' cannot be used in preamble

These commands can now only be used from an external .dbx (data model) file.

The solution consists in moving these data model macros to an external .dbx file.

In our example we will call said file mynote.dbx and we only have one line to move

\DeclareDatamodelFields[type=field,datatype=literal]{mynote}

We then call this data model via datamodel=mynote in the biblatex options.

MWE

\documentclass{article}

% This just makes a dummy bib file
\begin{filecontents}{\jobname.bib}
@ARTICLE{a,
   author = {Doe, J.},
   title = {The Title},
   journal = {The Journal},
   mynote = {This source is really interesting because it doesn't have a real title}
}

@ARTICLE{b,
   author = {Smith, J.},
   title = {The New Title},
   journal = {The Same Journal},
   mynote = {This second source is also really interesting because it contains words}
}
\end{filecontents}

% This does the work
\usepackage[style=trad-plain,datamodel=mynote]{biblatex}
\addbibresource{\jobname.bib}


\usepackage{xpatch}
\xapptobibmacro{finentry}{\setunit{\par}\printfield{mynote}}{}{}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

If mynote.dbx is just

\DeclareDatamodelFields[type=field,datatype=literal]{mynote}
2
  • How would you change this if you start with \usepackage[authordate, backend=biber]{biblatex-chicago}? Doing all that you said and then doing [..., datamodel=mynote], the obvious implementation to try, didn't work. Any recommendations?
    – ctde
    Aug 27, 2020 at 5:22
  • @ctde I'm afraid the biblatex-chicago wrapper package does not recognise the datamodel option. You may want to contact the author about this (though he may not be inclined to include it, after all biblatex-chicago isn't really supposed to be customised a lot: it is supposed to produce CMS-compliant output). It is possible to work around that, but it is going to be ugly. If you are interested in a workaround ask a new question, please.
    – moewe
    Aug 27, 2020 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .