# unicode-math: Use text font for numerical digits in mathmode

Using XeTeX with fontspec and unicode-math, I would like to use the documents main font for for digits (numbers) in mathmode. Also, I would like to make \text{} in mathmode use Lining numbers while the default for the document are OldStyle numbers. How can I achieve this behavior?

I tried inserting \setmathfont[range=\mathup/{num}]{Linux Libertine O} but it does not give the desired result.

Here is an MWE, pointing out the problems:

\documentclass{article}
\usepackage{iftex}

\usepackage{libertine}
\usepackage{fontspec}
\setmainfont[Numbers=OldStyle]{Linux Libertine O}

\usepackage{amsmath}

\usepackage{unicode-math}
% Here I try to set up the normal text font for digits in mathmode:
\setmathfont[range=\mathup/{num}]{Linux Libertine O}

\parindent0pt

\begin{document}

This is \ifXeTeX XeTeX\fi\ifLuaTeX LuaTeX\fi
with \fontname\font
\bigskip

Text numbers:
0123456789; italic: \textit{0123456789}; bold: \textbf{0123456789}

Text numbers lining:
\liningnums{0123456789; italic: \textit{0123456789}; bold:
\textbf{0123456789}}

Numbers in mathmode: $0123456789$ (ok)\\
mathit: $\mathit{0123456789}$ (wrong font)\\
mathbf: $\mathbf{0123456789}$ (wrong font)\\
mathrm: $\mathrm{0123456789}$ (wrong font)\\
text (math): $\text{0123456789}$ (should be lining)

In big equation, fonts for big brackets $\big( \Big( \bigg( \Bigg($ are
missing:
$\left(\frac{12a}{34b}\right)$

\end{document}


Using XeTeX, this results in:

So there are 3 problems:

1. Linux Libertine O for digits does not appear in \mathrm, \mathit, and \mathbf etc.
2. The big brackets are not working. (See more on this below.)
3. Is there a way to achieve Lining numbers in mathmode \text{} although the document number style is OldStyle?

Concerning problem 1, this is due to range=\mathup/{num} only applying to updright math text. Does anyone know how to apply this command for all numerals in all ranges? using only range={num} results in an error.

Concerning problem 2, I have two more pieces of information. A) Using LuaTeX on the same file, the brackets do appear, but without being scaled:

B) If I comment out the line \setmathfont[range=\mathup/{num}]{Linux Libertine O}, the problem does not occur at all. This suggests that the bracket mechanism is affected by changing the font for numbers, which it shouldn't be, right?

This problem is, by the way, not specific to Linux Libertine O. It also appeared when I was using SabonNextLTPro as main document font.

• unicode-math is somewhat buggy. In particular, the range stuff does not work as advertised. I think you have to think of it as a work in progress .... – cfr Apr 12 '17 at 0:12
• Yeah sure, I figured that from the manual :) But I was wondering, is there a hack to map only 0123456789 and not also other signs such as brackets to a different font? – LaTechneuse Apr 12 '17 at 9:24

In the meantime until anybody might come up with an idea, I though I'd share a workaround. It's basically reverting to mathspec instead of unicode-math. Nearly everything works out of the box in only three lines:

\documentclass{article}
\usepackage{iftex}

\usepackage[no-math]{fontspec}
\usepackage{libertine}
\setmainfont[Numbers=OldStyle]{Linux Libertine O}

\usepackage{amsmath}
\usepackage{mathspec}
\setmathfont(Digits){Linux Libertine O}

\parindent0pt

\begin{document}

This is \ifXeTeX XeTeX\fi\ifLuaTeX LuaTeX\fi
with \fontname\font
\bigskip

Text numbers:
0123456789; italic: \textit{0123456789}; bold: \textbf{0123456789}

Text numbers lining:
\liningnums{0123456789; italic: \textit{0123456789}; bold:
\textbf{0123456789}}

Numbers in mathmode: $0123456789$ (ok)\\
mathit: $\mathit{0123456789}$ (correct font but no italic)\\
mathbf: $\mathbf{0123456789}$ (correct font but no boldface)\\
mathrm: $\mathrm{0123456789}$ (ok)\\
text (math): $\text{0123456789}$ (should be lining)

In equations, testing fonts for big brackets $\big( \Big( \bigg( \Bigg($:
$\left(\frac{12a}{34b}\right)$

\end{document}