I am writing a simple LaTeX guide, aimed at editors of a student paper. The paper is for students of mathematics and physics at my university, and so we use LaTeX.
Anyways, I want to include lots of examples in the guide, but it has become a bit cumbersome. I am using the following format right now:
\hspace{20pt}
\begin{framed}
\begin{minipage}{0.8\textwidth}
\begin{verbatim}
Some code
\end{verbatim}
$\quad \Rightarrow$\\
\mbox{}\\
Some code
\end{minipage}
\end{framed}
The line `` Some code
'' Is first shown verbatim, and then put outside in order for it to compile completely, showing the output.
I wanted to simplify this into a single command, something like
\newcommand{\verandshow}{1}
{
\hspace{20pt}
\begin{framed}
\begin{minipage}{0.8\textwidth}
\begin{verbatim}
#1
\end{verbatim}
$\quad \Rightarrow$\\
\mbox{}\\
#1
\end{minipage}
\end{framed}
}
but the verbatim
environment messes everything up. The same goes for creating a new environment, and putting the \begin{verbatim}
and \end{verbatim}
statements in each end.
I have heard of alternative ways of showing code, like listings
and others, but they did not work all that well. And even if they did, a question remains unanswered, one that I haven't found a simple answer to, which is: How do you define a command or environment that puts arguments into a verbatim environment?
did not work all that well
mean? Please have a look on the thetcolorbox
package and itslistings
library. It does show latex code and it's output (for not too complicated code of course)