目录中的编号不支持希伯来数字

目录中的编号不支持希伯来数字

我注意到以下奇怪的现象:当使用希伯来语作为主要语言和阿拉伯数字时,目录中的编号是正确的,但当使用希伯来语字母作为数字时,它不起作用,即目录中的所有数字/字母都相同(但在页面本身上没有问题)。这是为什么?如何修复?

% !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}

答案1

这也许(我想礼貌一点……)是gloss-hebrew.ldf宏中的一个错误\hebrew@globalnumbers(如果这真的是一个错误,那么可能还有其他相同类型的错误)。

这是一个修复方法。我使用了 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}

在此处输入图片描述

附言:结果可能不是预期的那样。我不懂希伯来语……

请注意,在中可以发现gloss-hebrew.ldf

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

whose\protect看起来很可疑(不需要),因为\hebrewnumeral在 中定义的babel-hebrewalph.def是通过 声明的\newrobustcmd*

正如我在评论中提到的,这似乎是一种奇怪的政策。除了重新定义\@arabic这一点\arabic非常大胆之外,它还会破坏使用 LaTeX 计数器\arabic来获取明确数字的 LaTeX 软件包。

答案2

字体与该问题无关。

gloss-hebrew.ldf和 中也存在一些错误babel-hebrewalph.def,让我们来修复它们:

\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
          \advance\@tempcnta by -\@tempcntb\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}

在此处输入图片描述

.toc以下是更改后的文件内容:

\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}}

相关内容