2

I use polyglossia to produce documents written in arabic, a Right-to-Left mode. I choose the main font with the command \setmainfont, with the option Scale=1.3 to obtain the suitable tail of the characters. Now this option produces with the command \mathbf{} a curious effect, so it seems to scale the mathbf argument, and have the same effect with the option \mbox{\bf }. How can I avoid this effect, so compile as within this option ?

I give the the file used:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setmainfont[Script=Arabic,Scale=1.3]{Arial}    % can use all fonts     % use or not the scale option

\begin{document}

$f(X)$ $f(\mathbf{X})$ $f(\mbox{\bf X})$

\end{document}

and its compilation, using the scale option:

enter image description here

and the other case, without this option (but I need it!) which is the good one:

enter image description here

  • I'm afraid your code snippet isn't compilable at present. Please tell us (a) whether you use XeLaTeX or LuaLaTeX, (b) whether you load the fontspec and/or unicode-math packages, and (c) which math font you employ. Incidentally, it's doubtful that the issue you're experiencing is related to the polyglossia package. You appear to be loading the text font scaled by a factor 1.3, but no such scaling appears to be applied to the math font. – Mico Sep 29 '18 at 18:37
  • I use the file what I give and I compile it with Xelatex... – Faouzi Bellalouna Sep 29 '18 at 19:56
3

The best way to get correct scaling is to use unicode-math and load all fonts with the Scale=MatchLowercase option. I’ve taken the liberty of writing this example with a set of free fonts by Khaled Hosny, one of the top experts on Arabic and Math fonts here, or in the world. Khaled Hosny credits Bulaq Press in Cairo as the inspiration for the Arabic typeface of Amiri. Libertinus is an extension of Linux Libertine, by Philipp H. Poll, and I’ll let Dr. Hosny speak to how it influenced Amiri’s Latin letters (Lowercase j is very different!), but his Amiri and Libertinus Math work together very well.

\documentclass[varwidth, preview, 12pt]{standalone}
\usepackage{polyglossia}
\usepackage{unicode-math}

\setdefaultlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\defaultfontfeatures{Scale=MatchLowercase}
\setmainfont{Libertinus Serif}[
  Scale=1.0,
  Ligatures={Common, TeX}]
\setsansfont{Libertinus Sans}[
  Ligatures={Common, TeX}]
\setmonofont{Libertinus Mono}[
  Ligatures=TeX]
\newfontfamily\arabicfont{Amiri}[
  Language=Arabic,
  Script=Arabic,
  Ligatures={Common, TeX}]
\setmathfont{Libertinus Math}

\begin{document}

\parbox{10em}{
الخط
\LRE{Amiri \textbf{Bold}}

\begin{english}
Libertinus Serif \textbf{Bold}
\end{english}

\LR{$f(X)$ $f(\mathbf{X})$ $f(\mbox{\bf X})$ $f(\symbfup{X})$}
}

\end{document}

Amiri/Libertinus Sample

I set all the text inside a narrow box in order to fit the image bidirectional text inside the width this site allows.

The $f(\symbfup{X})$ notation is what I would recommend with unicode-math. With that package, \mathbf is intended more for words in math mode, such as VELOCITY.

Changing the Fonts

That example is a good template to select your own fonts, but if you want to stick with the Libertinus family, you might want to use the package instead of setting up everything manually:

\documentclass[varwidth, preview, 12pt]{standalone}
\usepackage{polyglossia}
\usepackage{unicode-math}

\setdefaultlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\usepackage{libertinus-otf}
\defaultfontfeatures{Scale=MatchLowercase}
\newfontfamily\arabicfont{Amiri}[
  Language=Arabic,
  Script=Arabic,
  Ligatures={Common, TeX}]

\begin{document}

\parbox{10em}{
الخط
\LRE{Amiri \textbf{Bold}}

\begin{english}
Libertinus Serif \textbf{Bold}
\end{english}

\LR{$f(X)$ $f(\mathbf{X})$ $f(\mbox{\bf X})$ $f(\symbfup{X})$}
}

\end{document}

You can instead substitute any other font family you choose, but in that case, make sure that your fonts match. You can set your math letters to be the same as your text font by adding additional commands like:

\setmathfont[range=up]{Arial}
\setmathfont[range=it]{Arial Italic}
\setmathfont[range=bfup]{Arial Bold}
\setmathfont[range=bfit]{Arial Bold Italic}

Be sure to put these after your main \setmathfont.

I don’t need a Scale= option here because I previously declared \defaultfontfeature{Scale=MatchLowercase}. (Note that the main font overrides this with Scale=1.0 to remain at its natural size, and all other fonts in the document are scaled to match it.)

Also note that unicode-math replaces all the math alphabets, including \mathscr, \mathcal, \mathbb and so on. You can also set these individually. For example, to replace \mathcal and \mathbfcal (by default the same as \mathscr) with the versions from STIX Two Math, you can use:

\setmathfont[range={cal,bfcal},Scale=MatchUppercase]{STIX Two Math}

Or to restore the default \mathbb and \mathbbit alphabets:

\setmathfont[range={bb, bbit}, Scale=MatchUppercase]{Latin Modern Math}
  • Ok thank you for the answer, useful for my files. I have only the problem of the \mathbb command which has now a curious appearance. Why ? Is there a command which allows to obtain the usual appearence ? – Faouzi Bellalouna Sep 30 '18 at 7:59
  • @FaouziBellalouna You’re welcome. You can restore the default \mathbb and \mathbbit with \setmathfont[range={bb, bbit}, Scale=MatchUppercase]{Latin Modern Math} after your main \setmathfont, or substitute any other math font of your choice. You might take a look at Stix Two Math. You could even select any OpenType font you please as bb. – Davislor Sep 30 '18 at 8:10
  • 1
    All is ok now. Many thanks for your help and explanation – Faouzi Bellalouna Sep 30 '18 at 8:13
  • Hello and excuse me for re-commenting so later. After an update, when I compile this file, I have the following error message: ! Undefined control sequence. l.931 \file_get:nnN Have you an idea about the cause of that ? – Faouzi Bellalouna Apr 6 at 15:13
  • @FaouziBellalouna I can’t reproduce your bug. The version with \usepackage{libertinus-otf} still compiles for me with XeLaTeX on an up-to-date TeX Live 2018. That error message is from a package, so I’d report it to the maintainer. – Davislor Apr 6 at 16:42

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.