How do I get Charter with its "oldstyle" option in text mode, and with Charter characters (including digits) in math mode?
The proposed solution needs to work with LuaLaTeX (because some text characters are non-ASCII and I prefer to paste those non-ASCII characters into the source file, and save the source as UTF-8).
Edit: Just in case it's relevant, I use MiKTeX v.2.9. Do I need to upgrade in order to solve this problem?
I can get tantalisingly close but can't get everything working at once.
MWE 1:
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont{XCharter} % see https://tex.stackexchange.com/a/205558
\usepackage[oldstyle]{xcharter}
% See https://tex.stackexchange.com/a/347574 for why this is needed.
\AtBeginDocument{%
\Umathcode`0="7 "0 `0
\Umathcode`1="7 "0 `1
\Umathcode`2="7 "0 `2
\Umathcode`3="7 "0 `3
\Umathcode`4="7 "0 `4
\Umathcode`5="7 "0 `5
\Umathcode`6="7 "0 `6
\Umathcode`7="7 "0 `7
\Umathcode`8="7 "0 `8
\Umathcode`9="7 "0 `9
}
\usepackage[charter]{newtxmath}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies a/b=c/d.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
Digits in text mode are just how I want. Moreover, letters in math mode are Charter italics, which I want. However, digits in math mode are Computer Modern, despite my attempt to use the code in this answer, which answered a similar question with regard to Libertine.
MWE 2
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{fontspec}
\setmainfont{XCharter}[Numbers={OldStyle}] % see https://tex.stackexchange.com/a/205558
\usepackage[charter]{newtxmath}
% See https://tex.stackexchange.com/a/347574 for why this is needed.
\AtBeginDocument{%
\Umathcode`0="7 "0 `0
\Umathcode`1="7 "0 `1
\Umathcode`2="7 "0 `2
\Umathcode`3="7 "0 `3
\Umathcode`4="7 "0 `4
\Umathcode`5="7 "0 `5
\Umathcode`6="7 "0 `6
\Umathcode`7="7 "0 `7
\Umathcode`8="7 "0 `8
\Umathcode`9="7 "0 `9
}
\begin{document}
Digits in plain text: 48/96=135/270.
$a=48, b=96, c=135, d=270\implies ab=cd.$ $8=5+3=9-1=2\times4=2^3.$
\end{document}
Now I attempt to get old-style digits in text mode by hacking \setmainfont rather than \usepackage{xcharter}. But this seems to pass the parameter oldstyleI (rather than oldstyle) to \usepackage{xcharter}. Anyway, the result is that text mode has old-style digits but with a small cap I for a 1. Good news is that digits in math mode are Charter, which is what I want.
It would be even nicer if both text and math modes could use old-style Charter digits. That way I could keep tables as array environments in math mode. Having to go to text mode for digits in tables entails replacing e.g. $\begin{array}{r} n \\ 1 \end{array}$
with \begin{tabular}{r} $n$ \\ 1 \end{tabular}
.