Related with "Can I change all math output to use monospaced text?", is it possible to use the monospace math only inside \texttt
(or other custom command)?
I tried to include the \everymath
inside a group, but it seems it's not working until after I use some math:
\documentclass{minimal}
\usepackage{amsmath}
\newcommand{\ttmath}{\everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}}
\newcommand{\val}[1]{\bgroup\ttmath\texttt{#1}\egroup}
\begin{document}
\val{1\ensuremath{\ensuremath{\cdot}10\ensuremath{^{-6}}}}
\ensuremath{a_0}, \ensuremath{m_{\text{e}}}).
\val{1\ensuremath{\ensuremath{\cdot}10\ensuremath{^{-6}}}}
\end{document}
Note that the first 10^-6 does not use monospace font, but the second does. a_0 and m_e use normal math font, which is fine.
I can get it fixed by adding \ensuremath{}
between \ttmath
and \texttt
, but is there a cleaner way?
PS. Please forgive the ugly code full of \ensuremath
, it's being generated from XML.
PPS. Without XeTeX or LuaLaTeX, please.