验证 biblatex 语言字段

验证 biblatex 语言字段

biblatex支持在language字段中使用语言代码(在文档中列为表 2)。如果某些内容不是已知的语言代码之一,是否可以发出警告?例如,我希望自动发现engglish下面 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}

答案1

由于您想测试 支持的语言biblatex,因此您实际上可以测试 bibstring 是否lang<language>存在。当且仅当该语言在文档的表 2 中列出时,它才存在biblatex

因为language是一个字段,我们可以用index技巧来处理它的值。

\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}

这与

\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}}

language不同之处在于,第二种解决方案仅在打印时才会发出警告。

相关内容