帶有 \symtt (或 \mathtt)的希臘打字機字符

帶有 \symtt (或 \mathtt)的希臘打字機字符

我想要在數學模式下使用希臘打字機字元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}

相關內容