Like displaymath, but without math-mode

I often find myself doing things like

$\begin{tabular}{cc} foo & bar \\ baz & qux \end{tabular}$


or

$\begin{verbatim} code snippet \end{verbatim}$


to put a table or code snippet into my document without making it float. I'm using $...$ because I like the way it centres its contents and leaves a little vspace above and below it. But of course $...$ also puts me in math-mode, which is not what I want.

What's the equivalent of $...$ that doesn't put me into math-mode?

In fact (if I may delve into 'opinion-based' territory for a moment), I am of the opinion that $...$ should not enter into math-mode at all. Consider something like:

Finally, our equation becomes
$x^2 = y^2 - z^2,$
which is easily proved.


I often want to include a comma (or a full-stop, or whatever) with the equation, in order to make it flow with the rest of the surrounding text. But the comma should not be typeset in math-mode, because it is not a mathematical comma, it is a textual comma. So what I really want to type is:

Finally, our equation becomes
\begin{some-suitable-environment}
$x^2 = y^2 - z^2$,
\end{some-suitable-environment}
which is easily proved.


so that I can delimit the piece of the centred text that is actually math. Is this a sensible suggestion? Does some-suitable-environment exist?

• $\begin{verbatim} produces ! Missing  inserted. <inserted text>  l.5 \begin{verbatim}  Apr 23, 2015 at 20:55 • to place a comma in the surrounding text font, just use \[a=b \text{,}$ May 5, 2015 at 14:28
• @DavidCarlisle Mm, that works. But, speaking idealistically rather than pragmatically, it's a bit dissatisfying to have to switch from the surrounding text-mode, to math-mode (with $...$) and back to text-mode (with \text{...}). In other words, I would prefer the document markup to emphasise that the comma is not part of the equation. May 5, 2015 at 14:32
• You appear to have changed the question, thus invalidating existing answers. Your original question was (mostly) about non-math usage and for example gave an example of verbatim (which, along with any other display environment will not work with your answer) If you want to ask about punctuation in math displays that is a different question and a duplicate of the related question in the right sidebar What could be more highlighting that it is not math than a command called \text ? May 5, 2015 at 14:38
• If you want a text comma (but why would you?), just type \text{,}. You're “solving” a problem creating many others: if you try your solution with \sum in the formula and compare it with a standard displaymath environment, you'll see what I mean. May 5, 2015 at 18:00

\begin{center}...\end{center}

\>
which is easily proved.


and ensures that the comma after the equation is set in the correct (text-mode) font.

• If you use \mbox\bgroup the argument of \mbox is just \bgroup not the tokens between \bgroup and \egroup the fact that it sort of accidentally produces something that does not generate an error is an accident of the expansion process. Your example is now using display math vertical spacing but inline math setting, which is odd to say the least. May 5, 2015 at 14:06
• Oh. I thought it a bit odd that \mbox works in this definition but \text doesn't. Thanks for the tip about the display/inline -- I guess I would need a \displaystyle in there somewhere. Hm, all a bit of a mess! May 5, 2015 at 14:34
• It's a "mess" because it is fundamentally abusing display math, so further additions to try to hide that just add complication on complication. May 5, 2015 at 14:40
• @JohnWickerson If that's your only worry, why not \makeatletter \begingroup\lccode\~=\,\lowercase{\endgroup\def~}{\@ifnextchar\]{\text{,}}{\mathpunct{\mathchar\,}}} \makeatother \AtBeginDocument{\mathcode\,="8000 }? That is, make , math active to check if the next token is \] and, in that case, output a “text comma”. May 5, 2015 at 19:05
• @Manuel Also , \end{align}, \end{gather} and so on, with the problem that you can't check for \end{align} following the comma. Too complicated. May 6, 2015 at 10:35