2

Problem

I am now preparing exercises for the course I am going to teach next quarter. I have two concerns

  • Writing problem descriptions and corresponding solutions in two separated files are pretty annoying since it may require lots of copy and paste in later days.
  • Using hyperlinks to jump between problem description and solution is also annoying since some problem descriptions are rather long and involving a lot of fine details, which would make both my life and students' life harder.

I am wondering if there is a mechanism that could hide selected part of the text from global setting. I know I could use comment but

  • It seems that I need to comment all individual spots. I do not know how to comment all the parts I need to comment (there are more than 200 exercises I am planning to write).
3

Here is one way using etoolbox and environ:

\documentclass{article}
\usepackage{environ}
\usepackage{etoolbox}

\newtoggle{doPrintStuff}        % the toggle is initially false

% Uncomment this if you don't want spaces after \end{maybePrint} to be
% discarded (the default is \environfinalcode{\ignorespacesafterend}, which
% causes such spaces to be ignored):
%
%\environfinalcode{}

\NewEnviron{maybePrint}{%
  \iftoggle{doPrintStuff}{\BODY}{}%
}

\begin{document}
X%
\begin{maybePrint}
  $\langle$environment contents$\rangle$
\end{maybePrint}
Y

\toggletrue{doPrintStuff}

X%
\begin{maybePrint}
  $\langle$environment contents$\rangle$
\end{maybePrint}
Y

X%
\begin{maybePrint}%
  $\langle$environment contents$\rangle$%
\end{maybePrint}
Y
\end{document}

Screenshot

  • I really like solution, which is more flexible than the one previously provided by Marian. I think I will use this one when compiling those exercises. – Mr.Robot May 16 at 6:40
2

You can define your macro, e.g., \comment that hides its content when some if-switch is activated. The following code introduces such a macro and the visibility of the \comment-content can be handled by enabling/disabling the \commenttrue part.

\documentclass{article}

\newif\ifcomment


\def\comment#1{%
    \ifcomment\relax\else #1\fi}

% \commenttrue


\begin{document}
%------------------------
Problem statement\dots

\comment{Solution of the problem: \dots}
%------------------------
\end{document}

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.