我想要在数学模式下使用希腊打字机字符unicode-math
。
我使用具有希腊字符的字体:
\setmonofont{NewCMMono10}[
Extension = .otf,
UprightFont = *-Regular,
ItalicFont = *-Italic.otf,
BoldFont = *-Bold.otf,
BoldItalicFont = *-BoldOblique.otf,
SmallCapsFeatures = {Numbers=OldStyle}
]
但以下方法均不起作用:\symtt{\Omega}
,\symtt{Ω}
(这两个方法生成正常的 Omega),\mathtt{\Omega}
(这个方法生成一个方框,?
好像字符丢失了一样)。
添加这个:
\setmathfont{NewCMMono10-Regular.otf}[
range = {tt},
]
没有帮助。
答案1
\symtt
不幸的是,它仅限于 Unicode 指定的字符集,但您可以将字体声明为数学字母表:
\documentclass{article}
\usepackage{unicode-math}
\setmonofont{NewCMMono10}[
NFSSFamily=ncmtt,
Extension = .otf,
UprightFont = *-Regular,
ItalicFont = *-Italic.otf,
BoldFont = *-Bold.otf,
BoldItalicFont = *-BoldOblique.otf,
SmallCapsFeatures = {Numbers=OldStyle}
]
\SetMathAlphabet\mathtt{normal}{TU}{ncmtt}{m}{n}
\DeclareMathAlphabet\mathttit{TU}{ncmtt}{m}{it}
\begin{document}
\showoutput
$\mathtt{abc αβγ}$
$\mathttit{abc αβγ}$
\end{document}
答案2
您可以定义数学字母表。这里我还介绍了如何在输入中支持标准名称,这样就不必被迫使用希腊字符。
\documentclass{article}
\usepackage{unicode-math}
\setmonofont{NewCMMono10}[
NFSSFamily = ncmtt,
Extension = .otf,
UprightFont = *-Regular,
ItalicFont = *-Italic.otf,
BoldFont = *-Bold.otf,
BoldItalicFont = *-BoldOblique.otf,
SmallCapsFeatures = {Numbers=OldStyle}
]
\DeclareMathAlphabet{\mathttinner}{TU}{ncmtt}{m}{n}
\ExplSyntaxOn
\NewDocumentCommand{\xmathtt}{m}
{
\mathttinner { \tl_map_function:nN { #1 } \sparusaurata_mathtt:n }
}
\cs_new_protected:Nn \sparusaurata_mathtt:n
{
\str_case:nnF { #1 }
{
{\Alpha}{Α} {\Beta}{Β} {\Gamma}{Γ} {\Delta}{Δ}
{\Epsilon}{Ε} {\Zeta}{Ζ} {\Eta}{Η} {\Theta}{Θ}
{\Iota}{Ι} {\Kappa}{Κ} {\Lambda}{Λ} {\Mu}{Μ}
{\Nu}{Ν} {\Xi}{Ξ} {\Omicron}{Ο} {\Pi}{Π}
{\Rho}{Ρ} {\Sigma}{Σ} {\Tau}{Τ} {\Upsilon}{Υ}
{\Phi}{Φ} {\Chi}{Χ} {\Psi}{Ψ} {\Omega}{Ω}
{\alpha}{α} {\beta}{β} {\gamma}{γ} {\delta}{δ}
{\epsilon}{ε} {\zeta}{ζ} {\eta}{η} {\theta}{θ}
{\iota}{ι} {\kappa}{κ} {\lambda}{λ} {\mu}{μ}
{\nu}{ν} {\xi}{ξ} {\omicron}{ο} {\pi}{π}
{\rho}{ρ} {\sigma}{σ} {\tau}{τ} {\upsilon}{υ}
{\phi}{φ} {\chi}{χ} {\psi}{ψ} {\omega}{ω}
{\vartheta}{ϑ}
{\varsigma}{ς}
{\varphi}{ϕ}
{\varpi}{ϖ}
}
{#1}
}
\ExplSyntaxOff
\begin{document}
$\xmathtt{abcαβγφϕΩ\alpha\beta\gamma\phi\varphi\Omega\varsigma}$
\end{document}
根据您的喜好或选择的字体,您可能想要将希腊字符替换为\phi
和\varphi
。
答案3
\documentclass{article}
\usepackage{unicode-math}
\setmonofont{NewCMMono10}[
Extension = .otf,
UprightFont = *-Regular,
ItalicFont = *-Italic.otf,
BoldFont = *-Bold.otf,
BoldItalicFont = *-BoldOblique.otf,
SmallCapsFeatures = {Numbers=OldStyle}
]
% Define a custom command for Greek typewriter characters
\newcommand{\greektexttt}[1]{\ensuremath{\text{\texttt{#1}}}}
\begin{document}
In math mode: $\greektexttt{abcαβγφϕΩΞεϖρ}$
\end{document}