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}
  • 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 1: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 1:48
5
+50

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.

| improve this answer | |

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.