I found this cool posting for allowing you to include a minted or lstlisting environment inside of a call to a macro:
https://github.com/gpoore/minted/issues/54#issuecomment-58233667
The code
\makeatletter
\newcommand{\foo}{%
\begingroup
\let\do\@makeother\dospecials
\catcode`\{=1
\catcode`\}=2
\endlinechar`\^^J
\foo@i}
\newcommand{\foo@i}[1]{%
\endgroup\scantokens{#1\noexpand}%
\expandafter\foo@cleanup}
\def\foo@cleanup#1^^J{#1 }
%http://tex.stackexchange.com/questions/71049/allow-macro-to-end-without-new-line
\makeatother
I understand that I can use saveboxes, but I do not want to. Substitution \foo for \question, I am trying to implement the equivalent of
\newcommand{\question}[1]{
\noindent\fcolorbox{black}{gray!11}{
\begin{minipage}[t]{0.97\textwidth}
\vspace*{1ex}
#1
\vspace*{1ex}
\end{minipage}
}
}
The problem is after hours of digging around the web, I can't get a clear picture on how this would work. I've tried to make new environments, play with tcolorbox, a bunch of different things. I thought I was making progress when I used \minipage{...} in the first part before \foo@i, and then \endminipage before the \endgroup, and quickly realized that this was not doing what I thought it was. The same goes for \tcolorbox and \endtcolorbox in the same locations.
So basically, is it possible to begin something like a minipage or (t/f)colorbox and wrap it around this? I cannot put something like \tcolorbox[colors etc]{\foo@i}} as the last line (right after \endlinechar), or really any other variant. At this point, endlessly permuting where these commands go is fruitless and I feel I need to be doing something differently.
Thank you for any pointers, e.g. a hacky way to get { and } in. I tried to use the catcodes but I think I'm missing the bigger picture.
The idea would be to use the macro in a situation like this:
\question{
\paragraph*{5: A question from my prof}
Consider some stuff about things i want you to solve:
\begin{minted}{matlab}
for i = 1:n
x(i) = x(i) + 1;
end
\end{minted}
Show that this is a thing that can be done yay.
}