[Tex/LaTex] change all math output to use monospaced text

fontsmath-modetypewriter

Is there any way of modifying the preamble, so instead of typing

$\mathtt{x}$ ...
\begin{eqnarray}
    \mathtt{y} & \mathtt{=} & \mathtt{z^\pi}
\end{eqnarray}

I can omit the \mathtt{…} commands?

Best Answer

You can add

 \everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}

to the document preamble (or the part of the document where you need this)

and

 \everydisplay{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}

if you need display math as well.


In then in addition you may need to force the initialisation by putting

\setbox0\hbox{$ $} 

in the preamble otherwise the first expression may not be initialised correctly. This just makes an empty math expression on a box and discards it to avoid the problem.