这个问题在这个网站上并不新鲜,但我试过以前的解决方案,但都不奏效。相关问题:
- 在 TeX Live 2016 中将 libertine 和 newtxmath 与 XeLaTeX 结合使用时,数学数字会以 CM 呈现
- newtxmath 与 fontspec 结合使用的注意事项
newtxmath
我的目标是通过 与 设置系统 OpenType 字体一起使用fontspec
。无论我以何种顺序加载包,数学模式中的数字都以 Computer Modern 而不是 Times 呈现。
% !TEX program = lualatex
\documentclass[12pt,a4paper]{article}
\usepackage{newtxmath}
\usepackage[no-math]{fontspec}
\setmainfont{Times New Roman}
\begin{document}
Text: 2, Math: \(x=\sqrt{2}\)
\end{document}
根据newtxmath
文档:
据我所知,newtxmath 可以与 [XeLaTeX 和 LuaLaTeX] 一起使用,但需要非常具体的加载顺序和选项选择。[...] 在加载和使用 fontspec 之前必须加载所有数学选项。
我认为我做得对。我的软件包也都是最新的。
我尝试去适应这个答案用于 Times 字体,但无法使其工作。
答案1
newtxmath
或多或少假设默认编码是 T1 或 OT1。但您可以重置操作员字体:
\documentclass[12pt,a4paper]{article}
\usepackage{newtxmath}
\DeclareSymbolFont{operators}{OT1}{ntxtlf}{m}{n}
\SetSymbolFont{operators}{bold}{OT1}{ntxtlf}{b}{n}
\usepackage[no-math]{fontspec}
\setmainfont{Times New Roman}
%
\begin{document}
Text: 2, Math: \(x=\sqrt{2}\)
\end{document}
另一种方法是给予时间 newtx-family 名称,以便 newtxmath 可以使用它。
\documentclass[12pt,a4paper]{article}
\usepackage[no-math]{fontspec}
\setmainfont{Times New Roman}[NFSSFamily=ntxtlf]
\usepackage{newtxmath}
%
\begin{document}
Text: 2, Math: \(x=\sqrt{2}\)
\end{document}
答案2
删除该no-math
选项并使用我的答案中的技巧在 TeX Live 2016 中将 libertine 和 newtxmath 与 XeLaTeX 结合使用时,数学数字会以 CM 呈现,但还增强了对其他字形的照顾。
\documentclass[12pt,a4paper]{article}
\usepackage{newtxmath}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\DeclareSymbolFont{oldoperators}{OT1}{ntxtlf}{m}{n}
\SetSymbolFont{oldoperators}{bold}{OT1}{ntxtlf}{b}{n}
\AtBeginDocument{%
\DeclareMathSymbol{0}{\mathalpha}{operators}{`0}%
\DeclareMathSymbol{1}{\mathalpha}{operators}{`1}%
\DeclareMathSymbol{2}{\mathalpha}{operators}{`2}%
\DeclareMathSymbol{3}{\mathalpha}{operators}{`3}%
\DeclareMathSymbol{4}{\mathalpha}{operators}{`4}%
\DeclareMathSymbol{5}{\mathalpha}{operators}{`5}%
\DeclareMathSymbol{6}{\mathalpha}{operators}{`6}%
\DeclareMathSymbol{7}{\mathalpha}{operators}{`7}%
\DeclareMathSymbol{8}{\mathalpha}{operators}{`8}%
\DeclareMathSymbol{9}{\mathalpha}{operators}{`9}%
\DeclareMathSymbol{\Gamma}{\mathalpha}{oldoperators}{"00}%
\DeclareMathSymbol{\Delta}{\mathalpha}{oldoperators}{"01}%
\DeclareMathSymbol{\Theta}{\mathalpha}{oldoperators}{"02}%
\DeclareMathSymbol{\Lambda}{\mathalpha}{oldoperators}{"03}%
\DeclareMathSymbol{\Xi}{\mathalpha}{oldoperators}{"04}%
\DeclareMathSymbol{\Pi}{\mathalpha}{oldoperators}{"05}%
\DeclareMathSymbol{\Sigma}{\mathalpha}{oldoperators}{"06}%
\DeclareMathSymbol{\Upsilon}{\mathalpha}{oldoperators}{"07}%
\DeclareMathSymbol{\Phi}{\mathalpha}{oldoperators}{"08}%
\DeclareMathSymbol{\Psi}{\mathalpha}{oldoperators}{"09}%
\DeclareMathSymbol{\Omega}{\mathalpha}{oldoperators}{"0A}%
\DeclareMathSymbol{!}{\mathclose}{operators}{"21}%
\DeclareMathSymbol{+}{\mathbin}{operators}{"2B}%
\DeclareMathSymbol{:}{\mathrel}{operators}{"3A}%
\DeclareMathSymbol{;}{\mathpunct}{operators}{"3B}%
\DeclareMathSymbol{=}{\mathrel}{operators}{"3D}%
\DeclareMathSymbol{?}{\mathclose}{operators}{"3F}%
\DeclareMathDelimiter{(}{\mathopen} {operators}{"28}{largesymbols}{"00}%
\DeclareMathDelimiter{)}{\mathclose}{operators}{"29}{largesymbols}{"01}%
\DeclareMathDelimiter{[}{\mathopen} {operators}{"5B}{largesymbols}{"02}%
\DeclareMathDelimiter{]}{\mathclose}{operators}{"5D}{largesymbols}{"03}%
\DeclareMathAccent{\acute}{\mathalpha}{operators}{"B4}%
\DeclareMathAccent{\grave}{\mathalpha}{operators}{"60}%
\DeclareMathAccent{\ddot}{\mathalpha}{operators}{"A8}%
\DeclareMathAccent{\tilde}{\mathalpha}{oldoperators}{"7E}%
\DeclareMathAccent{\bar}{\mathalpha}{oldoperators}{"16}%
\DeclareMathAccent{\breve}{\mathalpha}{oldoperators}{"15}%
\DeclareMathAccent{\check}{\mathalpha}{oldoperators}{"14}%
\DeclareMathAccent{\hat}{\mathalpha}{oldoperators}{"5E}%
\DeclareMathAccent{\dot}{\mathalpha}{oldoperators}{"5F}%
\DeclareMathAccent{\mathring}{\mathalpha}{oldoperators}{"17}%
\DeclareMathSymbol{\mathdollar}{\mathord}{operators}{"24}%
}
\begin{document}
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}}
$
$\Gamma\Delta\Theta$
\end{document}
由于技术限制,一些重音符号必须采用newtx
Times New Roman 字体代替。