After fiddling around with egreg's answer to my previous question, I finally discovered that lualatex
is not selecting the tnum
OpenType features, that is it uses the default numerals instead of the monospaced lining, whereas xelatex
does select the correct numerals.
The Goal
To use the Calluna font, with OldStyle figures in the main text, and Lining figures in mathmode, using code that's preferably compilable using lualatex
.
The Problem
Calluna has OldStyle figures by default, so the named character one
returns a LowerCase 1. The code supplied by egreg is supposed to select the character one.tnum
in math mode (or pnum
as it stands in his original answer, but that only influences horizontal spacing). His code works fine using xelatex
, but lualatex
produces the character one
instead, which for most fonts is actually a lining, proportional, figure, so exactly what egreg expected, but for Calluna this is an oldstyle, proportional numeral. Since Calluna is not freely available I changed the code to use EB Garamond which produces the same result.
Edit
The problem really is in the combination of lualatex
and egreg's code, since the normal \setmainfont
options are respected perfectly fine by lualatex
, if I set these to Lining I get Lining figures in the main text, but still not in the math text.
See my original question as well for the reasons to use this code instead of mathspec
for example.
After filing an issue at the luaotfload
GitHub, it appears the problem was that fontspec uses the Renderer=Full
/mode=node
option by default, while in math mode mode=base
/Renderer=Basic
should be used. However, now the font features are applied inconsistently, randomly changing between compilations.
The Question
How can I change the code, such that lualatex
consistently uses the Lining, Monospaced numerals (OpenType feature tnum
) in math mode, while using eulervm
for all other characters in mathmode?
The Code
\documentclass[landscape]{scrartcl}
\usepackage{amsfonts}
\usepackage{eulervm}
\usepackage{siunitx}
\usepackage{ifluatex}
\usepackage[no-math]{fontspec}
\setmainfont[
Ligatures={Common,TeX},
Numbers={OldStyle,Proportional},
]{EBGaramond12-Regular.otf}
% ]{Calluna}
\setsansfont[
Ligatures={Common,TeX},
Numbers={Lining,Proportional},
]{TeX Gyre Heros}
\setmonofont[
Ligatures={NoRequired,NoCommon,NoContextual},
Numbers={Lining,Monospaced},
]{TeX Gyre Cursor}
% LuaTeX uses the full renderer by default, this does not work in math mode, so negate manually
\ifluatex
\newfontfamily{\liningmain}[
Ligatures={Common,TeX},
Numbers={Lining,Monospaced},
Renderer=Basic,
]{EBGaramond12-Regular.otf}
% ]{Calluna}
\else
\newfontfamily{\liningmain}[
Ligatures={Common,TeX},
Numbers={Lining,Monospaced},
]{EBGaramond12-Regular.otf}
% ]{Calluna}
\fi
% A trick for extracting the family information
% which works independently of the chosen font
\begingroup
\def\getfamily#1#2#3#4#5{#4}
\edef\x{\endgroup
\def\noexpand\liningdefault{\expandafter\expandafter\expandafter
\getfamily\csname liningmain \endcsname}}\x
\DeclareSymbolFont{liningmath}{\encodingdefault}{\liningdefault}{m}{n}
\DeclareSymbolFontAlphabet{\mathlining}{liningmath}
\Umathcode`0="7 \symliningmath `0
\Umathcode`1="7 \symliningmath `1
\Umathcode`2="7 \symliningmath `2
\Umathcode`3="7 \symliningmath `3
\Umathcode`4="7 \symliningmath `4
\Umathcode`5="7 \symliningmath `5
\Umathcode`6="7 \symliningmath `6
\Umathcode`7="7 \symliningmath `7
\Umathcode`8="7 \symliningmath `8
\Umathcode`9="7 \symliningmath `9
\sisetup{
math-rm = \mathlining,
}
\usepackage{polyglossia}
\setmainlanguage[variant=british]{english}
\usepackage{blindtext}
\begin{document}
\section{testing}
\begin{tabular}{p{.15\textwidth}p{.85\textwidth}}
\hline
Mode & Result\\
\hline
Normal font & \fontname\font\\
Lining font & {\liningmain\fontname\font}\\
Text mode & 1234567890\\
Math mode & \(1234567890\)\\
\verb|\SI| text mode & \SI{1042358769}{\metre}\\
\verb|\SI| math mode & \(\SI{1234567890}{\metre}\)\\
\verb|\num| text mode & \num{1234567890}\\
\verb|\num| math mode & \(\num{1234567890}\)\\
verbatim & \verb|1234567890|\\
\hline
\end{tabular}
\end{document}