18

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?

  • 2
    Have a look at the \everymath command, and also eqnarray-vs-align for reasons to avoid eqnarray – cmhughes Jul 11 '12 at 16:46
19

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.

  • This is great, thank you. How would I reset the presentation of math LaTeX for later use? E.g. if I want monospace for some math blocks in a document using your solution, but want the default math presentation for everywhere else in the document? – Rob Stewart Jul 1 '15 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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