# Numbering in TOC does not work with Hebrew numerals

I have noticed the following odd behavior: With Hebrew as main language and Arabic numerals the numbering in the table of contents is just as it should be, but with Hebrew letters as numerals it does not work, i.e. all the numbers/letters are the same in the table of contants (but on the pages itself it is fine). Why is that? How can it be fixed?

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex

\documentclass[14pt,a4paper]{scrbook}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage[calendar=hebrew,numerals=hebrew]{hebrew}

\newfontfamily{\hebrewfont}[Mapping=tex-text,Scale=0.80,Script=Hebrew]{David CLM}

\setmainfont[Mapping=tex-text]{David CLM}
\setsansfont[Mapping=tex-text]{David CLM}
\setmonofont[Mapping=tex-text]{David CLM}

\begin{document}

\tableofcontents

\chapter{כותרת}
\section{עוד משהו}

\chapter{כותרת}
\section{עוד משהו}

\chapter{כותרת}
\section{עוד משהו}

\end{document}

• I don't have the David CLM font, but with Ezra SIL instead of it, I can reproduce this strange output. However, during compiling I get the message LaTeX Font Warning: Some font shapes were not available, defaults substituted. and this is from the command \tableofcontents – Micha May 7 '13 at 4:41
• I see the behaviour with Ezra SIL as well. – Johannes_B Mar 29 '15 at 15:52

This is perhaps (I wanted to be polite...) a bug in gloss-hebrew.ldf macro \hebrew@globalnumbers (if this is really a bug, there are others of the same type probably).

Here is a fix. I used fonts available by default on my Mac OS X.

\documentclass[14pt,a4paper]{scrbook}
%\listfiles % for help in finding in the source of the bug

\usepackage{fontspec}

\usepackage{polyglossia}

\setmainlanguage[calendar=hebrew,numerals=hebrew]{hebrew}

\makeatletter
\def\hebrew@globalnumbers{%
\let\orig@arabic\@arabic%
\def\@arabic ##1{\expandafter\hebrewnumber\expandafter{\number ##1}}%
\renewcommand\thefootnote{\protect\hebrewnumber{\c@footnote}}%
}
\makeatother

\newfontfamily{\hebrewfont}[Mapping=tex-text,
Scale=0.80,
Script=Hebrew]{Arial Hebrew}

\setmainfont[Mapping=tex-text]{Arial Hebrew}
\setsansfont[Mapping=tex-text]{Arial Hebrew}
\setmonofont[Mapping=tex-text]{Arial Hebrew}

\begin{document}
\tableofcontents

\chapter{כותרת}

\section{עוד משהו}

\chapter{כותרת}
\section{עוד משהו}

\chapter{כותרת}
\section{עוד משהו}

\end{document}


PS: perhaps the outcome is not the one expected. I don't know hebrew...

Notice that one finds in gloss-hebrew.ldf :

\def\hebrewnumber#1{%
\if@hebrew@numerals
\protect\hebrewnumeral{#1}%
\else
\number#1%
\fi
}


whose \protect appears dubious (unneeded) because \hebrewnumeral which is defined in babel-hebrewalph.def is declared via \newrobustcmd*.

As I mentioned in comment, this seems strange policy. Besides redefining \@arabic hence \arabic is very daring, it will break LaTeX packages which use \arabic with LaTeX counters to get explicit digits.

• I have my doubts about the \hebrewnumber as above. In the false case, \number#1% indicates that the macro should only be used only with \count registers. In the context of this question the \if@hebrew@numerals is \iftrue thus no problem. But if #1 is a sequence of explicit digit tokens, then there could be some impact on external material (if more digits follow, some later space will disappear). – user4686 Mar 29 '15 at 17:57

Fonts have nothing to do with the problem.

There are several errors in gloss-hebrew.ldf and also in babel-hebrewalph.def, let's fix them:

\documentclass[14pt,a4paper]{scrbook}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage[calendar=hebrew,numerals=hebrew]{hebrew}

\newfontfamily{\hebrewfont}[Mapping=tex-text,Scale=0.80,Script=Hebrew]{Taamey David CLM}

\setmainfont[Mapping=tex-text]{Taamey David CLM}
\setsansfont[Mapping=tex-text]{Taamey David CLM}
\setmonofont[Mapping=tex-text]{Taamey David CLM}

\makeatletter
\renewcommand*\hebrewnumeral[1]{%
\expandafter\@hebrew@numeral\expandafter{\the\numexpr#1}%
}
\renewcommand*\Hebrewnumeral[1]{%
\expandafter\@Hebrew@numeral\expandafter{\the\numexpr#1}%
}
\renewcommand*\Hebrewnumeralfinal[1]{%
\expandafter\@Hebrew@numeralfinal\expandafter{\the\numexpr#1}%
}
\renewrobustcmd*{\@hebrew@numeral}[1]      % no apostrophe, no final letters
{{\@gim@finalfalse\@gim@apostfalse\@hebrew@@numeral{#1}}}
\newrobustcmd*{\@Hebrew@numeral}[1]      % apostrophe, no final letters
{{\@gim@finalfalse\@gim@aposttrue\@hebrew@@numeral{#1}}}
\newrobustcmd*{\@Hebrew@numeralfinal}[1] % apostrophe, final letters
{{\@gim@finaltrue\@gim@aposttrue\@hebrew@@numeral{#1}}}
\newcommand*{\@hebrew@@numeral}[1]{%
\ifnum#1<\z@\space\xpg@warning{Illegal value (#1) for Hebrew numeral}%
\else
\@tempcnta=#1\@tempcntb=#1\relax
\divide\@tempcntb by 1000
\ifnum\@tempcntb=0\gim@nomil\@tempcnta\relax
\else{\@gim@apostfalse\@gim@finalfalse\@hebrew@numeral\@tempcntb}׳%
\multiply\@tempcntb by 1000\relax
\gim@nomil\@tempcnta\relax
\fi
\fi
}
\def\hebrewnumber#1{%
\if@hebrew@numerals
\hebrewnumeral{#1}%
\else
\number#1%
\fi
}
\def\hebrew@globalnumbers{%
\let\orig@arabic\@arabic%
\let\@arabic\hebrewnumber%
\renewcommand\thefootnote{\hebrewnumber{\c@footnote}}%
}
\def\nohebrew@globalnumbers{%
\let\@arabic\orig@arabic%
\renewcommand\thefootnote{\@arabic\c@footnote}%
}
\makeatother

\begin{document}

\tableofcontents

\chapter{כותרת}
\section{עוד משהו}

\chapter{כותרת}
\section{עוד משהו}

\chapter{כותרת}
\section{עוד משהו}

\end{document}


Here's the contents of the .toc file after the changes:

\select@language {hebrew}
\contentsline {chapter}{\numberline {\@hebrew@numeral {1}}כותרת}{\@hebrew@numeral {3}}
\contentsline {section}{\numberline {\@hebrew@numeral {1}‏.‏\@hebrew@numeral {1}}עוד משהו}{\@hebrew@numeral {3}}
\contentsline {chapter}{\numberline {\@hebrew@numeral {2}}כותרת}{\@hebrew@numeral {5}}
\contentsline {section}{\numberline {\@hebrew@numeral {2}‏.‏\@hebrew@numeral {1}}עוד משהו}{\@hebrew@numeral {5}}
\contentsline {chapter}{\numberline {\@hebrew@numeral {3}}כותרת}{\@hebrew@numeral {7}}
\contentsline {section}{\numberline {\@hebrew@numeral {3}‏.‏\@hebrew@numeral {1}}עוד משהו}{\@hebrew@numeral {7}}