This is a bit hackish, but may be an inspiration for a proper solution.
Biblatex loads datamodels very early, before processing any options defined in biblatex style files (.bbx
or .cbx
). This is why you can't control datamodel loading from within a style. You need to do adjustments before the biblatex is called. Below I describe how this can be done with a package. I assume that your tools are additions to some base biblatex style which your users can freely choose. Suppose your style and package are called dmtools
and you want two options manu
(to load a manuscript datamodel defined in dmtools-manu.dbx
) and fields
(to load additional fields defined in dmtools-fields.dbx
). You also have dmtools.bbx
and dmtools.cbx
with some macro definitions.
This is how these style and package are used:
\documentclass{article}
\usepackage[
basestyle=apa,
manu,
fields,
]{dmtools}
\usepackage[style=dmtools, ...]{biblatex}
\addbibresource{...}
\begin{document}
...
\end{document}
basestyle
is the base biblatex style to which your tools will serve as additions. If you don't need it, that is if your tools are supposed to provide additions to one bib style only, you can move the biblatex call inside the .sty
file.
Your package files then look like this:
dmtools.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dmtools}
\RequirePackage{kvoptions}
% options declarations
%
\DeclareBoolOption{manu}
\DeclareBoolOption{fields}
\DeclareStringOption[numeric]{basestyle}
\ProcessKeyvalOptions*
\ifdmtools@manu
\def\dmtmanu{dmtools-manu} % the name of .dbx file for the 'manu' tool
\fi
\ifdmtools@fields
\def\dmtfields{dmtools-fields} % the name of .dbx file for the 'fields' tool
\fi
\ifx\dmtools@basestyle\@empty
\else
\def\dmtbasestyle{\dmtools@basestyle} % the name of bibstyle to load later
\fi
\endinput
This declares options and sets some commands and \if
's to be used later. The basestyle
option is optional and if absent the numeric
style is used.
dmtools.dbx
% DM Tools data models
% load datamodel for the 'manu' tool
\ifdmtools@manu
\blx@inputonce{\dmtmanu.dbx}{DM Tools data model}{}{}{}{}
\fi
% load datamodel for the 'fields' tool
\ifdmtools@fields
\blx@inputonce{\dmtfields.dbx}{DM Tools data model}{}{}{}{}
\fi
% load datamodel for the style specified in the 'basestyle' option
\ifx\dmtools@basestyle\@empty
\else
\blx@inputonce{\dmtbasestyle.dbx}{biblatex style data model}{}{}{}{}
\fi
\endinput
This file loads your datamodels and also the datamodel for the basestyle
. You will probably need to adjust this to handle also bibstyle
and citestyle
options.
Finally, bibliography and citation style files:
dmtools.bbx
\ProvidesFile{dmtools.bbx}
\RequireBibliographyStyle{\dmtbasestyle}
\ifdmtools@manu
%
% macro (re)definitions
%
\fi
\ifdmtools@fields
%
% macro (re)definitions
%
\fi
\endinput
dmtools.cbx
\ProvidesFile{dmtools.cbx}
\RequireCitationStyle{\dmtbasestyle}
\ifdmtools@manu
%
% mscro (re)definitions
%
\fi
\ifdmtools@fields
%
% mscro (re)definitions
%
\fi
\endinput
These files load the basestyle
bib- and cite-styles and then (re)define macros/commands that you need for your tools.
biblatex
themselves. You can also provide the\renewbibmacro
s separately for package authors or those who like to play around withbiblatex
. – moewe Jan 16 '14 at 21:45