Question

Most things I've wanted to do in LaTeX have either been straight-forward, or easily found on the web, but this one has been stumping me.

I have a macro 'solution': to apply some common formatting to each solution:

\newcommand\solution[1]{{\\ \\* \bf Solution.}#1\qed \newpage}

Which has worked nicely so far, but now I wanted to include a drawing which I've done quickly using 'ASCII Art' so I'd like to use \verbatim. But it doesn't work, it produces the following errors:

Runaway argument?
...
! File ended while scanning use of \@xverbatim.

From what I read in the "Not So Short introduction to LaTeX", \verbatim can't be used this way. I assume there is a better way to do what I'm trying to do?

Was it helpful?

Solution

You could try changing \newcommand to \newenvironment and then use something like

\begin{solution}
  \begin{verbatim}
    [ascii art here]
  \end{verbatim}
\end{solution}

OTHER TIPS

This is a FAQ.

Use the package cprotect

e.g. ( with tcolorbox but it is working with most of the newcommand created)

\usepackage{tcolorbox}
\usepackage{cprotect}

\newcommand{\tcb}[1] {
 \begin{tcolorbox}   [arc=0mm,colback=bginf,coltitle=black!70!black,colframe=black!30!white,width=\linewidth,fontupper=\bfseries\small,halign title=flush center,halign upper=center]
#1
\end{tcolorbox}
}


\cprotect\tcb{\scriptsize
     \begin{verbatim}
...
     \end{verbatim}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top