2

I'm using xelatex with polyglossia to typeset a mixed English/Hebrew document, with the majority of the text in English. The body of the document is fine. The table of contents is the problem. I run into a problem where the table of contents has some entries going left-to-right and some going right-to-left.

All section heads have English text which should be set left-to-right both in the TOC and the document. However, some of the entries have RTL entries in the TOC.

The problem seems to be created by the use of the "hebrew" environment. If I use it then the next sectioning command that creates an entry in the TOC has the effect that the section heading itself is good (text going LTR), but the TOC is RTL.

A MWE and the resulting TOC is shown below. The actual section header in the main body is correct.

Experimenting I've found if I have an empty "hebrew" environment after the real one then that undoes the effect (as shown in the MWE below). But this doesn't work all the time so it's not a work-around.

Any help would be gratefully received.

\documentclass{article}


\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguage[numerals=hebrew]{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{Hadasim CLM}




\begin{document}

\tableofcontents

\newpage
\section{Chapter 1}

blah blah

\section{Chapter 2}

blah blah


\begin{hebrew}
 שֶׁהֶחֱיָנוּ וְקִיְּמָנוּ וְהִגִּיעָנוּ לַזְּמָן הַזֶּה.
\end{hebrew}

\begin{hebrew}
% deliberately empty
\end{hebrew}
\section{Other chapter}

\begin{hebrew}
 שֶׁהֶחֱיָנוּ וְקִיְּמָנוּ וְהִגִּיעָנוּ לַזְּמָן הַזֶּה.
\end{hebrew}

\section{And the last chapter}

Blah Blah Blah

\end{document}

Table of contents showing entries that are LTR and RTL

1
  • 1
    Welcome to TeX.SE!
    – Mensch
    Apr 7 at 11:18

1 Answer 1

2

Seems like a bug of polyglossia. Here is a possible solution:

\documentclass{article}


\usepackage{polyglossia}

\setdefaultlanguage{english}
\setotherlanguage[numerals=hebrew]{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{Hadasim CLM}

\makeatletter
\ExplSyntaxOn
\renewenvironment{otherlanguage}[2][]
{%
    % Get real current options (incl. defaults)
    \clist_clear_new:N \l_xpg_current_options
    \prop_map_inline:cn {xpg@current@options@#2}
    {
        \clist_put_right:Nn \l_xpg_current_options {##1=##2}
    }
    % Store current options and language on stack
    \polyglossia@stack@language:nn{\clist_use:Nn \l_xpg_current_options {,}}{#2}%
    \selectlanguage[#1]{#2}%
}
{%
    % restore previous language in aux file and remove closed one from stack
    \beginL\polyglossia@unstack@language:n{xpg@set@language@only@aux}\aftergroup\endL
}
\ExplSyntaxOff
\makeatother


\begin{document}
    
    \tableofcontents
    
    \newpage
    \section{Chapter 1}
    
    blah blah
    
    \section{Chapter 2}
    
    blah blah
    
    
    \begin{hebrew}
        שֶׁהֶחֱיָנוּ וְקִיְּמָנוּ וְהִגִּיעָנוּ לַזְּמָן הַזֶּה.
    \end{hebrew}
    
    \begin{hebrew}
        % deliberately empty
    \end{hebrew}
    \section{Other chapter}
    
    \begin{hebrew}
        שֶׁהֶחֱיָנוּ וְקִיְּמָנוּ וְהִגִּיעָנוּ לַזְּמָן הַזֶּה.
    \end{hebrew}
    
    \section{And the last chapter}
    
    Blah Blah Blah
    
\end{document}
10
  • Thanks for the prompt response -- I get the following error ! LaTeX Error: Command \xpg@set@language@only@aux undefined. Also I think you are right about polyglossia. In my post above, I was using Overleaf. I subsequently installed the fonts on my desktop and it works fine with an older version of polyglossia Apr 7 at 14:56
  • @ScottHazelhurst which version of polyglossia are you using?
    – Udi Fogiel
    Apr 7 at 14:59
  • Overleaf uses /usr/local/texlive/2022/texmf-dist/tex/latex/polyglossia/polyglossia.sty Package: polyglossia 2022/04/20 v1.56. This doesn't work. Apr 7 at 15:01
  • My desktop version which does work is polyglossia 2021/04/12 v1.53 Apr 7 at 15:02
  • @ScottHazelhurst I'm working with polyglossia 2023/02/11 v1.60...
    – Udi Fogiel
    Apr 7 at 15:03

You must log in to answer this question.

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