tt 字体的数学符号

tt 字体的数学符号

我正在尝试用打字机字体排版一些数学公式;旨在模拟特定计算环境的外观。但是,\mathtt在数学模式下似乎不会影响符号。例如,在类似以下内容中:

$\mathtt{\{a[1],t\}\times\{t,a[2]\}}$

括号和\times符号将以普通数学符号表示。我可以用类似这样的方法获得效果

\newcommand{\tbl}{\textbraceleft}
\newcommand{\tbr}{\textbraceright}
\texttt{\tbl a[1],t\tbr\texttimes\tbl t,a[1]\tbr}

只是这个符号太笨拙了,而且texttimes符号太小了。还有一些符号,例如,\Rightarrow似乎没有打字机对应的符号。(有一个\textrightarrow表示单箭头的,但我需要双箭头。)

我发现那\usepackage[T1]{fontenc}并没有什么区别。

那么,有没有简单的方法可以获取全部用打字机字体表示的数学公式,而无需使用大量的\text...控制序列?

答案1

您可以使用数学文本部分地实现你的目标。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[vscale=0.7]{geometry}
\usepackage[subdued,defaultmathsizes]{mathastext}
\MTnonlettersobeymathxx     % math alphabets will act on (, ), [, ], etc...
\MTexplicitbracesobeymathxx % math alphabets will act on \{ and \}
\MTfamily {\ttdefault}      % we will declare a math version using tt font
\Mathastext [typewriter]    % the math version is called typewriter

\begin{document}\thispagestyle{empty}

So far everything is normal $ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>$.
Indeed, we are here in the \emph{subdued} mode of mathastext. 

Let's see the effect of \string\mathtt\ or \string\mathrm\ or \string\mathbf:

\[ \mathtt{ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>}\]

\[ \mathrm{ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>}\]

\[ \mathbf{ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>}\]

You should compare with a document not loading mathastext, and you will see
there that the math alphabet commands do not act on parentheses, etc... 

I must dwelve on a subtelty: in the \emph{subdued} mode, the \string\mathrm,
etc.. commands are not modified by \texttt{mathastext}: it defines altered
variants \string\Mathrm, etc... but does not identify the original with the new.
For some matters of font encoding, it is the variants which should be used (the
problem didn't show in the examples above, but it was just lucky):

\[ \Mathtt{\{a[1],t\}\times\{t,a[2]\}} \]

\[ \Mathbf{\{a[1],t\}\times\{t,a[2]\}} \]

\texttt{mathastext} has limited influence: we see that the \string\times{}
symbol is not affected. We now will switch to the typewriter math version using
the command \string\MTversion \{typewriter\}. In this math version, we are not
in \emph{subdued} mode anymore, and the lowercase form of the math alphabets can
be used directly. \MTversion {typewriter}
\[ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>\]
\[ \{a[1],t\}\times\{t,a[2]\} \]
\[ \mathit{\{a[1],t\}\times\{t,a[2]\}} \]
By default the text font is also modified. Perhaps we
don't want that, so we issue \string\MTversion [normal]\{typewriter\}.\MTversion
[normal]{typewriter} This way the text font is not affected. But the math is
automatically in typewriter font (not the delimiters though):

\[ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>\]

The idea of the math version is to typeset only portions of the code with the
desired fonts for the letters and simple symbols in math. We return to the
normal situation with \string\MTversion \{normal\}. Here it is:
\MTversion {normal}
\[ (a^n +b^n)[c^m +d^m] = \left<x_i + y_j\right>\]

Because we switched back to the subdued version, we have to explicitely
reactivate the action of the math alphabets on the non letters (from the ascii
range), with 
\string\MTnonlettersobeymathxx{}
and \string\MTexplicitbracesobeymathxx{}

\MTnonlettersobeymathxx{}
\MTexplicitbracesobeymathxx{}
$\Mathtt{\{a[1],t\}\times\{t,a[2]\}}$

$\Mathit{\{a[1],t\}\times\{t,a[2]\}}$

$\Mathbf{\{a[1],t\}\times\{t,a[2]\}}$

And I was careful to use \string\Mathtt{} and \string\Mathit, not
\string\mathtt{} or \string\mathit.  
\end{document}

数学文本

以下是没有使用 mathastext 的数学字母表的效果:

没有数学文本

相关内容