verbatim font in align environment

Is it possible to use the font of verbatim environment in align environment, please? I need to do so for a block of coding which is mathematic formulae itself. Thanks. If you like an example, please see below. In that picture, I wount like to combine the effect of align and verbatim.

\documentclass[]{article}

\usepackage{amsmath}

\begin{document}

\begin{align*}
a &= b+1 \\
&= c+2
\end{align*}

\begin{verbatim}
a = b+1
= c+2
\end{verbatim}

\end{document}

• With \texttt{formula}? – Arzigoglu May 17 '17 at 6:42
• Can you make a minimal example of what you need? – egreg May 17 '17 at 6:49
• @egreg Please see my update. – LaTeXFan May 17 '17 at 7:20
• @Arzigoglu I tried your suggestion, but it did not seem to work. – LaTeXFan May 17 '17 at 7:20
• Inside of align you could use \mathtt{formula} – Skillmon May 17 '17 at 7:23

The following works but gives ugly spacing (Thanks to Steven B. Segletes):

\documentclass[]{scrartcl}
\usepackage{amsmath}
\begin{document}
\begin{align}
\mathtt{a}&\mathtt{{}=b+1}\\%insert {} before = to get the spacing right
&\mathtt{{}=c+2}
\label{ha}
\end{align}
\end{document}


Another solution -- which I wouldn't use because it alters too much:

\documentclass[preview]{standalone}
\usepackage{amsmath}
\renewcommand*\familydefault{\ttdefault}% has to be used before mathastext
\usepackage{mathastext}
\renewcommand*\familydefault{\rmdefault}
\begin{document}
\begin{align}
a&=b+1\\
&=c+2
\label{ha}
\end{align}
\end{document}


To allow the font changes to be switched on and off, one can use the subdued-option of mathastext. Please note, that this does NOT leave the default math versions untouched! Read the package documentation and specifically the section dealing with subdued (1.3.3 as of writing this) for more information!

\documentclass[preview]{standalone}
\usepackage{amsmath}
\usepackage[subdued,defaultmathsizes,defaultimath,nohbar]{mathastext}
\MTDeclareVersion[n]{lmvtt}{T1}{lmvtt}{m}{n}
\renewcommand*\familydefault{\ttdefault}% has to be used before mathastext
\Mathastext[ttmath]
\renewcommand*\familydefault{\rmdefault}
\begin{document}
normal:
\begin{align}
a&=b+1\\
&=c+2
\label{ha}
\end{align}
\bgroup
tt-style:
\MTversion{ttmath}
\begin{align}
a&=b+1\\
&=c+2
\label{hatt}
\end{align}
\egroup
normal:
\begin{align}
a&=b+1\\
&=c+2
\label{haha}
\end{align}
\end{document}


• Let alone that you need to type mathtt all the time. – LaTeXFan May 17 '17 at 7:34
• Another complication is that I only want to use verbatim font in certain align environment but not all. So the second method might not work. – LaTeXFan May 17 '17 at 7:50
• @LaTeXFan Please see my edit! – Skillmon May 17 '17 at 9:10
• You can fix the first method by adding a blank atom to the left of the =, as in \mathtt{{}=b+1}. Likewise, \mathtt{{}=c+2} – Steven B. Segletes May 17 '17 at 10:09