# Verbatim math inside tabular or align environment?

Is it be possible to display a table with both typeset math expressions and verbatim renderings the corresponding input for those expressions?

For example, something like the first two lines of output shown below, but within a tabular or align environment. (The last two lines of the output give almost what I want, but of course lack display of /.)

The source for the above is:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\noindent
$X \vee Y$ \qquad \verb!X \vee Y!
\\
$X \wedge Y$ \qquad \verb!X \wedge Y!

\noindent
\begin{align*}
X \wedge Y &\qquad \texttt{X  wedge Y}
\\
X \vee Y &\qquad \texttt{X vee Y}
\end{align*}

\end{document}


Of course I am aware of how to do this when just text is involved, as considered, e.g., in: How use fancyvrb to show both result and verbatim text?.

A mathemartical aside

Somewhat confusingly, the symbol \vee is used in topology to denote the wedge sum, whereas the symbol \wedge is not (it's used for the smash product).

• While you can get verbatim into an align, the easist would probably be to stick with tt text, as in \texttt{X \char92 wedge Y} – Steven B. Segletes Apr 9 '20 at 19:49
• You can do \texttt{X \string\wedge\ Y} and \texttt{X \string\vee\ Y}. – Werner Apr 9 '20 at 19:49
• Drat, I forgot about the \string command! – murray Apr 9 '20 at 19:58
• The problem is that align* absorbs the text up to \end{align*} as the argument to a macro, so \verb is not allowed. – egreg Apr 9 '20 at 20:00

You can write some code to format both input and output at the same time:

\documentclass{article}

\usepackage{amsmath}

\makeatletter
\newcommand{\mathandcode}[1]{%
\mbox{$#1$} &
\mbox{\ttfamily \detokenize{#1}}% https://tex.stackexchange.com/a/139980/5764
}

\begin{document}

\begin{tabular}{ l l }
\mathandcode{X \vee Y} \\
\mathandcode{X \wedge Y}
\end{tabular}

\end{document}

• Perhaps the simplest yet! – murray Apr 11 '20 at 20:20

You could use a tabular as shown in the following example:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}

\begin{tabular}{>{$}l<{$}l}
X \vee Y & \verb!X \vee Y!
\\
X \wedge Y & \verb!X \wedge Y!
\end{tabular}

\end{document}

• This way seems a lot simpler than having to use \string. – murray Apr 9 '20 at 19:59