
我想為所有減號指定字型(在下面的範例中:Times New Roman),無論它們是使用 Unicode 字元「2212 還是在數學模式下使用連字號建立的。
如果我將「2212」新增至 的範圍選項中\setmathfont
,則當我使用正確的 unicode 字元「減號」編寫文字時,它會起作用。
但是當我寫$-6$(這裡的-是一個普通的連字號)時,輸出是一個正確的減號,但不是Times New Roman。請參閱我的範例中的最後 6 個。
\documentclass{article}
\RequirePackage[silent]{fontspec}
\setmainfont{Times New Roman}
\RequirePackage{unicode-math}
\setmathfont{STIXTwoMath}[]
\setmathfont{Times New Roman}[ range = { up/{num,latin,Latin}, "2212 } ]
\begin{document}
%% Minus ("2212) in source code:
−6 and $−6$
%% Hyphen ("002D) in source code:
-6 and $-6$
\end{document}
輸出:
有誰知道我如何在 $ 環境中「存取」連字符?
答案1
我不確定為什麼會這樣,但如果你說range = { "2212, \minus }
,它有效,但你確實需要同時說明"2212
和\minus
:
\documentclass{article}
\RequirePackage[silent]{fontspec}
\setmainfont{Times New Roman}
\RequirePackage{unicode-math}
\setmathfont{STIX Two Math}
\setmathfont{Times New Roman}[
range = { "2212, \minus }
]
\begin{document}
%% Minus ("2212) in source code:
−6 and $−6$
%% Hyphen ("002D) in source code:
-6 and $-6$
\end{document}
因此,您可能需要執行類似的操作來為加號和減號選擇相同的字體:
\documentclass{article}
\RequirePackage[silent]{fontspec}
\setmainfont{Times New Roman}
\RequirePackage{unicode-math}
\setmathfont{STIX Two Math}
\setmathfont{Times New Roman}[
range = { "2212, \minus, "002B }
]
\begin{document}
-6 and $-6$
+6 and $+6$
\end{document}
答案2
我建議你寫\textnormal{-}
。
\documentclass{article}
\RequirePackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{STIXTwoMath}[]
\setmathfont{Times New Roman}[ range = { up/{num,latin,Latin}, "2212 } ]
\begin{document}
%% Minus ("2212) in source code:
−6 and $−6$
%% Hyphen ("002D) in source code:
-6 and $\textnormal{-}6$
\end{document}