3

Problem using polyglossia and cleveref (vanilla install). It is not using the selected language.

Example document, where it's used only package's supported languages:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{german}
\setotherlanguage{english}
\usepackage{cleveref}
\begin{document}
\section{Test1}\label{sec:test1}
Blablabla \Cref{sec:test1}.
\selectlanguage{english}
\section{Test2}\label{sec:test2}
Blablabla \Cref{sec:test2}.
\end{document}

The result is presented below. Note that before the second section, we have selected english as the current language, but it appears Abschnitt instead.

enter image description here

The following error also appears when using portuguese as main language (whether using variant=brazilian or not):

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

This problem is caused because cleveref defines the language brazilian instead of portuguese.

dexteritas
  • 9,161
LEo
  • 772
  • 1
    it helps to read the documentation: "Cleveref recognises these commands, so you should not pass language options to cleveref when using polyglossia." – Ulrike Fischer Jul 02 '22 at 16:17
  • is it new? 'cos I guess it did work previously... (on Overleaf version for example, it does) – LEo Jul 02 '22 at 21:47
  • No idea, I neither use polyglossia nor cleveref much. I only checked the documentation. – Ulrike Fischer Jul 02 '22 at 21:54
  • 1
    IMHO best would be to participate to add the missing support of another language to cleveref. See section 14.3 of the manual for more information. – cabohah Mar 13 '23 at 07:47
  • 2
    The OP's german/english code works as intended for me in TL 2021 but \Cref does not recognise the change in language in TL 2022. I cannot see how to apply the currently marked duplicate to the OP's current example. That said, I suspect this answer is a suitable duplicate candidate instead. – Dai Bowen Mar 16 '23 at 14:11
  • 2
    @LEo does this answer resolve or help with your current question? If I add \providecommand\german@loaded{} and \providecommand\english@loaded{} inside \makeatletter/\makeatother your current MWE appears to compile as intended. – Dai Bowen Mar 17 '23 at 17:05
  • @DaiBowen it did work! – LEo Mar 19 '23 at 14:01

1 Answers1

3

As pointed by @DaiBowem, this answer says that "\cref@addlanguagedefs is currently broken if you use polyglossia", the command to check if a a language has been loaded no longer exists. The fix is to provid those missing commands by adding:

\makeatletter
\providecommand\german@loaded{}
\providecommand\english@loaded{}
\makeatother

and the patched example will be:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{german}
\setotherlanguage{english}
\usepackage{cleveref}
\makeatletter
\providecommand\german@loaded{}
\providecommand\english@loaded{}
\makeatother
\begin{document}
\section{Test1}\label{sec:test1}
Blablabla \Cref{sec:test1}.
\selectlanguage{english}
\section{Test2}\label{sec:test2}
Blablabla \Cref{sec:test2}.
\end{document}

giving the expected result

enter image description here

LEo
  • 772