如何在打字機字體中產生穩定的數學符號?

如何在打字機字體中產生穩定的數學符號?

首先,最小工作樣本如下。

\documentclass{article}

\newcommand*\ttand{\mathord{\texttt{\&}}}

\begin{document}

$\ttand$

\itshape$\ttand$

\end{document}

在此輸入影像描述

正如你所看到的,我在打字機字體中定義了一個數學符號 & 。但它並不穩定,因為它可能受到\itshape\bfseries等因素的影響。此外,它不能透過替換\texttt為來工作,\mathtt因為\mathtt它不能在 & 上工作。然後如何在打字機字體中產生穩定的數學符號?

答案1

您可以考慮用 包裹 & 符號\textnormal,然後將內部字體變更為等寬字體,以防止同一範圍內其他字體命令的干擾。這可確保 & 符號始終排版為中等粗細、直立和等寬字體。

\documentclass{article}

\newcommand*{\ttand}{\mathord{\textnormal{\ttfamily\&}}}

\begin{document}

\itshape $\ttand$ % shape

\bfseries$\ttand$ % weight

\sffamily$\ttand$ % family

\sffamily\scshape\bfseries$\ttand$ % or even all three!

\end{document}

答案2

我會用\mathtt.

\documentclass{article}

\newcommand*\ttand{\mathtt{\mathchar\inteval{"7000+`\&}}}

\begin{document}

text $\ttand$ text

\textit{text $\ttand$ text}

\end{document}

解釋:我們想要得到一個尊重目前數學組的符號,因此它的數學代碼應該是"70xx,其中"xx是 的 ASCII 代碼&。由於我懶得找後者,所以我使用簡單的算術。

相關內容