[Tex/LaTex] switching between math-styles with \mathversion

fontsunicode-math

This is a follow-up to this question. It explains switching math fonts within a single document with unicode-maths \mathversion command.

The unicode-math docs have it that

\setmathfont{math-style=Tex}{Cambria Math}

is equivalent to

\unimathsetup{math-style=Tex}
\setmathfont{Cambria Math}

Now if I want to use a math font that is by design upright e.g. the Neo Euler font. I have to use

\setmathfont{math-style=upright}{euler.otf}

If I want to switch between the Euler font and another one that is italic by design, say XITS. Using

\setmathfont[version=XM]{xits-math.otf}
\setmathfont[version=NE,math-style=upright]{euler.otf}

to be able to use \mathversion{NE} and \mathversion{XM} as in this example

\documentclass{minimal}
\usepackage{unicode-math}
\setmathfont[version=XM]{xits-math.otf}
\setmathfont[version=NE,math-style=upright]{euler.otf}
\begin{document}
\[a+b\]
\mathversion{NE}
\[a+b\]
\mathversion{XM}
\[a+b\]
\end{document}

does not work. math-style as a package option is not switched as well, so everything is typeset upright. I haven’t found a way around this, as package options are set when the package is loaded.

Best Answer

I've been wrong before but I think this isn't possible. \mathversion works by simply changing the font that each math char is pointing to, whereas to change from upright to italic maths you need to remap every single symbol that would be affected by the change.

It doesn't seem likely to me that people will want to change this often if ever in a document, so I don't think it's that cumbersome to write instead

\setmathfont[math-style=TeX]{xits-math.otf}
\[a+b\]
\setmathfont[math-style=upright]{euler.otf}
\[a+b\]

and so on.