I am trying to typeset some mathematics all in typewriter font; aiming to emulate the appearance of a particular computing environment. However, \mathtt in math mode doesn't appear to affect the symbols. For example, in something like:

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

the braces and \times symbol will be in ordinary math symbols. I can obtain the affect with something like

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

except that this is getting pretty clumsy, and the texttimes symbol is too small. And then there are symbols such as \Rightarrow which don't seem to have a typewriter equivalent. (There is a \textrightarrow for a single arrow, but I need a double arrow.)

I have found that \usepackage[T1]{fontenc} makes no difference.

So - is there any easy way of obtaining a math formula all in typewriter font, without resorting to using masses of \text... control sequences?

  • For example $\mathfrak{c}=2^{\aleph_0}$ in typewriter font? Impossible! – Przemysław Scherwentke Jun 19 '13 at 1:28
  • Did you solve this for \Rightarrow? – Joachim Breitner Jan 13 '16 at 11:36

You can use mathastext to partially obtain what you are aiming at.

\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

And here is the effect of math alphabet without mathastext:

no mathastext

  • That looks very good! I'll give mathastext a try. In the meantime, I'm managing with cmtt10, and other symbols such as \texttimes as I need them. Thank you for your long and detailed response to my query. – Alasdair Jun 20 '13 at 23:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.