Using \ verbatim as part of an argument for a macro?

Most of the things I wanted to do in LaTeX were either straightforward or easily detectable on the Internet, but that pushed me.

I have a โ€œsolutionโ€ macro: apply some general formatting to each solution:

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

This works well so far, but now I wanted to include a drawing that I made quickly using "ASCII Art", so I would like to use \ verbatim. But it does not work, it causes the following errors:

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

From what I read in "Not So Short Introduction to LaTeX", \ verbatim cannot be used that way. I guess there is a better way to do what I'm trying to do?

+4
source share
3 answers

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

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

This is a FAQ .

+2
source

Use cprotect package

eg. (with tcolorbox, but it works with most of the newly created team)

 \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} } 
0
source

All Articles