1

I've tried to follow this answer (and the subsequent ones cited there), but to no avail. When I try to compile with LuaLaTeX using the XCharter font, the numbers in math mode appear in CM.

\documentclass{article}

\usepackage[xcharter]{newtxmath}
\usepackage{fontspec}
\setmainfont{XCharter}

\begin{document}
Text: 123, Math: \( 123 \)
\end{document}

How can I get both the text and the math to use the XCharter font to write numbers? Thank you very much in advance!

2 Answers 2

1
\documentclass{article}

\usepackage[xcharter]{newtxmath}
\usepackage{fontspec}
\setmainfont{XCharter}[NFSSFamily=xcharter]

\DeclareSymbolFont{numbers}{TU}{xcharter}{m}{n}

\AtBeginDocument{
    \DeclareMathSymbol{0}{\mathalpha}{numbers}{48}
    \DeclareMathSymbol{1}{\mathalpha}{numbers}{49}
    \DeclareMathSymbol{2}{\mathalpha}{numbers}{50}
    \DeclareMathSymbol{3}{\mathalpha}{numbers}{51}
    \DeclareMathSymbol{4}{\mathalpha}{numbers}{52}
    \DeclareMathSymbol{5}{\mathalpha}{numbers}{53}
    \DeclareMathSymbol{6}{\mathalpha}{numbers}{54}
    \DeclareMathSymbol{7}{\mathalpha}{numbers}{55}
    \DeclareMathSymbol{8}{\mathalpha}{numbers}{56}
    \DeclareMathSymbol{9}{\mathalpha}{numbers}{57}
    }


\begin{document}
Text: 0123456789, Math: \( 0123456789 \)
\end{document}

enter image description here

1

A good deal of fixes is necessary.

\documentclass{article}

% fix math accents
\DeclareSymbolFont{charteraccents}{T1}{XCharter-TLF}{m}{n}
\SetSymbolFont{charteraccents}{bold}{T1}{XCharter-TLF}{b}{n}
\DeclareMathAccent{\grave}{\mathalpha}{charteraccents}{0}
\DeclareMathAccent{\acute}{\mathalpha}{charteraccents}{1}
\DeclareMathAccent{\hat}{\mathalpha}{charteraccents}{2}
\DeclareMathAccent{\tilde}{\mathalpha}{charteraccents}{3}
\DeclareMathAccent{\ddot}{\mathalpha}{charteraccents}{4}
\DeclareMathAccent{\mathring}{\mathalpha}{charteraccents}{6}
\DeclareMathAccent{\check}{\mathalpha}{charteraccents}{7}
\DeclareMathAccent{\breve}{\mathalpha}{charteraccents}{8}
\DeclareMathAccent{\bar}{\mathalpha}{charteraccents}{9}
\DeclareMathAccent{\dot}{\mathalpha}{charteraccents}{10}

\usepackage{amsmath}
\usepackage[no-math]{fontspec}
\usepackage[xcharter]{newtxmath}

\setmainfont{XCharter}[NFSSFamily=XCharter]

% fix numbers and operators
\DeclareSymbolFont{operators}{TU}{XCharter}{m}{n}
\SetSymbolFont{operators}{bold}{TU}{XCharter}{b}{n}

\begin{document}

Text: 123, Math: \( 123 \)

Text: 2, Math: \(x=\sqrt{2}+1234567890\)

!+:;=?()[]

${!}{+}{:}{;}{=}{?}{(}{)}{[}{]}$

\'a\`a\"a\~a\=a\u{a}\v{a}\^a\.a\r{a}

$
\acute{\mathrm{a}}
\grave{\mathrm{a}}
\ddot{\mathrm{a}}
\tilde{\mathrm{a}}
\bar{\mathrm{a}}
\breve{\mathrm{a}}
\check{\mathrm{a}}
\hat{\mathrm{a}}
\dot{\mathrm{a}}
\mathring{\mathrm{a}}
$

$\vec{a}$ $\widehat{aa}$ $\widetilde{aa}$

$\Gamma\Delta\Theta$

\end{document}

enter image description here

You must log in to answer this question.

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