2

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}.

2 Answers 2

2

Since you are using LuaLaTeX, you can load unicode-math instead of newtxmath, which has compatibility problems. Use the XCharter-Math font for math.

EDIT: In the comments, you requested the numeral 1 from [oldstyleI], which is character variant 01 in the OpenType version of XCharter. A revised version is below.

\documentclass[12pt,a4paper]{article}

\usepackage{unicode-math}

\defaultfontfeatures[XCharter]{ Numbers=OldStyle,
                                CharacterVariant=1, % Change the shape of 1 in text mode
                                UprightFont=*-Roman,
                                BoldFont=*-Bold,
                                ItalicFont=*-Italic,
                                SlantedFont=*-Slanted,
                                BoldItalicFont=*-BoldItalic,
                                BoldSlantedFont=*-BoldSlanted,
                                Extension=.otf }

\setmainfont{XCharter}
\setmathfont{XCharter-Math}

\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}

XCharter sample

In the unlikely event that you ever want old-style numbers in math mode too, you can add the command:

\setmathfont{XCharter-Roman.otf}[range={up/num},
                                 Numbers=OldStyle,
                                 CharacterVariant=01] % Change the shape of 1 in math mode

Here is a version that works in PDFLaTeX:

\documentclass[12pt,a4paper]{article}

\usepackage{amsmath}
\usepackage[charter]{mathdesign}
\usepackage[oldstyle]{xcharter}

\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}

I recommend that you use unicode-math and LuaLaTeX when you can, and PDFLaTeX with legacy 8-bit fonts when you have to. But, since you say the problem here was being unable to read Unicode, there is a good chance that your document would work if you saved it in NFC (normalized precomposed) UTF-8 encoding. PDFLaTeX is not able to understand Unicode combining characters, bur can handle any Unicode character that directly maps to an 8-bit input encoding.

Edit:

If you truly want to use an OpenType text font together with a legacy Type 1 math font, this should work:

\documentclass[12pt,a4paper]{article}

\usepackage{amsmath}
\usepackage[charter]{mathdesign}
\usepackage{fontspec}

\setmainfont{XCharter}[NFSSFamily=mdbch, Numbers=OldStyle]

\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}
5
  • It's not that I "truly want to use an OpenType text font together with a legacy Type 1 math font", but rather that I just want to read my documents, text mode and math mode, without eye strain. To date, Charter is the best font I've found. Your second example to its credit doesn't entail a hack for each digit. And it comes within an ace of what I'm after (textmode "1" is the smallcap I shape of \usepackage[oldstyleI]{xcharter} rather than the short 1 shape of \usepackage[oldstyle]{xcharter}) but perhaps that's the best that \setmainfont offers.
    – Rosie F
    Commented May 10, 2022 at 16:17
  • Your edited variant with Numbers=OldStyle,CharacterVariant=1 worked! With this proviso: If \usepackage{amssymb} is needed, it must precede \usepackage{unicode-math} to prevent the Latex error that \eth is already defined.
    – Rosie F
    Commented May 12, 2022 at 8:46
  • @RosieF You don’t need to load amssymb together with unicode-math. Some publishers’ stylesheets do, however.
    – Davislor
    Commented May 12, 2022 at 9:15
  • unicode-math without amssymb lacks \Box. And although \def\ge{\geqslant} enables $2\ge3$ to work, \let\ge\geqslant does not. (This is the first time I've known \let\foo\baz fail and \def\foo{\baz} succeed -- supposing that \baz take no params. Is \let deprecated?)
    – Rosie F
    Commented May 12, 2022 at 9:38
  • @RosieF \box used to be defined in the kernel. You can define it as \mdwhtsquare (or any other size you prefer) in unicode-math. If I understand your other point correctly, I think the bug you were having is that unicode-math delays defining its symbols until the end of the preamble, for compatibility with other packages loaded afterward. If you want to override a symbol from it, you need to write \AtBeginDocument{\let...}.
    – Davislor
    Commented May 12, 2022 at 15:22
0

If you don't want to use unicode-math, you have to redefine the operators font to use XCharter with lining figures.

\documentclass[12pt,a4paper]{article}

\usepackage{amsmath}
\usepackage{fontspec}
\usepackage[charter]{newtxmath}

\setmainfont{XCharter}[Numbers={OldStyle}] % see https://tex.stackexchange.com/a/205558
\newfontfamily{\XCharterLF}{XCharter}[NFSSFamily=xcharterlf]

\DeclareSymbolFont{operators}{TU}{xcharterlf}{m}{n}

\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$.

$\sin x$

\end{document}

enter image description here

4
  • The mdbch font should also work. It’s one of the few OML-encoded upright math fonts, with both Latin and lowercase Greek.
    – Davislor
    Commented May 9, 2022 at 16:57
  • With your preamble, my code compiles but still produces CM digits in math mode. (And the small-cap I for text mode 1.) // @Davislor Which parts of egreg's example should I replace with mdbch?
    – Rosie F
    Commented May 9, 2022 at 17:26
  • @RosieF Sorry, which preamble of mine had that problem?
    – Davislor
    Commented May 9, 2022 at 17:31
  • @RosieF I edited my answer to use mdbch (through the mathdesign package). It stands for MathDesign Bitstream CHarter.
    – Davislor
    Commented May 9, 2022 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .