How do I detect whether or not I'm in teletype mode in LaTeX? I'm looking for something like \ifmmode or \mathpalette or \mathchoice.

Perhaps this is an xy problem, so let me give my original context: I'd like to define versions of some operators that work well in texttt. For example, I'd like a version of \vdash that works well enough in a monospaced font. Here I can define separate ones for tt mode and normal mode, but I'd like a single command that picks which one to use depending on the mode:

\noindent \texttt{abcdefghijklmnopqrstuvwxyz} \\
\noindent \texttt{a$\vdash$cdefghi$\vdash$klmnopqrstuvwxyz} \\
\noindent \texttt{abcdefghijklmnopqrstuvwxyz} \\
\noindent \texttt{a\bettervdash cdefghi\bettervdash klmnopqrstuvwxyz} \\
\noindent \texttt{abcdefghijklmnopqrstuvwxyz} \\
\noindent $abc\bettervdash def$ \\
\noindent $abc\vdash def$ \\

rendered document

Thoughts I've had:

  1. I can try to parse \the\font, looking for tt
  2. I can condition on whether \widthof{i} and \widthof{m} are equal

Is there a better way? If not, is there reason to believe that one of these will work more uniformly than the other?

  • 1
    there is certainly no guarantee that a monospace font will have tt in its name Courier for example, or Consolas as used in this site – David Carlisle Jul 18 at 20:13

Your Answer

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

Browse other questions tagged or ask your own question.