I would like to make a table showing some custom commands that I have defined. It would be nice if I could do something like the following.
\documentclass{article}
\newcommand{\reals}{\ensuremath{\mathbf{R}}}
\newcommand{\CodeExample}[1]{\verb~#1~ & #1 \\}
\begin{document}
$$
\begin{array}{r@{\qquad}r}
\CodeExample{\reals}
\end{array}
$$
\end{document}
I want the left column of my table to be the LaTeX code, and the right column to be the typeset output. However, my code places the typeset output in both columns. Is there anyway to make this work, or do I need to manually enter both columns of my table?
Thanks everyone for your help! I would like to do one more thing: define an environment to generate the table of code examples. Here is my attempt.
\documentclass{article}
\usepackage{array,xparse}
\NewDocumentCommand{\CodeExample}{v}{#1 & \scantokens{#1} \\}
\newenvironment{CodeExamples}[1]
{
\begin{center}
\begin{tabular}{|>{\ttfamily}l|>{$}l<{$}|}
\hline
}
{
\hline
\end{tabular}
\end{center}
}
\newcommand{\reals}{\ensuremath{\mathbf{R}}}
\begin{document}
\begin{CodeExamples}
\CodeExample{\reals}
\CodeExample{\reals^{n}}
\end{CodeExamples}
\begin{CodeExamples}
\ \CodeExample{\reals}
\CodeExample{\reals^{n}}
\end{CodeExamples}
\end{document}
There are two problems with my environment. First, I need the ensuremath in my definition of the reals macro; otherwise, I get a "mathbf only allowed in math mode" error. Second, the environment seems to be eating the first character of the input: that is why I added the extra space in the second example of the CodeExamples environment.

showexpl. Check out some examples of usingshowexpl. – Werner Feb 07 '13 at 07:28\[…\]preferable to$$? – Werner Feb 07 '13 at 07:29