5

Consider the following test file and compile it with LuaTeX (TeXLive 2016):

\documentclass{article}
\usepackage[math-style = TeX]{unicode-math}

\setmainfont{texgyretermes}[
  Extension = .otf,
  UprightFont = *-regular,
  BoldFont = *-bold,
  ItalicFont = *-italic,
  BoldItalicFont = *-bolditalic,
  ]

\setsansfont{texgyreadventor}[
  Extension = .otf,
  UprightFont = *-regular,
  BoldFont = *-bold,
  ItalicFont = *-italic,
  BoldItalicFont = *-bolditalic,
  ]

\setmathfont{Latin Modern Math}

\begin{document}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

\setmathfont[range=up/{greek,Greek,latin,Latin,num}]{texgyreadventor-regular}
\setmathfont[range=it/{greek,Greek,latin,Latin,num}]{texgyreadventor-italic}
\setmathfont[range = {}]{Latin Modern Math}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

\setmathfont{Latin Modern Math}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

% {
%   \setmathfont[range=up/{greek,Greek,latin,Latin,num}]{texgyreadventor-regular}
%   \setmathfont[range=it/{greek,Greek,latin,Latin,num}]{texgyreadventor-italic}
%   \setmathfont[range = {}]{Latin Modern Math}

%   \begin{equation}
%     \int_{t = 0}^{x^2} t dt
%   \end{equation}
% }

\end{document}

If I uncomment the last lines, LuaTeX hangs forever. How can I change math font inside a group?


EDIT

I'm well aware that I should not use a non math font to do math but, unfortunately, a sans serif math font does not yet exist, AFAIK.

The problem does not appear to be linked with the fact that I use a non math font.

\documentclass{article}
\usepackage[math-style = TeX]{unicode-math}

\setmathfont{Latin Modern Math}

\begin{document}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

\setmathfont{Asana-Math}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

\setmathfont{Latin Modern Math}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}


% {
%   \setmathfont{Asana-Math}

%   \begin{equation}
%     \int_{t = 0}^{x^2} t dt
%   \end{equation}
% }


\end{document}

However, as @cfr suggested, I should use \mathversion: the following works.

\documentclass{article}
\usepackage[math-style = TeX]{unicode-math}

\setmathfont[version=lm]{Latin Modern Math}
\setmathfont[version=asana]{Asana-Math}

\mathversion{lm}

\begin{document}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

\mathversion{asana}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}

\mathversion{lm}

\begin{equation}
  \int_{t = 0}^{x^2} t dt
\end{equation}


{
  \mathversion{asana}

  \begin{equation}
    \int_{t = 0}^{x^2} t dt
  \end{equation}
}

\end{document}
cjorssen
  • 10,032
  • 4
  • 36
  • 126
  • Can you explain why you want to do this? Why not define another maths version and use that instead? – cfr Aug 27 '16 at 22:50
  • @cfr My tcolorbox example environments are in sans serif font. I'd like to have a math font that fits. But I don't know how to do with mathversion. Would you mind writing à code showing how it works with opentype non math fonts? – cjorssen Aug 27 '16 at 22:54
  • Please make sure your code examples compile before posting them unless the error is the problem. – cfr Aug 27 '16 at 23:52
  • It would work if you had a suitable sans serif font, but I don't think there are any to be had. – cfr Aug 28 '16 at 01:37
  • The problem really is that unicode-math is designed to work with opentype maths fonts. It isn't designed to work with other kinds of fonts. While you can persuade it to do some things with them by a combination of brute force and ignorance (in my case, anyway, though probably not yours), there is a real limit to that. unicode-math *needs* a maths table to work properly. I would suggest simply not using unicode maths fonts if you need to switch to sans serif for maths. Stick to traditional TeX fonts for maths in that case. – cfr Aug 28 '16 at 01:48
  • Admittedly, unicode-math should not fail quite so confusingly and spectacularly if you try to use version here - and I certainly would consider that a bug, even if a satisfactory fix would be to fail with meaningful errors - but it cannot be expected to actually work. It just isn't meant to. – cfr Aug 28 '16 at 01:50
  • That I know of, there are no sanserif OpenType Math fonts. – Joseph Wright Aug 28 '16 at 06:44
  • @cfr Thanks for your comments (see my edited answer). Would you mind writing an answer so I can grant you the bounty? – cjorssen Aug 28 '16 at 10:16
  • I can't. It isn't just that the fonts you are using are not maths fonts. It doesn't seem to be possible to combine version and range at all, even if you are trying to restrict the range for a font with a maths table. Perhaps @JosephWright knows if this is a bug or a known limitation and whether there's a workaround. – cfr Aug 28 '16 at 14:45
  • @cjorssen See http://tex.stackexchange.com/questions/326876/is-it-possible-to-combine-version-and-range-when-specifying-a-maths-font-with-un. – cfr Aug 29 '16 at 00:58
  • @cfr Thanks for asking the right question :) You still deserve the bounty since you clearly identified the true issue here! – cjorssen Aug 29 '16 at 08:55
  • Let's see if you get a proper answer first: your bounty has 5 days to run. No point in wasting it. – cfr Aug 30 '16 at 02:43
  • You will probably want to read Ulrike's answer to the question I asked about this. – cfr Sep 04 '16 at 16:04

1 Answers1

5

There are really two problems here.

The first is that unicode-math really wants opentype fonts with a proper math table. It only works with fonts lacking this at all, as I understand it, because the configuration falls through to setting the applicable range to up, despite the font lacking anything which usually enables the setting of ranges etc.

The usual way to set an alternative set of maths fonts is to declare an alternative maths version e.g. bold versus normal. unicode-math supports this. This basically works, as your example shows.

However, the second problem is that it seems to be impossible to combine the use of range with version. Setting a range affects all maths versions rather than just the specified one, as I demonstrate in this question.

cfr
  • 198,882