# Insert mono space and sans serif in other language mode

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

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

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}%
\gdef\reset@font{\protect\normalfont}%
}
\makeatother


Now you get:

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.