reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
190 stars 51 forks source link

Undefined control sequence using polyglossia and cleveref #562

Closed leolca closed 2 years ago

leolca commented 2 years ago

Problem using polyglossia and cleveref. The following error appears when using portuguese as main language (whether using variant=brazilian or not):

! Undefined control sequence.
\__hook begindocument ...ame extras\cref@language
                                                  \endcsname }\@ifundefined ...

The sample code is presented below:

\documentclass{article}
\usepackage{polyglossia}
%\setmainlanguage[variant=american]{english}
%\setotherlanguage[variant=brazilian]{portuguese}
\setmainlanguage[variant=brazilian]{portuguese}
\setotherlanguage[variant=american]{english}
\usepackage{cleveref}
\selectlanguage{english}
\begin{document}
\section{Test}\label{sec:test}
Blablabla \Cref{sec:test}.
\end{document}
jspitz commented 2 years ago

It works if you use \usepackage[brazilian]{cleveref} In any case, this does not look like a polyglossia bug to me. Rather a cleveref deficiency.

jspitz commented 2 years ago

The cleveref documentation notes that

Cleveref supports a number of languages other than English, and also sup-
ports the babel and polyglossia packages for those languages. Either pass
the desired language as an option to cleveref, or pass it as a global option
to \documentclass.

Also the manual categorizes it as a "non-bug" that

If you are using babel, you must still pass the appropriate language option
to cleveref, as well as to babel. Passing it to babel alone is not sufficient
(you will get the default English cross-reference formats). The best way to
set the document language is as a global option in the \documentclass line.

so what you observe is not a bug but by design. You could file an enhancement request to the cleveref author that he should track the loaded languages (e.g. via the tracklang package) and then automatically handle those.

In any case, nothing to do on the polyglossia side.