2

In a Hebrew document, I changed the fonts as in the MWE below.

The thing is that when I have some text typed inside \text{…}, the font used to print it is not the font used for math.

How do I fix it?

I tried the no-math for fontspec but it doesn't help.

The output now:

image 01

whereas I want the "sec" to be printed with "Latin Modern Math":

image 02

MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[no-math]{fontspec}
\usepackage{polyglossia}
\newfontfamily\hebrewfont{Arial}[Script=Hebrew]
\newfontfamily\englishfont{TeX Gyre Bonum}[Script=Latin, Language=English]
\setmathrm{Latin Modern Math} 
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\DeclareTextFontCommand{\emph}{\boldmath\bfseries}
\begin{document}
אבג דהו $\Delta t=1\ \text{sec}$ זחט יכל.
\end{document}
3
  • You should not be using \text for this, it does not do what you think. For typesetting numbers and units use the siunitx package. Note for example that \ is the wrong space between number and unit
    – daleif
    Sep 8, 2022 at 17:10
  • @daleif Hmm no directly related, but loading the siunitx anywhere in the preamble gives the error "Package bidi Error: Oops! you have loaded package color after bidi package. Please load package color before bidi package, and then try to run xelatex on your document again." Is there a known problem with these two packages?
    – tush
    Sep 8, 2022 at 18:09
  • on the other hand I cannot test any of your code as I don't have any of the fonts.
    – daleif
    Sep 9, 2022 at 8:21

2 Answers 2

5

The simplest solution is to use \mathrm instead of \text. This defaults to the main document font, but you can change it with \setmathrm{Latin Modern Roman}. Also use ~ for a non-breaking space.

\documentclass{article}
\tracinglostchars=3 % Make it an error to use the wrong font for the current language.
\usepackage{amsmath}
\usepackage{polyglossia}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
\newfontfamily\hebrewfont{Arial}[Script=Hebrew]
\newfontfamily\englishfont{TeX Gyre Bonum}[Script=Latin, Language=English]
\setmathrm{Latin Modern Roman} 
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\DeclareTextFontCommand{\emph}{\boldmath\bfseries}

\begin{document}
אבג דהו $\Delta t=1\mathrm{~sec}$ זחט יכל.
\end{document}

Font sample

In practice, you probably want to make commands for this, such as \sec or \unit{s}, but at that point you might seriously consider siunitx. You will seriously thank yourself later for using semantic markup that lets you change the formatting of your units or your vectors in a single place. Otherwise, hunting down all the \mathrm commands that format units, and only those that do, will be a major headache when you have to change it later.

i took the liberty of adding a command to stop you from trying to display Hebrew in a font that doesn’t support it, and to automatically rescale the fonts to the same x-height.

Side Notes

By the way, I answered the question as asked, but this isn’t a selection of fonts I would use by choice. You might get some more harmonious-looking traditional fonts with:

\documentclass{article}
\tracinglostchars=3 % Make it an error to use the wrong font for the current language.
\usepackage{unicode-math}
\usepackage{polyglossia}

\defaultfontfeatures{ Scale=MatchUppercase, Ligatures=TeX }
% The Culmus fonts are available at https://culmus.sourceforge.io/download.html
\newfontfamily\hebrewfont{Frank Ruehl CLM}[Script=Hebrew]
\newfontfamily\englishfont{TeX Gyre Schola}
\setmathfont{TeX Gyre Schola Math}
\setmathrm{TeX Gyre Schola}

\setdefaultlanguage{hebrew}
\setotherlanguage{english}

\DeclareTextFontCommand{\emph}{\boldmath\bfseries}

\begin{document}
אבג דהו $\Delta t=1\mathrm{~sec}$ זחט יכל.
\end{document}

Frank Ruehl CLM + Schola sample

This uses the fonts from the Culmus Project.

Or, if you want to stay with Arial and use a math font that matches it better:

\documentclass{article}
\tracinglostchars=3 % Make it an error to use the wrong font for the current language.
\usepackage{unicode-math}
\usepackage{polyglossia}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
\newfontfamily\hebrewfont{Arial}[Script=Hebrew]
\newfontfamily\englishfont{Fira Sans}
\setmathfont{Fira Math}
\setmathrm{fira Sans}

\setdefaultlanguage{hebrew}
\setotherlanguage{english}

\DeclareTextFontCommand{\emph}{\boldmath\bfseries}

\begin{document}
אבג דהו $\increment t=1\mathrm{~sec}$ זחט יכל.
\end{document}

Fira sample

