4

I tried to use the commands defined here: Can I change all math output to use monospaced text? to change the font in the math environment. However, the following code does not compile:


\everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}
\everydisplay{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}
    \begin{align*}
        T = \{
              \alpha : A \subseteq B,\\
               \beta : B \subseteq C\\
            \}
    \end{align*}

It compiles correctly in normal math mode (without using "align" and line breaks), or without the commands to change the font. How can I modify the font used inside the align environment to typewriter? (Similar to: \newenvironment where all text is typewriter (like \texttt) , but in math mode)

I would like to write something like:


    \begin{ttalign*}
        T = \{
              \alpha : A \subseteq B,\\
               \beta : B \subseteq C\\
            \}
    \end{ttalign*}

where the environment "ttalign" behaves likes "align", but with the typewriter font instead of the normal font.

2
  • Welcome to TeX.SE. Have you looked into the mathastext package?
    – Mico
    Commented Sep 5, 2016 at 13:46
  • I looked into it after reading your comment. However, I did not understand how to use it to define a new environment. I edited my post to better describe what I want. Could you please elaborate more on how to use mathastext to achieve the align+typewriter effect? Thanks. Commented Sep 5, 2016 at 16:25

2 Answers 2

3

You don't need to reset \tmp every time: when you use \mathtt once, the relative math group is allocated and will no longer change.

\documentclass{article}
\usepackage{amsmath}

\newenvironment{ttmath}
 {\everymath{\ttmathgroup}\everydisplay{\ttmathgroup}}
 {}

\AtBeginDocument{%
  $\mathtt{\xdef\ttmathgroup{\fam\the\fam\relax}}$%
}

\begin{document}

\begin{align*}
T = \{
      &\alpha : A \subseteq B,\\
      &\beta : B \subseteq C\\
    \}
\end{align*}

\begin{ttmath}
\begin{align*}
T = \{
      &\alpha : A \subseteq B,\\
      &\beta : B \subseteq C\\
    \}
\end{align*}
\end{ttmath}

\end{document}

enter image description here

You can define a ttalign* environment, if you prefer:

\newenvironment{ttalign*}
 {\everymath{\ttmathgroup}\everydisplay{\ttmathgroup}\csname align*\endcsname}
 {\endalign}
0

Since I was already using xparse, I defined a new environment this way:

\NewDocumentEnvironment{ttmath}{}{\begingroup\everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}}{\endgroup}

And then, combined with the original align environment:

\begin{ttmath}
  \begin{align*}
        T = \{
            &\alpha : A \subseteq B,\\
            &\beta : B \subseteq C\\
        \}
    \end{align*}
\end{ttmath}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .