0

The following question builds on this answer.


The following LaTeX document is saved in a file whose path is ~/test.tex.

\documentclass{article}

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}

\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setmainfont{Arial}

\usepackage[english]{cleveref}
\appto{\captionshebrew}{%
   \crefname{theorem}{thm}{thms}%
}

\begin{document}

\begin{theorem}\label{t1}
This is the first theorem.
\end{theorem}

\begin{theorem}\label{t2}
This is the second theorem.
\end{theorem}

Here are references to~\cref{t1,t2}.

\end{document}

When the following commands are executed at the terminal:

> cd ~
> xelatex test
> xelatex test

a PDF file is generated at the path ~/test.pdf. When opened in a PDF viewer, the file displays as follows:

[![Referencing multiple labels][1]][1]

(Note that Hebrew is a right-to-left language.)

The word and between the references to the two theorems was injected automatically by cleverer. However, this connective is an English word, and therefore is not the correct word in the present context; it should have been the Hebrew counterpart וגם.

How can this be fixed?

2
  • copy from cleverref.sty a language definition (e.g. everything from \DeclareOption{italian}{% to the closing brace) in your preamble. This are around 200 lines. Then replace everything in a suitable way to define the hebrew language. Nov 14, 2022 at 11:57
  • @UlrikeFischer I've followed your suggestion, but it didn't work. See my answer below.
    – Evan Aad
    Nov 14, 2022 at 16:20

2 Answers 2

5

If you look into the cleveref code you can see that language support consist of two parts: At first a language option is defined, followed by a \cref@addlanguagedefs command which repeats everything. The second part is meant for multilingual documents.

But \cref@addlanguagedefs is currently broken if you use polyglossia: To test if a language has been loaded it uses an internal polyglossia command that no longer exists, so to make use of it you have to provide the missing commands for every language:

Move also the newtheorem declaration behind cleveref.

\documentclass{article}
\usepackage{amsthm}

\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\setmainfont{Arial}

\usepackage[english]{cleveref}

\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{claim}{Claim}

\makeatletter
%work around cleveref bug:
\providecommand\hebrew@loaded{}
\providecommand\english@loaded{}

\cref@addlanguagedefs{hebrew}
 {%
  \renewcommand{\crefrangeconjunction}{ AA }%
  \renewcommand\crefrangepreconjunction{ BB }%
  \renewcommand\crefrangepostconjunction{ CC }%
  \renewcommand{\crefpairconjunction}{ DD }%
  \renewcommand{\crefmiddleconjunction}{ EE }%
  \renewcommand{\creflastconjunction}{ FF }%
  \renewcommand{\crefpairgroupconjunction}{ GG }%
  \renewcommand{\crefmiddlegroupconjunction}{ HH }%
  \renewcommand{\creflastgroupconjunction}{ II }%
  \crefname{definition}{DEFINITION}{DEFINITIONS}%
  \crefname{theorem}{THEOREM}{THEOREMS}%
  \crefname{claim}{CLAIM}{CLAIMS}%
 }
\makeatother
\begin{document}

\begin{definition}\label{d1}
This is a definition.
\end{definition}

\begin{definition}\label{d2}
This is another definition.
\end{definition}

\begin{definition}\label{d3}
This is yet another definition.
\end{definition}

\begin{theorem}\label{t}
This is a theorem.
\end{theorem}

\begin{claim}\label{c}
This is a theorem.
\end{claim}

Here is a reference to~\cref{d1,d2,d3,t,c} based upon~\cref{d1,d2,t}.

\selectlanguage{english}
Here is a reference to~\cref{d1,d2,d3,t,c} based upon~\cref{d1,d2,t}.


\end{document}

enter image description here

8
  • Thank you. Unfortunately, I cannot use this solution, because it fails when amsthm's \newtheorem is replaced by thmtools's \declaretheorem. I need to use the thmtools package in order to work around a quirk (bug?) of the cleveref package, as suggested in this answer.
    – Evan Aad
    Nov 15, 2022 at 10:32
  • 2
    that is not a bug. See 6 Overriding the Cross-Reference Type in the cleveref documentation how to change the type of a label. Nov 15, 2022 at 10:36
  • Thank you, but the tools described in chapter 6 of the cleveref package are unable to solve the issue described in my other post. Chapter 6 describes how to alias a counter to a different name. This is helpful, as stated in chapter 6, "if you want multiple counters to use the same cross-reference format". But my case is the reverse: I want the same counter to use multiple cross-reference formats, since all the theorem environments I defined use the same counter, namely definition, in order for their numbering to be unified and continuous.
    – Evan Aad
    Nov 17, 2022 at 6:30
  • The chapter also mention the optional argument of label. Nov 17, 2022 at 7:04
  • 1
    yes, and it continues with If you need to do this frequently, it can become tedious specifying the label explicitly each time and then recommends aliascnt. See e.g. tex.stackexchange.com/a/258853/2388 for an implementation. Nov 17, 2022 at 9:06
0
\documentclass{article}
\usepackage{amsthm}

\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{claim}{Claim}

\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setmainfont{Arial}

\usepackage[english]{cleveref}

\newcommand{\crefrangeconjunction}{ AA }
\newcommand\crefrangepreconjunction{ BB }
\newcommand\crefrangepostconjunction{ CC }
\newcommand{\crefpairconjunction}{ DD }
\newcommand{\crefmiddleconjunction}{ EE }
\newcommand{\creflastconjunction}{ FF }
\newcommand{\crefpairgroupconjunction}{ GG }
\newcommand{\crefmiddlegroupconjunction}{ HH }
\newcommand{\creflastgroupconjunction}{ II }

\crefname{definition}{DEFINITION}{DEFINITIONS}
\crefname{theorem}{THEOREM}{THEOREMS}
\crefname{claim}{CLAIM}{CLAIMS}

\begin{document}

\begin{definition}\label{d1}
This is a definition.
\end{definition}

\begin{definition}\label{d2}
This is another definition.
\end{definition}

\begin{definition}\label{d3}
This is yet another definition.
\end{definition}

\begin{theorem}\label{t}
This is a theorem.
\end{theorem}

\begin{claim}\label{c}
This is a theorem.
\end{claim}

Here is a reference to~\cref{d1,d2,d3,t,c} based upon~\cref{d1,d2,t}.

\end{document}

Cleveref workout

Notes

  1. I don't know what the commands \crefmiddleconjunction and \creflastconjunction do, and would appreciate if someone tells me, so I can revise the above code and make it complete.

  2. The solution above is good only for a monolingual document in which the main, and essentially only, language is Hebrew. I don't know how to modify it for bilingual documents in which some parts have Hebrew as the main language, whereas other parts have English as the main language.

5
  • naturally you should remove the \DeclareOption{hebrew}{ (and the closing brace). That is for the package. You only need the content. Nov 14, 2022 at 16:21
  • @UlrikeFischer Oh, I see. What about the \usepackage[hebrew]{cleveref} line? should the option be hebrew, english, or none? And should the \usepackage line precede or succede the \DeclareOption block, or does it not matter? And what about the line \def\cref@language{hebrew} -- should I keep it, or delete it?
    – Evan Aad
    Nov 14, 2022 at 16:23
  • @UlrikeFischer I've removed the \DeclareOption{hebrew}{ (and the closing brace), as you suggested, but it still doesn't work. I've updated my answer accordingly.
    – Evan Aad
    Nov 14, 2022 at 16:59
  • 1
    Please do not post edits as answers to your questions. Instead, use the Edit link and edit your question. You can insert a horizontal line using --- as separator. Nov 14, 2022 at 17:04
  • 1
    Read the error message and make some educated guesses. Nov 14, 2022 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .