1

Suppose I am writing a document in Hebrew with English as the other language, using polyglossia:

\usepackage{xcolor}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}

\newfontfamily\hebrewfont[Script=Hebrew,Color=teal]{Hadasim CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew,Color=cyan]{IBM Plex Sans Hebrew}
\newfontfamily\hebrewfonttt[Script=Hebrew,Color=magenta]{Miriam CLM}
\newfontfamily\englishfont{TeX Gyre Bonum}[Script=Latin,Language=English,Color=brown]
\newfontfamily\englishfontsf{CMU Sans Serif}[Script=Latin,Language=English,Color=olive]
\newfontfamily\englishfonttt{Logix Mono}[Script=Latin,Language=English,Color=orange]
\begin{document}
טקסט רגיל

\texttt{טקסט מונו}

\textsf{סנס סריף}

\begin{english}
These letters are in brown color.

\textsf{This should be in olive color, and it isn't.}
\end{english}
\end{document}

Note: All those fonts are available from overleaf online editor, for your convenience.

Now I want to insert English language text in various faces. To insert roman font, just do

\textenglish{Your text}

or

\begin{english}
Your text
\end{english}

Now how do I insert English text in mono space and sans serif faces?

The last input line in the example should be colored in olive, according to my specification for the font. It isn't, which means that TeX is using neither CMU Sans Serif nor IBM Plex Sans Hebrew?

What am I missing here?

enter image description here

2
  • @Davislor I edited the original question.
    – tush
    Jan 10, 2022 at 8:38
  • 1
    Thanks, it’s much clearer to me now.
    – Davislor
    Jan 10, 2022 at 19:27

2 Answers 2

2

Referring to this answer https://tex.stackexchange.com/a/325833/255984, polyglossia has some trouble redefining fonts when multiple languages are used. Adding the following code to the preamble fixes the problem:

\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
  \gdef\reset@font{\protect\normalfont}%
}
\addto\inlineextras@english{\xpg@set@normalfont{english}}
\addto\blockextras@english{\xpg@set@normalfont{english}}
\makeatother

Now you get: enter image description here

0

The following is based on this answer.

According to the fontspec manual, Part II section 1, Main Commands, you have defined a command with which to insert those fonts:

\newfontfamily⟨cmd⟩{⟨font⟩}[⟨font features⟩]

Now use the language switching command \textenglish{} for short insertions of text and the environment \begin{english}...\end{english} for longer passages:

\textenglish{%
\englishfonttt{This is printed in the Logix Mono face, colored orange}
}
\begin{english}
\englishfontsf{And this is printed in the CMU Sans Serif face, in olive color}
\end{english}

Actually englishfont, englishfonttt and englishfontsf could be replaced by any other string(s) to be used as an allowed command name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.