3

biblatex supports using language codes in the language field for an entry (listed as Table 2 in the docs). Is it possible to issue a warning, in case something is not one of the known language codes? For instance, I would have liked to automatically spot the typo in engglish in the MWE below.

MWE:

\documentclass{article}

\usepackage{filecontents}

\usepackage[style=alphabetic,backend=biber]{biblatex}
\bibliography{test}

\begin{filecontents}{test.bib}
@techreport{Volpe2000,
 author = {Wolpe, Richard and Nesnas, Issa A. D. and Estlin, Tara and Mutz, Darren and Petras, Richard and Das, Hari},
 date = {2000},
 institution = {Jet Propulsion Laboratory, California Institute of Technology},
 location = {Pasadena, California},
 language = {engglish},
 title = {{CLARAty}: Coupled Layer Architecture for Robotic Autonomy}
}
\end{filecontents}

\begin{document}
This is a test~\autocite{Volpe2000}.

\printbibliography{}
\end{document}
  • What would count as 'known' language code? The ones listed in the babel docs, the ones known by polyglossia, those languages for which biblatex has an .lbx? – moewe Nov 8 '17 at 13:45
  • @moewe There is a list of languages in the bibtex docs (Table 2). I thought that is the important one? – languitar Nov 8 '17 at 13:46
  • That is a reasonable assumption. – moewe Nov 8 '17 at 13:50
4

Since you want to test for languages supported by biblatex, you can actually test if the bibstring lang<language> exists. It exists if and only if the language is listed in Table 2 of the biblatex documentation.

Since language is a field, we can use the index trick to process its values.

\documentclass{article}
\usepackage{filecontents}
\usepackage[style=alphabetic,backend=biber]{biblatex}

\begin{filecontents}{\jobname.bib}
@techreport{Volpe2000,
 author = {Wolpe, Richard and Nesnas, Issa A. D. and Estlin, Tara and Mutz, Darren and Petras, Richard and Das, Hari},
 date = {2000},
 institution = {Jet Propulsion Laboratory, California Institute of Technology},
 location = {Pasadena, California},
 language = {engglish},
 title = {{CLARAty}: Coupled Layer Architecture for Robotic Autonomy}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\makeatletter
\DeclareIndexListFormat{language}{%
  \ifboolexpr{ test {\ifbibstring{#1}} or test {\ifbibstring{lang#1}} }
    {}
    {\blx@warning@noline{Unknown language '#1'
       in 'language' field of\MessageBreak
       '\thefield{entrykey}'}}}

\AtDataInput{\indexlist{language}}
\makeatother

\begin{document}
This is a test~\autocite{Volpe2000}.

\printbibliography
\end{document}

This is not much different from

\DeclareListFormat{language}{%
  \usebibmacro{list:delim}{%
    \ifbibstring{#1}
      {\bibxstring{#1}}
      {\ifbibstring{lang#1}
         {\bibxstring{lang#1}}
         {#1}}}%
  \ifbibstring{#1}
    {\bibstring{#1}}
    {\ifbibstring{lang#1}
       {\bibstring{lang#1}}
       {\blx@warning@noline{Unknown language '#1'
          in 'language' field of\MessageBreak
          '\thefield{entrykey}'}%
        #1}}%
  \usebibmacro{list:andothers}}

The difference being that with the second solution the warning is only issued if language is printed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.