I want to create a documentation .pdf that shows examples of code for my commands and also what the result is.
To prevent differences between the description and the result I thought about creating a command to handle that:
\documentclass{article}
\NewDocumentCommand{\example}{m}
{
#1
\par
\begin{verbatim}
#1
\end{verbatim}
}
\NewDocumentCommand{\myfunction}{O{default}m}
{
#1: This should be #2
}
\begin{document}
\example{\myfunction[Nobody]{quite easy}}
\end{document}
The problems seems to be the verbatim section since it does not only get the contents of #1 but seems to take whatever is put into the brackets of \example until \end{verbatim} is found (which never comes)... Is that the case? If so, how to prevent it?
P.S.: Using \verb|#1| also did not work...

\verbenvironment not the other way around. – mrCarnivore May 15 '23 at 08:18varg type) then use\scantokens(or write to a file and read back) to execute – David Carlisle May 15 '23 at 08:25