# How to make option langid={english} conditional?

How can i make all references to have langid={english} option unless there are cyrillic letters inside a reference, then it should be langid={russian}? Optional question: How can i make all references to have langid={english} unless otherwise stated with langid={russian} inside of reference?

• Interesting question, but i think adding the id usinng copy/paste might be a much qicker and more save approach. – Johannes_B May 24 '15 at 18:22
• I never learned the cyrillic script, nor do i have any idea how to input that properly and what the OS does with your input. Consider the following А A Α which is a cyr. A, a latin A and a greek Alpha. Can you ensure, that every cyr. A is really a cyr. A and nothing else? EDIT: Just checked, my OS and Editor use the right chars when changing the keyboard Layout. – Johannes_B May 24 '15 at 18:42
• That makes sense. But copypasting is not funny. – Eugenii Barannik May 24 '15 at 19:05

That is an interesting question indeed. I am always very wary of automatic solutions, they do exactly what they are told and are not intelligent. And one always has to check if everything went exactly as planned manually anyway.

With Biber we can do regex checks on fields. Regex allows to check for Cyrillic characters.

Here we check the title field (the best indicator for the language of the work, I would have thought) for Cyrillic letters. Entries with Cyrillic characters are classified as as russian, all other as english. That is, if no langid field is present; an existing langid field is never overwritten and thus naturally takes precedence over this procedure.

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=title,
match=\regexp{\p{cyrillic}},
final]
\step[fieldset=langid, fieldvalue=russian]
}
\map{\step[fieldset=langid, fieldvalue=english]}
}
}


Note that with this approach you have a "Russian -- English" dychotomy; French, Dutch, German, Ukrainian, Bulgarian works all fall through the cracks.

In the MWE below I have changed the finentry macro to display the langid.

MWE

\documentclass[german,russian,english]{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber,style=authortitle,autolang=other]{biblatex}
\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@article{cheby,
author   = {Б. В. Гнеденко},
title    = {П. Л. Чебышев, \enquote{Полное собрание сочинений} тт.~I--V (рецензия)},
journal  = {УМН},
year     = {1954},
volume   = {9},
number   = {4(62)},
pages    = {263--266},
}
@article{lewis,
author  = {Lewis, David},
year    = {1970},
title   = {How to Define Theoretical Terms},
journal = {Journal of Philosophy},
volume  = {67},
pages   = {427–446},
}
@article{hilbert:trans,
author    = {David Hilbert},
title     = {Ueber die Transcendenz der Zahlen $e$ und $\pi$},
journal   = {Mathematische Annalen},
date      = {1893},
volume    = {43},
pages     = {216-219},
langid    = {german},
url       = {http://resolver.sub.uni-goettingen.de/purl?PPN235181684_0043},
}
\end{filecontents*}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=title,
match=\regexp{\p{cyrillic}},
final]
\step[fieldset=langid, fieldvalue=russian]
}
\map{\step[fieldset=langid, fieldvalue=english]}
}
}

\renewbibmacro*{finentry}{\printfield{langid}\finentry}

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


Note that hilbert:trans retains its german langid, while lewis gets classified as english and cheby as russian.

This mapping will classify entries via the occurence of Cyrillic characters in the title field: if it contains none the langid is set to english; if it does, it is set to russian.

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=title,
notmatch=\regexp{\p{cyrillic}},
final]
\step[fieldset=langid, fieldvalue=english]
}
\map{
\step[fieldsource=title,
match=\regexp{\p{cyrillic}},
final]
\step[fieldset=langid, fieldvalue=russian]
}
}
}


Output in the MWE is the same as above.

• Note that the optional question is also answered here. Because no fields are overwritten \DeclareSourcemap{\maps[datatype=bibtex]{\map{\step[fieldset=langid, fieldvalue=english]}}} will set all those entries to english that do not have a langid yet. – moewe May 25 '15 at 6:53