# Inconsistent script sizes with STIX Two and unicode-math

With unicode-math, it is recommended to use \symup to get upright symbols in math-mode, and to use \textnormal to get upright text, e.g. for text label subscripts. When using the STIX Two fonts, these two commands give inconsistent results.

\documentclass{article}

\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}

\begin{document}
$\textnormal{AVfi}_{\textnormal{AVfi}_\textnormal{AVfi}} \qquad \symup{AVfi}_{\symup{AVfi}_\symup{AVfi}}$
\end{document}


In the left case, we get nice kerning, and ligatures, but the font size in the subscripts are bad. In the right case, the font size in the subscripts is good, but the kerning and ligatures are bad.

I think the problem is that STIX Two Text doesn't contain the correct glyphs for optical sizes in subscripts.

Is it possible to get good kerning, ligatures, and sizing without modifying the font files? If not, is there an easy way to achieve the desired result using fontforge? I can live without the ligatures, if this causes problems.

• Note, thet it's recommended to use \symup to get symbols in math mode, and not words. – Sergei Golovan Dec 23 '16 at 15:29
• @SergeiGolovan I know. I only used it here to illustrate the difference in optical sizes. – Håkon Marthinsen Dec 23 '16 at 15:31
• in addition to what @SergeiGolovan says, there will never be ligatures among math symbols, at least not the "f" kind. – barbara beeton Dec 23 '16 at 15:31
• @barbarabeeton My intent wasn't to get ligatures among math symbols. I want to use \textnormal with the sizing achieved using \symup. – Håkon Marthinsen Dec 23 '16 at 15:32
• I'm not sure STIX Two Text has optical sizes for subscripts and superscripts, like STIX Two Math. It's easy to remove the optical sizes in the math font. – egreg Dec 23 '16 at 16:00

Optical sizes for letters are chosen at certain font sizes in math mode.

Here's an experiment: you can see that the +ssty=0 or +ssty=1 features are not honored in text (second line).

What you can do is disabling optical sizes in math (fourth line).

\documentclass{article}

\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}[
SizeFeatures={
{Size={9-}},
{Size={6-9},RawFeature={+ssty=0}},
{Size={-6},RawFeature={+ssty=1}},
},
]
\newfontfamily{\stixmath}{STIX Two Math}[
SizeFeatures={
{Size={9-}},
{Size={6-9},RawFeature={+ssty=0}},
{Size={-6},RawFeature={+ssty=1}},
},
]
\setmathfont{STIX Two Math}
\setmathfont{STIX Two Math}[
version=test,
script-features={},
sscript-features={}
]

\begin{document}

AVfi{\footnotesize AVfi}{\tiny AVfi}

{\stixmath AVfi{\footnotesize AVfi}{\tiny AVfi}}

$\textnormal{AVfi}_{\textnormal{AVfi}_\textnormal{AVfi}}$

{\mathversion{test}$\symup{AVfi}_{\symup{AVfi}_\symup{AVfi}}$}

$\symup{AVfi}_{\symup{AVfi}_\symup{AVfi}}$

\end{document}


Note that the font size used by \textnormal in subscripts is exactly the same as the one used by \symup; just add

$\textnormal{\detokenize\expandafter{\the\font}}$

$\scriptstyle\textnormal{\detokenize\expandafter{\the\font}}$

$\scriptscriptstyle\textnormal{\detokenize\expandafter{\the\font}}$

\detokenize\expandafter{\the\textfont2}

\detokenize\expandafter{\the\scriptfont2}

\detokenize\expandafter{\the\scriptscriptfont2}


at the end of the previous example and you'll see

The difference in size is only an optical effect due to the subscripts obtained with \symup are affected by ssty.

Math fonts and math mode are designed for math, which means that they are mostly meant for single math symbols and not for text words. If you really want to print a word in a subscript, it would more logical to explicitly switch to text mode -- and in text mode you naturally can adjust the font sizes:

\documentclass[fleqn]{article}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{STIX Two Text}
\setmathfont{STIX Two Math}

\newcommand\mytext[1]
{%
{\mathchoice
{\mbox{\normalfont\normalsize\color{green}#1}}%
{\mbox{\normalfont\normalsize\color{blue}#1}}%
{\mbox{\normalfont\footnotesize\color{red}#1}}%
{\mbox{\normalfont\fontsize{5.5pt}{6pt}\selectfont\color{red!50!green}#1}}%
}%
}

\begin{document}
$\mytext{AVfi}_{\mytext{AVfi}_{\mytext{AVfi}}} \qquad \symup{AVfi}_{\symup{AVfi}_{\symup{AVfi}}}$

$\mytext{AVfi}_{\mytext{AVfi}_{\mytext{AVfi}}} \qquad \symup{AVfi}_{\symup{AVfi}_{\symup{AVfi}}}$

\end{document}


• \textnormal in math mode does \mathchoice under the hood, choosing \f@size, \sf@size and \ssf@size. – egreg Dec 23 '16 at 17:29
• @egreg Yes, but but if I understood the question correctly \sf@size is a bit too small for the OP. – Ulrike Fischer Dec 23 '16 at 17:31
• No, it's a completely different problem. – egreg Dec 23 '16 at 17:31