All the questions I could find on this subject are about people who want to use \verb
in the argument passed to a command, or about people who want within a \newcommand to wrap one of the arguments within a \verb(atim)
.
Instead, I just want to use a \verbatim
environment within something like a \newcommand. More specifically, I've tried the following:
\newcommand \MyFoo {
blabla
\begin{verbatim}
hihi
\end{verbatim}
}
and as you probably all know, this doesn't work: the definition goes through, but when I try to use \MyFoo
I get an error about File ended while scanning use of \@xverbatim.
).
Strictly speaking, I don't need to use \newcommand
. What I have is a bunch of chunks (which contain plain normal text, as well as verbatim elements) stored in a file, and then I want to construct various documents from this by selecting various of those chunks: in one document I might want to use chunk 4, 7, and 9, while in another I might want 4, 6, 7, and 8.
The only solution I could find so far is to store each chunk in a separate file (so I just \input
the relevant chunk instead of calling a command containing the chunk), but editing hundreds of small files is much too inconvenient, so I'd much rather keep all the chunks in a single file.
I'm thinking of writing a script which extracts the relevant chunks, but I'm still hoping there's a more direct solution. Now that I think about it, I could also live with someway to set the list of enabled chunks somewhere, then \input
the chunks-file and within that file have each chunk be conditionalized on its inclusion in the list of enabled chunks.
\detokenize
would suffice, or even\texttt
in some cases.\texttt
at many places, but for multiline code samples, this is impractical. @Mico: yes, I'm using pdflatex. I'll take a look at your lualatex links, tank you.