1

I am composing some notes for a workshop which will have a mixed audience who use different statistical software packages. For the lab sessions, I wish to create a practice that contains questions and corresponding software codes.

My question: could anyone kindly recommend what are some methods to allow for switching some software code on/off so that I can i) just write the question once, and ii) compile different versions for different users?

Here is the scheme:

enter image description here

And I put the codes at the end as a minimal replicable example.

Ideally, it'd be great if I can incorporate a command (macro?) such as:

printSoftwareA
% printSoftwareB
% printSoftwareC

at the preamble so that I can switch them on or off. The reason I'd like to see them all in one document is that it'd be easier for me to main all the codes at once to ensure coherence between the software.

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{listings}
\definecolor{verbgray}{gray}{0.9}

\lstnewenvironment{code}{%
  \lstset{backgroundcolor=\color{verbgray},
  frame=single,
  framerule=0pt,
  basicstyle=\ttfamily,
  columns=fullflexible}}{}

\begin{document}

\section*{General text for all readers}

This is the text I'd like to show all readers.

\subsection*{How to do it in Software A}

\begin{code}
proc reg;
model y=x;
run;

\end{code}

\subsection*{How to do it in Software B}

\begin{code}
reg y x
\end{code}

\end{document}
2

Thanks to the pointer in the comment about the comment package! I figured that out. Here is my approach just in case others are planning to do the same:

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{listings}
\definecolor{verbgray}{gray}{0.9}

\lstnewenvironment{code}{%
  \lstset{backgroundcolor=\color{verbgray},
  frame=single,
  framerule=0pt,
  basicstyle=\ttfamily,
  columns=fullflexible}}{}

\usepackage{comment}

\includecomment{softwareA}
%\excludecomment{softwareA}

%\includecomment{softwareB}
\excludecomment{softwareB}

\begin{document}

\section*{General text for all readers}

This is the text I'd like to show all readers.

\begin{softwareA}
\subsection*{How to do it in Software A}
\begin{code}
proc reg;
model y=x;
run;
\end{code}
\end{softwareA}

\begin{softwareB}
\subsection*{How to do it in Software B}
\begin{code}
reg y x
\end{code}
\end{softwareB}

\end{document}

By toggling the includecomment{} and excludecomment{} I was able to achieve my goal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.