0

I have a document written in both English and Hebrew. For some reason, English chapters title, number and name are not typed in the font I declared for English language text (Latin Modern Roman), but rather in the font set up for Hebrew.

Why is that?

Colors are added for visualization purpose.

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

\documentclass[openany,a5paper]{book}
\usepackage{polyglossia,xcolor}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\englishfont{Latin Modern Roman}[
    Script=Latin, 
    Language=English,
    Ligatures=TeX,
    Color=red]
\newfontfamily\hebrewfont{Arial}[
    Script=Hebrew, 
    Color=blue]

\begin{document}
\chapter{פרק ראשון}
טקסט טקסט טקסט.
\begin{english}
\chapter{this should be in Latin Modern}
Like this one is.
\end{english}
\end{document}

enter image description here

1
  • 1
    This might or might not be useful to you, but ``babel` with the bidi and layout=sectioning.tabular commands should be able to handle this. If you add babeltags, your document should be backward-compatible with \begin{english} or \texthebrew.
    – Davislor
    Commented Feb 6, 2022 at 20:21

1 Answer 1

1

This seems to be a problem with polyglossia. I found a solution here but it seemed incomplete. It adds font switching commands to the language switching command, but it didn't do that when you end a language environment, e.g. at \end{english}. I added that code, so that it sets up the language outside of the english environment, which normally should be hebrew. The scheme will probably not work with more complicated nested environments.

\documentclass[openany,a5paper]{book}
\usepackage{polyglossia,xcolor}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\englishfont{Latin Modern Roman}[
    Script=Latin, 
    Language=English,
    Ligatures=TeX,
    Color=red]
\newfontfamily\hebrewfont{Arial}[
    Script=Hebrew, 
    Color=blue]

% Add correction code, inspired by https://tex.stackexchange.com/a/325833/113546
\makeatletter
\def\xpg@set@normalfont#1{%
  \letcs{\rmfamily}{#1@font@rm}%
  \letcs{\sffamily}{#1@font@sf}%
  \letcs{\ttfamily}{#1@font@tt}%
  \def\normalfont{\protect\xpg@select@fontfamily{#1}}%def instead of gdef
  \def\reset@font{\protect\normalfont}%
}
\addto\inlineextras@english{\xpg@set@normalfont{english}}
\addto\blockextras@english{\xpg@set@normalfont{english}}
% Switch back explicitely to previous language
% This should normally be 'hebrew' outside 'english'.
\addto\endenglish{\selectlanguage{\babelname}}
\addto\inlineextras@hebrew{\xpg@set@normalfont{hebrew}}
\addto\blockextras@hebrew{\xpg@set@normalfont{hebrew}}
\makeatother

\begin{document}
\chapter{פרק ראשון}
טקסט טקסט טקסט.
\begin{english}
\chapter{this should be in Latin Modern}
Like this one is.
\chapter{Another test}
Some other text.
\end{english}

\chapter{פרק ארבע}
  טקסט טקסט טקסט.

\end{document}
2
  • Well done. I am too a novice Texnician to truly understand what xpg and letcs do, but I think I get the idea.
    – tush
    Commented Feb 6, 2022 at 20:28
  • I forgot to take out the \show\endotherlanguage. It was there for debugging. And after a \show TeX signals an error which really isn't an error. Commented Feb 6, 2022 at 21:44

You must log in to answer this question.

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