# Tabular environment within the \newenvironment

I'm writing a book, in which we refer the reader to the CD-ROM for the source code, and tell him the compiler and the result of running the program. Here's an example:

Since this "template" is happening a lot in the book, I decided to define a new environment for it (the command \cprotEnv used below is from the package cprotect):

\newenvironment{CDROM}[2]
{\begin{tabular}{| m{0.5in} m{0.3in} m{5in} |}
\hline
\includegraphics[width=0.5in]{CD-ROM.pdf} && #1 \\
& \includegraphics[width=0.3in]{Hand.pdf} &
We used the free compiler #2. \\
& \includegraphics[width=0.3in]{Hand.pdf} &
}
{\\ \hline \end{tabular}}

\cprotEnv\begin{CDROM}{\verb"\SampleCodes\C++\GetPageSize"}{Open Watcom}
The page size for this system is 4096 bytes.
\end{CDROM}


However, the output is something peculiar:

The problem is that \cprotEnv is thought for particular environments such as align that don't accept verbatim in their body. If your schemes are always like the example, with two "handed lines", it's easier to define a command rather than an environment:

\newcommand{\CDROM}[3]
{\begin{tabular}{| m{0.5in} m{0.3in} m{5in} |}
\hline
\includegraphics[width=0.5in]{CD-ROM.pdf} && #1 \\
& \includegraphics[width=0.3in]{Hand.pdf} &
We used the free compiler #2. \\
& \includegraphics[width=0.3in]{Hand.pdf} & #3\\ \hline \end{tabular}}


and then use it as

\cprotect[mmm]\CDROM{\verb"\SampleCodes\C++\GetPageSize"}{Open Watcom}
{The page size for this system is 4096 bytes.}


A way that frees you from \cprotect is

\newcommand{\CDROM}{\begingroup\catcode\#=12 \xCDROM}
\newcommand{\xCDROM}[3]
{\begin{tabular}{| m{0.5in} m{0.3in} m{5in} |}
\hline
\includegraphics[width=0.5in]{CD-ROM.pdf} &&
\ttfamily\catcode\\=12 \catcode\ =9
\scantokens{#1} \\
& \includegraphics[width=0.3in]{Hand.pdf} &
We used the free compiler #2. \\
& \includegraphics[width=0.3in]{Hand.pdf} & #3\\ \hline \end{tabular}\endgroup}


and now

\CDROM{\SampleCodes\C++\GetPageSize}{Open Watcom}
{The page size for this system is 4096 bytes.}
\CDROM{\SampleCodes\C#\GetPageSize}{}{}


work without \verb. This, however, assumes that you don't need spaces in the "verbatim" first argument.

By splitting the command into two parts we can ensure that the # character is not doubled as it would happen if we added \catcode\#=12 along with the other settings.

• Great, thanks! Just one point: The second approach prints unwanted spaced and the command \endinput; i.e. instead of \SampleCodes\C++\GetPageSize it prints \SampleCodes \C ++\GetPageSize \endinput. – M.S. Dousti Jul 18 '11 at 12:43
• See edited answer; if you don't need spaces in that argument it's more practical. – egreg Jul 18 '11 at 12:51
• Sorry, one more problem: If I try something like \CDROM{\SampleCodes\C#\GetPageSize}{}{}, I get an error related to the use of #. I can't escape it since the catcode of \ has changed. I can't change the catcode of # since I need it to define #1, #2, and #3. What can I do? – M.S. Dousti Jul 22 '11 at 5:45
• You find the new definition. – egreg Jul 22 '11 at 7:47