zepinglee / citeproc-lua

A Lua implementation of the Citation Style Language (CSL) for use with LaTeX
MIT License
66 stars 8 forks source link

Bug with lualatex and a nonbreakspace in the locale file #42

Closed hvoss49 closed 1 year ago

hvoss49 commented 1 year ago

Describe the bug running this with pdflatex or xelatex works fine. But running with lualatex the   in the file csl-locales-de-DE.xml which should be a non breakable space is for lualatex a linebreak (see image and the linebreak between u. a., which is et al in german).

If I change the   to   in the file csl-locales-de-DE.xml, (line no 77 , localisation for et-al), then it works for lualatex, but gives an error for pdflatex.

Additional information

To Reproduce

\documentclass{article}
\usepackage{libertinus}
\usepackage[ngerman]{babel}
\usepackage[style=modern-language-association]{citation-style-language}
\addbibresource{biblatex-examples.bib}
\begin{document}
~\parencite{aksin}
\printbibliography
\end{document}

Screenshots

Bildschirmfoto 2023-09-25 um 10 53 01
zepinglee commented 1 year ago

Thanks for your bug report and I can reproduce it. However I can’t solve it in the first try. Currently I’m on vacation and I’ll loot at it again after returning home.

zepinglee commented 1 year ago

This problem can be reproduced with the following minimal code and it's explained in https://tex.stackexchange.com/q/618254/82731. I'm planning to use tex.sprint("\\def...") mentioned in the comment.

\documentclass{article}

\usepackage{luacode}
% \usepackage[ngerman]{babel}

\begin{document}

\def\foo{}
\begin{luacode*}
  token.set_macro("foo", "u.~a.")
\end{luacode*}
% \show\foo
\foo

\end{document}
Screenshot 2023-10-02 at 12 22 54
zepinglee commented 1 year ago

If I change the   to   in the file csl-locales-de-DE.xml, (line no 77 , localisation for et-al), then it works for lualatex, but gives an error for pdflatex.

The citeproc-lua has a limited method to convert unicode to LaTeX and thin space is kept in the unicode form. Since this code point is not defined in utf8enc.dfu, it's not accepted by pdftex. How about converting it to \thinspace{}?

https://github.com/zepinglee/citeproc-lua/blob/e31cbe8b2156480e3557c93f5ead45eb59658c48/citeproc/citeproc-output.lua#L1761-L1770