1

I am using both \mathscr and \mathcal to different meanings and expecting different characters to appear.

I recently switched to XeTeX and started using new fonts (TeX Gyre Pagella in this example) with the packages fontspec and unicode-math. As suggested by the answer to this question, I override \mathcal and \mathscr with characters coming from a different font (XITS-math).

Unfortunately this has the effect of mangling the setting of a (seemingly) unrelated math symbol : the nth root.

\documentclass{minimal}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}
% Math font overrides ----
\setmathfont[range={\mathcal,\mathbfcal},
             StylisticSet=1,Extension=.otf,BoldFont=*bold]{xits-math}
\setmathfont[range=\mathscr,Extension=.otf,BoldFont=*bold]{xits-math}

\begin{document}
Some math letters:
\[ \mathbb{C} \mathcal{C} \mathscr{C} \mathfrak{C} \]

Here's a big $n$-th root:
\[ F_k(x,y,z)  = \sqrt[n]{\sum_{i=1}^{k} f_i^n} \,. \]
\end{document}

This code produces the following result: Mangled nth root All Cs are different, but the n is too close from the radical symbol (√).

Commenting out the math font overrides yield the correct result for the nth root (but \mathcal and \mathscr now produce identical characters): correct nth root

My questions are then

  • Why does overriding \mathscr and \mathcal affects the setting of the nth root ?
  • How can I avoid this problem ? (or do I have to change fonts ?)
  • 1
    while waiting for experts you can use \sqrt[n\;] to improve the looks... – user4686 Oct 26 '17 at 13:43
  • \setmathfont overwrites the math fontdimens, and the one from xits are not suitable for pagella. There is no good solution for this problem, see e.g. tex.stackexchange.com/a/375243/2388. – Ulrike Fischer Oct 26 '17 at 14:02
  • @UlrikeFischer is it theoretically envisionable that unicode-math avoids overriding math fontdimens not relevant for \mathcal, \mathscr range? – user4686 Oct 26 '17 at 15:05
  • This particular situation will be fixed in the next version of unicode-math. (Assuming that the first maths font loaded is the one that drives the majority of the formatting.) – Will Robertson Jan 3 '18 at 6:53
3

Edit

Imho with a current unicode-math (2/2018) this is no longer needed.

=====

It looks as if it could work if you reset the fontdimens:

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{TeX Gyre Pagella Math}

\ExplSyntaxOn 
 %store the values
\int_step_inline:nnnn {1}{1}{65}{\tl_set:cx{l_tmp_fontdimen_#1_tl}{\the\fontdimen #1  \l__um_font }}
\ExplSyntaxOff

% Math font overrides ----
\setmathfont[range={\mathcal,\mathbfcal},
             StylisticSet=1,Extension=.otf,BoldFont=*bold]{xits-math}
\setmathfont[range=\mathscr,Extension=.otf,BoldFont=*bold]{xits-math}


\ExplSyntaxOn
%restore the values
\int_step_inline:nnnn {1}{1}{65}{\fontdimen #1  \l__um_font =\tl_use:c{ l_tmp_fontdimen_#1_tl}}
\ExplSyntaxOff



\begin{document}
Some math letters:
\[ \mathbb{C} \mathcal{C} \mathscr{C} \mathfrak{C} \]

Here's a big $n$-th root:
\[ F_k(x,y,z)  = \sqrt[n]{\sum_{i=1}^{k} f_i^n} \,. \]
\end{document}

But this is quite experimental ... and only tested with xelatex. (And probably they are still wrong for the other math styles).

enter image description here

  • This seems to work, thanks ! Additionally LuaLaTeX did not have this problem, so another solution could be using LuaLaTeX instead of XeTeX – Louen Oct 26 '17 at 15:48
  • 1
    The root is defined differently in both engines but with lualatex you can get similar problems. See e.g. tex.stackexchange.com/a/364328/2388. – Ulrike Fischer Oct 26 '17 at 16:03

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.