4

I’m trying to use unicode-math’s capabilities (\setmathfont[range=…]) to use a non-math font in math mode. For example:

\documentclass{scrartcl}

\usepackage{unicode-math}

\setmainfont{FreeSans}
\setsansfont{FreeSans}

\setmathfont{Latin Modern Math}
\setmathfont{FreeSans}[range=up/{greek,Greek,latin,Latin,num}]
\setmathfont{FreeSans Oblique}[range=it/{greek,Greek,latin,Latin,num}]
\setmathfont{FreeSans Bold}[range=bfup/{greek,Greek,latin,Latin,num}]

\begin{document}

abc123

\textit{abc123}

\textbf{abc123}

\bigskip

\begin{tabular}{ll}
    math        & $abc123$ \\
    mathit      & $\mathit{abc123}$ \\
    mathrm      & $\mathrm{abc123}$ \\
    mathup      & $\mathup{abc123}$ \\
    mathbf      & $\mathbf{abc123}$ \\
    mathbfup    & $\mathbfup{abc123}$
\end{tabular}

\end{document}

With this document, I would expect all text to be in FreeSans and the lines with mathrm and mathup as well as mathbf and mathbfup to be the same. However, my result is this:

result of test document

So, I have two questions about what is happening:

  1. Why are \mathit and \mathup different from \mathbfup? \mathbfup works as it should, producing text in FreeSans Bold. The other two, on the other hand, produce the default of Latin Modern Math.
  2. How do I get all of these commands to use FreeSans, just like \mathbfup does? I know about unicode-math’s command \setmathfontface⟨command⟩{⟨font name⟩}[⟨font features⟩], but that doesn’t let me specify a range like range=up/{greek,Greek,latin,Latin,num}, as far as I can tell. And shouldn’t unicode-math’s own commands like \mathup work correctly “out of the box”, anyway?

Version info: TeX Live 2017, LuaTeX v1.0.4, unicode-math 2017/01/27 v0.8d.

  • Yes, it doesn't work properly. :( There's a (or more) question about this somewhere. – cfr Jun 16 '17 at 2:59
  • 1
    Free Sans isn't a maths font, is really the problem. There's no maths table. See tex.stackexchange.com/questions/326521/… and tex.stackexchange.com/questions/326876/…. You aren't using versions, but I suspect the issue is the same. You are trying to feed unicode-math a font which is not a unicode maths font. It just isn't designed for that. – cfr Jun 16 '17 at 3:07
  • I thought the (part of) the whole point of the range option was to allow using non-math fonts? E.g. section 4.1.1 in the documentation. – Socob Jun 17 '17 at 17:00
  • I don't see anything in 4.1.1 which suggests that. It will 'fall through', yes, so a text font can be made to work that way, so it will fall through to ASCII (as in the Fraktur example there). But you are trying to do something which requires rather more in terms of specifying the ranges for specific bits of maths, and I don't see how that can possibly be expected to work for a non-maths font. And nothing in that section suggests that it is expected to work. – cfr Jun 17 '17 at 22:28
  • @cfr I’m not sure what makes you say that. I mean, yeah, my example is more complicated, but suppose I just specified (for example) bfup/{latin}. Why would that not work/what would be the purpose of being able to specify latin if it didn’t work this way? What’s more, it does work (as you can see in my example, Latin letters and numbers are in FreeSans in math mode, the first row in the table; what’s more, the text in \mathbfup is in FreeSans Bold as well). It’s just that some of the \math… commands don’t do what I’d expect. – Socob Jun 18 '17 at 1:22
4

It you want really to change \mathbf and similar: This is done easily by (re)declaring the math alphabets.

The problem starts if you want to adapt the \symXX commands which normally map chars to the glyphs on the mathematical plan. Here the implementation is rather broken. It works more or less if you set your fonts as the last "math font", but this breaks various mathematical font dimens. If you reset them by setting a real math font as the last font, then the symXX fonts break. See also this issue https://github.com/wspr/unicode-math/issues/331.

\documentclass{scrartcl}

\usepackage{unicode-math}

\setmainfont{FreeSans}[NFSSFamily=FreeSans]
\setsansfont{FreeSans}

\setmathfont{Latin Modern Math}



\setmathfont{FreeSans}[range=up/{greek,Greek,latin,Latin,num}]
\setmathfont{FreeSans Bold}[range=bfup/{greek,Greek,latin,Latin,num}]
\setmathfont{FreeSans Oblique}[range=it/{greek,Greek,latin,Latin}]

% better a real math font at the end, but breaks the ranges above:
\setmathfont{Latin Modern Math}[range=\int]

 %Or with `\setmathfontface`, see documentation
\DeclareMathAlphabet{\mathrm}{TU}{FreeSans}{m}{n}
\DeclareMathAlphabet{\mathbf}{TU}{FreeSans}{bx}{n}
\DeclareMathAlphabet{\mathit}{TU}{FreeSans}{m}{it}
\let\mathbfup\mathbf


\begin{document}

abc123 αβ

\textit{abc123 αβ}

\textbf{abc123 αβ}

\bigskip

\begin{tabular}{ll}
    math        & $abc123$ \\
    mathrm      & $\mathrm{abc123αβ}$ \\
    mathup      & $\mathup{abc123αβ}$ \\
    mathbf      & $\mathbf{abc123αβ}$ \\
    mathbfup    & $\mathbfup{abc123αβ}$\\
    symup       & $\symup{aα} \mupalpha $\\
    symit       & $\symit{a}\symit{α}\symit{β} \mita  \mitalpha  \mitvarTheta $\\
    symbf       & $\symbf{a}\symbf{b}\symbf{c}\symbf{α}\symbf{β} \mbfa \mbfb \mbfc \mbfvarTheta \mbfalpha \mbfbeta$ \\
\end{tabular}

\end{document}

enter image description here

  • 1
    What is the optional NFSSFamily for? I have never seen that before. – Henri Menke Jun 16 '17 at 10:01
  • 2
    @HenriMenke: With it I can use the name FreeSans as family name in \DeclareMathAlphabet (it could also be "frS" or some other string). – Ulrike Fischer Jun 16 '17 at 10:23
  • Nice, thank you! Some questions out of interest, though: Why does declaring \mathrm in this way also cause \mathup to work correctly? And is the line \let\mathbfup\mathbf actually necessary (it seems to work for me without it, as well)? Finally, any clue on why \mathup and \mathbfup behave differently in this situation (aren’t they both unicode-math commands)? – Socob Jun 19 '17 at 14:18
  • \mathup and \mathbfup are defined in a bit special way in unicode-math. Imho you can add \mathup with \let\mathup\mathrm. – Ulrike Fischer Jun 19 '17 at 14:26
  • Actually, now that I think about it: I originally didn’t want to use \setmathfontface because I couldn’t specify ranges like with \setmathfont. With your solution, all glyphs from FreeSans would be used, not just Greek, Latin etc. For example: \mathrm{\nabla} or \mathbf{\nabla}. – Socob Jun 19 '17 at 14:37

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.