# Is it possible to create biblatex datamodels entries programatically?

I'm trying to add some multi language support for a custom data model in biblatex.

I'm following this answer. And have a functional prototype. However, when I started migrating the fields, it seems that it is quite repetitive to put different languages to each one of them, like

\DeclareDatamodelFields[type=field, datatype=literal]{
organization,%
title,%
country,%
country-es,%
country-en,%
description,%
description-es,%
description-en%
}


I'm looking for a way to put a loop in there (somehow), such that I can automatically create the different versions of each field.

\DeclareDatamodelFields[type=field, datatype=literal]{
organization,%
title,
% some language to support the following
foreach f in (country, description)
foreach l in (, -es, -en)
print f l,
}


I didn't find information on what language biblatex uses to process this .dbx files.

I know that I can use some external program to generate the .dbx file and then just use it. But I was looking for something that could be maintained and compiled automatically with the project in LaTeX.

Any suggestions?

• Since a .dbx is going to be (used as) an external file anyway most of the time, I would just go with automatic creation by your favourite script language. I don't think that the DeclareDatamodelFields-syntax allows for programming-like structures. I might be wrong here, but it could just be a list parser behind it. – moewe Aug 25 '16 at 7:25
• Any news here? I feel this more a feature request for Biber, if you don't want to use a script language to create the .dbx. (Why don't you want to create the .dbx from a script?) – moewe Sep 4 '16 at 7:39
• I was thinking to have something similar to what biblatex does natively. But I ended up doing it with an script outside, and used the generated files. – adn Sep 4 '16 at 22:25
• Mhh, I'm not quite sure what you mean by "what biblatex does natively". There is a big file blx-dm.def with all the known fields, there is no shortcut in there. BTW If you managed to solve your problem, you might want to post a self-answer so future readers with a similar problem can see your solution. – moewe Sep 5 '16 at 4:07
• I was checking that file, but there is some latex code that produces some entries, maybe I didn't understand it well. But, my solution is not a solution, is a patch actually. As I did it by hand. In that case the answer will be 'no, there is no way of doing it automatically'. – adn Sep 5 '16 at 12:46

The .dbx files are simply processed like normal LaTeX, so in theory you can use every tool that LaTeX offers you. But \DeclareDatamodelFields and friends process their mandatory (second) argument with \docsvlist{#2}, which means that the input can not be arbitrary, but must be a comma-separated list of strings. So a loop within \DeclareDatamodelFields is ruled out, but there is no problem with building loops outside of \DeclareDatamodelFields.

In the MWE there are two nested loops. The outer loop (\adn@dbx@fieldloop) loops over the field names, the inner (\adn@dbx@langloop) over the language names. With expl3 you might be able to obtain a more natural loop-like structure instead of the unusual structure imposed by etoolbox.

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

\usepackage{filecontents}
\ProvidesFile{adn.dbx}[2018/10/24 example for loops in dbx files]
\DeclareDatamodelFields[type=field, datatype=literal]{#1-#2}}

\DeclareDatamodelFields[type=field, datatype=literal]{#1}%
}

\end{filecontents}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
author         = {Humphrey Appleby},
title          = {On the Importance of the Civil Service},
date           = {1980},
description    = {Vanilla},
description-es = {¡Hola!},
description-en = {How do you do?},
country        = {Plaincountry},
country-es     = {Spain},
country-en     = {England},
}
\end{filecontents}

\renewbibmacro*{finentry}{%
\printfield{description}%
\newunit
\printfield{description-es}%
\newunit
\printfield{description-en}%
\newunit
\printfield{country}%
\newunit
\printfield{country-es}%
\newunit
\printfield{country-en}%
\newunit
\finentry}

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


Since .dbx files are usually files that remain constant over many projects and are probably only generated once, I still consider it not a bad idea to generate such a file with an external scripting language. You would save on the overhead induced by the loops on each LaTeX run.