I'm writing a documentclass for creating exercise sheets and exams at school. For this purpose I created a boolean variable \g_test_showresults_bool which can be used to conditionally display the solutions/results of the exercises, so I can create one document without results for the students and one with the results for me.
I already created such a environment for "normal" content (text, math) but I am not able to create one for listings. I tried the solutions explained here but without success. I also found \lstnewenvironment, but I don't know how to include my boolean \g_test_showresults_bool here.
Here is my current template. I would also appreciate a macro instead of an environment.
\documentclass{article}
\usepackage{xparse}
\usepackage{listings}
\ExplSyntaxOn
\bool_new:N \g_test_showresults_bool
\bool_set_eq:NN \g_test_showresult_bool \c_true_bool
\NewDocumentEnvironment { reslstlisting } { } {
}{
}
\ExplSyntaxOff
\begin{document}
% Display this listing only if \g_test_showresults_bool is true
\begin{reslstlisting}
float i;
i = i + 6;
\end{reslstlisting}
\end{document}
expl3\bool-'variable' over a traditional\newif\ifshowresultand\showresulttrueand\showresultfalseusage here – Jun 24 '17 at 16:20l3keysand tried to focus to the usage of LaTeX3. A solution compatible withl3keyswould also be helpful. – dawu Jun 24 '17 at 16:29l3keysalso sets booleans. But your main problem is to produce the verbatim environment. Maybe you should search for a way to do that. Btw: Why don't you use one of the existing exercise packages? – TeXnician Jun 24 '17 at 17:19xsim(specifically packagexsimverb) manual page 50/51. That would support verbatim/listings... – TeXnician Jun 24 '17 at 17:44