# .bib files: edition, language, langid

When writing bib files, bibtex prescribes a captitalized ordinal for editions, such as edition={Fourth}. But babelbib and biblatex insist on numbers, such as edition=4. This means that whenever we switch from one setup to another one, we have to rewrite our bib files. Similar rewriting has to happen for langid in biblatex+biber vs. language in babelbib+bibtex.

E.g., the following file is made for processing with pdflatex and bibtex:

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}
\usepackage{babelbib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Fischer-LineareAlgebra,
author={Gerd Fischer},
title={Lineare Algebra},
edition={12},
isbn={3-528-87217-9},
publisher={Vieweg},
language={ngerman}
}
\end{filecontents}
\bibliographystyle{bababbrv}
\begin{document}
\cite{Fischer-LineareAlgebra}
\bibliography{\jobname}
\end{document}


With bibtex but without babelbib, we'd have to rewrite 12 to Twelth. With biber+biblatex, we'd have to keep 12 but change language to langid.

So, how to automatize this process? Each manual rewriting is error prone and takes time...

• With biblatex, at least, you can use a source map to dynamically adjust your bib entries at compile time. I don't know anything about babelbib. – David Purton Apr 3 at 2:41
• My other thought is to use a bibliography manager that lets you export bib files in the appropriate format. – David Purton Apr 3 at 2:48

While there is a common core of fields that all BibTeX and biblatex styles support and where the input is expected to be the same by all tools involved there is a smaller, but nonnegligible list of fields that behave differently not only in the broad biblatex vs. BibTeX comparison, but also between different BibTeX .bst files. So whenever you switch styles it is a good idea to have a look at the documentation and scrutinise the output carefully for anything out of the ordinary.

If you want to be super flexible it might be attractive to look at the .bib file only as an intermediate format and store the database in a different, more flexible and powerful format. You would store your bibliography entries in a different database and then export to .bib files with the correct data model for the job. This could for example be possible with Zotero and https://retorque.re/zotero-better-bibtex/ (there are other contenders like Mendeley and Citavi, but in my very limited experience – I have used none of those tools productively, but seen quite a lot of questions about them on this site – Zotero's .bib export is superior to the other two especially with the help of BetterBibTeX). While the Zotero data model itself is in some ways less fine grained than the biblatex data model (for example), BetterBibTeX offers a variety of export refinements that could help you produce tailor-made .bib files for each bibliography style you use. Of course that introduces additional overhead and I am not entirely convinced that Zotero's data model is the best one can do, so you may well want to shop around or roll your own system if you decide to go for this option.

If you want to stick to .bib files as your primary bibliography database you need tools to manipulate the contents of those files.

Some .bib file managers like JabRef already have a set of clean-up options available and offer other search-and-replace features that could come in handy for tasks like this.

But there are also classical command line tools for the manipulation of .bib files. The first such program that comes to my mind is BibTool. Biber also has a --tool mode, but it has the disadvantage that it conforms to the standard biblatex data model by default and clears out any fields it does not know. That can be configured, but you need to be aware of this before you start Prevent biber --tool from removing non-standard fields in .bib files.

BibTool can easily rename, delete or add fields and can even rewrite the field contents with RegExp.

For example

rename.field { language = langid }
rewrite.rule {"^\"$$[^#]*$$\"$" # "{\1}"} rewrite.rule { edition # "^{1}$"  # "{First}"   }
rewrite.rule { edition # "^{12}$" # "{Twelfth}" }  saved as mytool.rsc and called on in.bib @book{Fischer-LineareAlgebra, author={Gerd Fischer}, title={Lineare Algebra}, edition={12}, isbn={3-528-87217-9}, publisher={Vieweg}, language={ngerman} }  as in the question as follows bibtool -r mytool.rsc in.bib -o out.bib  produces @Book{ fischer-linearealgebra, author = {Gerd Fischer}, title = {Lineare Algebra}, edition = {Twelfth}, isbn = {3-528-87217-9}, publisher = {Vieweg}, langid = {ngerman} }  (Naturally this is not the input biblatex wants, because it would prefer 12 instead of Twelfth, this is just to show how things could work.) This needs some configuration especially if you want to replace edition numbers as there is no simple way to replace those with a few lines. You could programmatically generate the replace rules for numbers up to $n\$ from a different scripting/programming language. While we are at the topic of different languages, there are some libraries to read and write .bib files with Python or Perl, so if you want a more powerful manipulation tool it is possible to roll your own using the full force of those languages.

If you only want to modernise your entries for biblatex some changes can be applied by Biber on the fly

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}
\usepackage{csquotes}
\usepackage[style=alphabetic, backend=biber]{biblatex}

\DeclareSourcemap{
\maps{
\map[overwrite]{
\step[fieldsource=language, final]
\step[fieldset=langid, origfieldval]
\step[fieldset=language, null]
}
\map{
\step[fieldsource=edition, match=\regexp{\ATwelfth\Z}, replace={12}]
}
}
}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{Fischer-LineareAlgebra,
author    = {Gerd Fischer},
title     = {Lineare Algebra},
edition   = {Twelfth},
isbn      = {3-528-87217-9},
publisher = {Vieweg},
language  = {ngerman}
}
\end{filecontents}