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}