plk / biblatex

biblatex is a sophisticated bibliography system for LaTeX users. It has considerably more features than traditional bibtex and supports UTF-8
505 stars 114 forks source link

Biblatex fails to detect languages loaded with `\babelprovide` #1362

Open Mycroft-47 opened 1 month ago

Mycroft-47 commented 1 month ago

As suggested by @u-fischer on stackexchange, I'm opening this issue to report a problem with biblatex failing to detect languages loaded using \babelprovide from the babel package.

Description I'm experiencing a persistent warning Please rerun LaTeX when using biblatex in a multilingual document with babel (check this .log file). The warning only appears when I use a macro or environment that requires switching to a non-main language, specifically when using the otherlanguage environment with a non-main language as an option.

Here's a minimal example that reproduces the warning:

\documentclass{report}

\usepackage{babel}
\babelprovide[import=fr, main]{french}
\babelprovide[import=en]{english}

\usepackage{csquotes}
\usepackage{biblatex}

\addbibresource{biblatex-examples.bib}

\begin{document}

Donec varius orci eget risus.\cite{bertram}

\begin{otherlanguage}{english}
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\end{otherlanguage}

\printbibliography

\end{document}
moewew commented 1 month ago

Oh, this is going to be a bigger project.

I haven't yet looked at \babelprovide, which is a completely different way of loading languages than previously in babel (it doesn't use .ldf files, instead it uses .ini files), in depth. Unfortunately, a quick look suggests that none of our existing code can be used since one can do shenanigans of the following sort (where we load the Dutch language to define a language called english).

\listfiles
\documentclass{article}

\usepackage{babel}
\babelprovide[import=fr, main]{french}
\babelprovide[import=nl]{english}

\usepackage{csquotes}
\usepackage{biblatex}

\addbibresource{biblatex-examples.bib}

\begin{document}

Donec varius orci eget risus.\cite{bertram} \today

\begin{otherlanguage}{english}
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \today
\end{otherlanguage}

\today

\printbibliography

\end{document}
u-fischer commented 1 month ago

one can do shenanigans of the following sort

We discussed and agreed with the maintainer of the language package to provide data about the languages in bcp format. https://github.com/latex3/latex2e/issues/1035. The support is not fully complete (e.g. babel currently errors on the tag keyword), but the command is in the current LaTeX and the language key word is reliable and you can use it to detect languages:

\documentclass{article}

\usepackage{babel}
\babelprovide[import=fr, main]{quack}
\babelprovide[import=nl]{english}

\begin{document}
\today 

\languagename, \BCPdata{language}, \BCPdata{region}, \BCPdata{script}, 
%\BCPdata{tag} (errors in babel)

\begin{otherlanguage}{english}
\today

\languagename, \BCPdata{language}, \BCPdata{region}, \BCPdata{script}, 

\BCPdata{main.language}, \BCPdata{main.region}, \BCPdata{main.script}

\end{otherlanguage}

\end{document}

gives

image

If you miss something (e.g. a list of loaded languages) I would suggest to discuss that with the package maintainers so that they provide that in a uniform way.

moewew commented 1 month ago

Thanks, that looks like a good start. I think our problem though is that at the moment we build everything upon babel (classic babel that is) language identifiers. At the moment I can't see a way to obtain this name for .ini files (I can see name.babel in some of them, but it's not documented in the manual and \localeinfo{name.babel} errors).

polyglossia has \babelname and \mainbabelname to access the babel name of languages used etc.

But maybe we should be moving away from babl identifiers and go for BC47. See also https://github.com/plk/biblatex/issues/961, https://github.com/plk/biblatex/issues/160, but of course that requires careful consideration...

jbezos commented 3 weeks ago

Why not to use the basic syntax, namely,

\documentclass[english,french]{report}
\usepackage{babel}

(Or, if you want ini files, \usepackage[provide*=*]{babel}.) That way, languages can be detected by other packages.

It's a real question, to know if I can improve something.

pauloney commented 3 weeks ago

But it is Babel that is allowing users to deviate from standard naming, no? If Babel allowed only the use you describe above, the problem would be mute, no?

On Fri, Jun 14, 2024 at 8:41 AM Javier Bezos @.***> wrote:

Why not to use the basic syntax, namely,

\documentclass[english,french]{report}\usepackage{babel}

That way, languages can be detected by other packages.

— Reply to this email directly, view it on GitHub https://github.com/plk/biblatex/issues/1362#issuecomment-2168295748, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR7WYX7RALFXJ4A7GK74U3ZHMFLFAVCNFSM6AAAAABJA6FLRCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRYGI4TKNZUHA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jbezos commented 3 weeks ago

\babelprovide is not a general alternative to be used in any context and in any circumstance. From the manual: “In other words, \babelprovide is mainly meant as alternative when the ldf does not exists or does not work as expected, and for secondary tasks.” Particularly in French, the ldf is much preferred (https://latex3.github.io/babel/guides/locale-french.html). But my experience tells me users tend to use packages in quite ‘creative’ ways, which is great, but I’d like to know why, to improve them.

u-fischer commented 3 weeks ago

@jbezos

Why not to use the basic syntax, namely,

biblatex can not control what user do, and user use all syntax variants as they are examples of all of them everywhere (some of them e.g. using ini-files as intended to avoid problems with old ldf like the ones for arabic or hebrew).

So from the biblatex view they need reliable interface to detect the main and the current language for all these variants. And they need reliable interfaces to detect how to select a language, e.g. if the bib-file contains langid=french biblatex must know what do even if the user does something like \babelprovide[import=fr, main]{quack}

pauloney commented 3 weeks ago

I would go beyond what Ulrike said and add that detection of languages is extremely important even on settings where running a TeX command is not possible -- like for example -- a speller, where most parsing is done in Perl, and it has to separate the pieces of each language on separate files. Parsing such code with Perl to obtain the language of a string is awful and unreliable.

On Sat, Jun 15, 2024, 9:03 AM Ulrike Fischer @.***> wrote:

@jbezos https://github.com/jbezos

Why not to use the basic syntax, namely,

biblatex can not control what user do, and user use all syntax variants as they are examples of all of them everywhere (some of them e.g. using ini-files as intended to avoid problems with old ldf like the ones for arabic or hebrew).

So from the biblatex view they need reliable interface to detect the main and the current language for all these variants. And they need reliable interfaces to detect how to select a language, e.g. if the bib-file contains langid=french biblatex must know what do even if the user does something like \babelprovide[import=fr, main]{quack}

— Reply to this email directly, view it on GitHub https://github.com/plk/biblatex/issues/1362#issuecomment-2170075936, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR7WYWEPTUNXLI76VHQSP3ZHRQWFAVCNFSM6AAAAABJA6FLRCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZQGA3TKOJTGY . You are receiving this because you commented.Message ID: @.***>

cfr42 commented 3 weeks ago

\babelprovide is not a general alternative to be used in any context and in any circumstance. From the manual: “In other words, \babelprovide is mainly meant as alternative when the ldf does not exists or does not work as expected, and for secondary tasks.”

Judging by questions on SE, I do not think this is how users are treating this facility. And the manual is not clear enough on this point that I've felt confident telling somebody to prefer the old interface, even though I was well aware of that description. If you mean, 'do not use unless ...', it would be better to say so, imho. (Still people will use it, of course. Whatever you do, people will still do that.)