我尝试去追随这个答案(以及随后引用的那些),但无济于事。当我尝试使用 XCharter 字体编译 LuaLaTeX 时,数学模式中的数字出现在 CM 中。
\documentclass{article}
\usepackage[xcharter]{newtxmath}
\usepackage{fontspec}
\setmainfont{XCharter}
\begin{document}
Text: 123, Math: \( 123 \)
\end{document}
我怎样才能让文本和数学都使用 XCharter 字体来写数字?提前谢谢您!
答案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}
答案2
需要进行大量修复。
\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}