2

With normal text, I have the choice between \texttt{…}, which applies the font change to an argument, and \ttfamily, which applies it to the rest of the group.

In math mode, I have the former, with \mathtt{…}. What is the equivalent of \ttfamily in math mode?

(Why can’t I use \mathtt? Because I want to apply the change in a >{…} column spec, together with lhs2Tex.)

Mico
  • 506,678
  • Are you using one of the "standard" LaTeX document classes (article, report, book) or a document class that's based on one of these classes? If so, >{\tt} works just fine in math mode. – Mico Feb 25 '18 at 19:47
  • 1
    @Mico actually that or in general \DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt} is perhaps a cleaner answer than mine (although it's the same thing really) you should probably post as answer. – David Carlisle Feb 25 '18 at 20:08
  • @DavidCarlisle - Done. :-) – Mico Feb 25 '18 at 20:20
  • 1
    @Mico voted! (somehow I hadn't seen your comment, although the site says it was posted 20min before my answer:-) – David Carlisle Feb 25 '18 at 20:24

2 Answers2

4

Probably an abuse of syntax but anyway you can use

enter image description here

\documentclass{article}

\begin{document}


$\mathtt{\global\count1\fam}\fam\count1 abc=xyz$

\end{document}
David Carlisle
  • 757,742
1

If you use one of the "standard" LaTeX document classes (article, report, book) or a document class that's built on one of these classes, you could use >{\tt} as the "prefix" to the relevant column type. A full MWE (minimum working example):

\documentclass{article}
\usepackage{array}
\begin{document}
$\begin{array}{>{\tt}c}
   aaaa
\end{array}$
\end{document}

The KOMA-Script document classes (e.g., scrartcl, scrreport, scrbook) and the memoir class no longer define \tt. If you use one of these classes, you will also need to provide the following directive in the preamble:

\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}

as well as \usepackage{array}. A suitably modified MWE:

\documentclass{scrreprt} % or: \documentclass{memoir}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\usepackage{array}
\begin{document}
$\begin{array}{>{\tt}c}
   aaaa
\end{array}$
\end{document}
Mico
  • 506,678