(There is also [a fork of Fira, FiraGO, that supports Hebrew.)

Or, a good companion font for Computer Modern might be:

\documentclass{article}
\tracinglostchars=3 % Make it an error to use the wrong font for the current language.
\usepackage{fontspec}
\usepackage{polyglossia}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
% Frank Ruhl Libre is available from:
% https://opensiddur.org/wp-content/uploads/fonts/display-font-charmap.php?fnt=FrankRuhlLibre
\defaultfontfeatures[FrankRuhlLibre]{ UprightFont = *-Light ,
                                      BoldFont = *-Medium ,
                                      Extension = .ttf ,
                                      Scale = 0.85 }

\newfontfamily\hebrewfont{FrankRuhlLibre}[Script=Hebrew, Language=Hebrew]
\newfontfamily\englishfont{Latin Modern Roman}
\setmathrm{Latin Modern Roman}

\setdefaultlanguage{hebrew}
\setotherlanguage{english}

\DeclareTextFontCommand{\emph}{\boldmath\bfseries}

\begin{document}
\emph{ אבג דהו $\Delta t=1\mathrm{~sec}$ זחט יכל}

אבג דהו $ \Delta t=1\mathrm{~sec}$ זחט יכל.
\end{document}

Frank Ruhl Libre + Latin Modern sample

Where you can download the Hebrew font from OpenSiddur.

As a historical aside, Hayyim Selig Slonimski, a leader of the nineteenth-century Maskilim and one of the first to publish scientific works in Hebrew, used Drugulin in the body of his books published in Warsaw. That would be an unusual choice today! (But if you were inclined to, the Taamey Ashkenaz font from Culmus with Times is a close approximation.)

Post-Post-Script

As requested, an example using siunitx:

\documentclass{article}
\tracinglostchars=3 % Make it an error to use the wrong font for the current language.
\usepackage{amsmath}
\usepackage{polyglossia}
\usepackage[mode=math,
            propagate-math-font=true,
            reset-math-version=false
           ]{siunitx}

\defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX }
\newfontfamily\hebrewfont{Arial}[Script=Hebrew]
\newfontfamily\englishfont{TeX Gyre Bonum}
\setmathrm{Latin Modern Roman}
\setboldmathrm{LM Roman 10 Bold}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\DeclareTextFontCommand{\emph}{\boldmath\bfseries}

\begin{document}
\emph{ אבג דהו $\Delta t=\qty{1}{\second}$ זחט יכל} \\
אבג דהו
\( \Delta t=\qty{1}{\second} \)
זחט יכל.
\end{document}

Bad font sample, with working \emph.

I turned off the reset-math-version package option because the redefinition of \emph suggests you’re using \boldmath and want it to propagate to your units. You might want to \setboldmathrm to make this work properly.

You can also reduce the spacing in some circumstances with the tight-spacing option, or use a font other than \mathrm with the unit-font-command= option.

11
  • I'd say ~ is too large as a unit space, \, would be better. BTW, I don;t have the hebrew fonts from any of your examples, do you mind testing siunitx with your example (per OPs comment above).
    – daleif
    Sep 9, 2022 at 8:23
  • 2
    @daleif Okay, added an example with siunitx.
    – Davislor
    Sep 9, 2022 at 8:49
  • @Davislor I couldn't ask for a more elaborated answer. Beautiful. But, I just checked your first MWE, and tried to change mathrm{sec} to mathbf{sec} and nothing is changed. Why is that?
    – tush
    Sep 9, 2022 at 13:43
  • @Davislor the selection of fonts was just for demonstration reasons, picking a font (Arial) that should be available to the preponderance of the users here.
    – tush
    Sep 9, 2022 at 13:44
  • 1
    @tush Because I erroneously copied \setmathrm{Latin Modern Math} from the question, which I should have corrected to \setmathrm{Latin Modern Roman}. i said so above, but neglected to do so in the MWE itself.
    – Davislor
    Sep 9, 2022 at 17:12
1
\newfontfamily\lmmath{Latin Modern Math}
\NewCommandCopy{\oldtext}{\text}
\RenewDocumentCommand{\text}{m}{\oldtext{\lmmath #1}}

Add these to preamble. enter image description here

2
  • That works, but is there an other way of doing it without introducing a new font family?
    – tush
    Sep 8, 2022 at 16:05
  • You should read the amstext document. The \text macro allows the user to insert “normal text” into math formulas. If you must use \text, this is the better solution I can think of at present. Or it's possible that you don't know the function of \text very well. Instead of typesetting with mathematical font, it's to insert the normal text in the normal text font.
    – Clara
    Sep 8, 2022 at 16:12

You must log in to answer this question.

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