First, note that the command you want is \textnormal
, not \text
—especially with DavidCLM and amsthm
. If you use \text
inside a theorem statement, which is italicized, it will inherit the italic formatting of the text around it. And your English and Hebrew italics slant in opposite directions! Using \textnormal
resets all text formatting, which is what you want here.
Babel in LuaTeX can detect which language you’re typing in and change fonts automatically. With this set-up, \textenglish
, \begin{hebrew}
, etc. still work, but they won’t usually do anything because the script you’re typing in will change languages automatically and override them.
If you need to alternate complete paragraphs in English and Hebrew, this won’t be adequate: the layout will stay right-to-left even in English sections. You would need to remove the onchar=
options and go back to \textenglish
and \begin{english}
.
Again, this MWE requires LuaLaTeX. (Since you use Mapping=
, you appear to be compiling in XeTeX.)
\documentclass[a4paper]{article}
\tracinglostchars=2
\usepackage{amsmath,amsthm}
\usepackage[bidi=basic,
layout=sectioning.tabular,
nil
]{babel}
\usepackage{unicode-math}
\defaultfontfeatures{ Scale=MatchUppercase,
Ligatures=TeX,
Renderer=HarfBuzz }
% The Culmus fonts are free for download at
% https://sourceforge.net/projects/culmus/
\defaultfontfeatures[DavidCLM]{
UprightFont = *-Medium,
ItalicFont = *-MediumItalic,
BoldFont = *-Bold,
BoldItalicFont = *-BoldItalic,
Extension = .otf }
\defaultfontfeatures[MiriamCLM]{
UprightFont = *-Book,
BoldFont = *-Bold,
Extension = .ttf }
\babelprovide[import, onchar=ids fonts]{english}
\babelfont{rm}
[Scale=1.0, Language=Default]{NewComputerModernBook}
\babelfont{sf}
[Language=Default]{NewComputerModernSansBook}
\babelfont{tt}
[Language=Default]{NewComputerModernMonoBook}
\babelprovide[import, main, onchar=ids fonts]{hebrew}
\babelfont[hebrew]{rm}
[Language=Default]{DavidCLM}
\babelfont[hebrew]{sf}
[Language=Default]{MiriamCLM}
\babelfont[hebrew]{tt}
[Language=Default]{MiriamMonoCLM}
\setmathfont{NewCMMath-Book}
\setmathrm{NewComputerModernBook}
\setmathsf{NewComputerModernSansBook}
\setmathtt{NewComputerModernMonoBook}
\babeltags{english=english} % Enable \textenglish, \begin{english}, etc.
\babeltags{hebrew=hebrew} % Enable \texthebrew, \begin{hebrew}, etc.
\begin{document}
\noindent שלום Hello
\[
y=\underbrace{x+z}_{\textnormal{const}}=\textnormal{abc}=\mathrm{abc}
\]
\end{document}

If you are going back to explicit language tagging, or you want to stick with Polyglossia, there are two quick fixes. One is to define a new command like \mathtext
or \mathen
as a shortcut for \textnormal{\textenglish{...}}
. The other is to wrap your equations in \begin{english}
and \end{english}
so that the \text
commands default to your English font. At least use \textup
instead of \text
in this case, so you don’t have a head-on collision of italics that slant left and right.
\documentclass[a4paper]{article}
\tracinglostchars=2
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\defaultfontfeatures{ Scale=MatchUppercase,
Ligatures=TeX }
\setmainfont[Script=Hebrew, Scale=1.0]{David CLM}
\newfontfamily{\englishfont}{Latin Modern Roman}
\setmathrm{Latin Modern Roman}
\newcommand\mathtext[1]{\textnormal{\textenglish{#1}}}
\begin{document}
\noindent שלום \textenglish{Hello}
\begin{english}\[
y=\underbrace{x+z}_{\mathtext{const}}=\textup{abc}=\mathrm{abc}
\]\end{english}
\end{document}
\text
is the wrong command to use here in the first place. It is not a device to providing upright text (add\itshape
before your math and see why).