3

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 /.)

Displaying input and output of math expressions

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).

murray
  • 7,944

2 Answers2

4

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

enter image description here

\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}
leandriis
  • 62,593
3

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

enter image description here

\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}
Werner
  • 603,163