zepinglee / citeproc-lua

A Lua implementation of the Citation Style Language (CSL)
MIT License
62 stars 7 forks source link

Duplicate citekeys discard bibliography #14

Closed michal-h21 closed 2 years ago

michal-h21 commented 2 years ago

When you have duplicate citekyes in the bibliography source file, Citeproc issues runtime error:

Module csl Error: Duplicate entry key "texbook" in "examples.bib". on input line 7

stack traceback:
        [C]: in function 'error'
        ...ocal/texlive/2022/texmf-dist/tex/latex/base/ltluatex.lua:110: in field 'module_error'
        ...ichal/texmf/scripts/citation-style-language/csl-core.lua:21: in function 'csl-core.error'
        ...ichal/texmf/scripts/citation-style-language/csl-core.lua:115: in upvalue 'read_data_files'
        ...ichal/texmf/scripts/citation-style-language/csl-core.lua:126: in function 'csl-core.make_citeproc_sys'
        ...ichal/texmf/scripts/citation-style-language/csl-core.lua:162: in function 'csl-core.init'
        /home/michal/texmf/scripts/citation-style-language/csl.lua:34: in function 'csl.init'
        [\directlua]:1: in main chunk.
\lua_now:e #1->\__lua_now:n {#1}

l.7 \begin{document}

What is worse, processing of the bibliography and in-text citations fails, nothing is produced. I've found this thanks to this question on TeX.sx.

Here is a MWE:

\documentclass{article}

\usepackage{citation-style-language}
\cslsetup{style = apa}
\addbibresource{examples.bib}

\begin{document}

\cite{texbook}
\printbibliography

\end{document}

examples.bib:

@book{texbook,
  author = {Donald E. Knuth},
  year = {1986},
  title = {The {TeX} Book},
  publisher = {Addison-Wesley Professional}
}

@book{texbook,
  author = {Donald E. Knuth},
  year = {1986},
  title = {The {TeX} Book},
  publisher = {Addison-Wesley Professional}
}
bdarcus commented 2 years ago

Notwithstanding error handling, technically a bib file with duplicate keys is invalid. So citeproc-lua should throw an error?

michal-h21 commented 2 years ago

Sure, it is invalid, so warning or error message would be fine.

zepinglee commented 2 years ago

The package follows BibTeX which raises an error in case of repeated keys. Since it's run inside LuaTeX, the error blocks the TeX interpreter and causes empty output.

The BibTeX error message:

Repeated entry---line 8 of file examples.bib
 : @book{texbook
 :              ,
I'm skipping whatever remains of this entry

Biber only given warnings in such cases:

WARN - Duplicate entry key: 'texbook' in file 'examples.bib', skipping ...

I suppose warning messages would be enough for duplicate entry keys.