1

I want to create a long document that has environments for 1) problems, 2) solutions, 3) commentary. I would like to be able to easily create the associated pdf that includes, for example, all problems and solutions, but which omits all commentary. Is there a simple way to exclude everything that occurs within a certain environment?

2 Answers2

2

You can easily redefine an environment so that it ignores all the input. For example, you could write

\newenvironment{commentary}{\iffalse}{\fi}

Then you can redefine commentary as something more useful if needed to. If you want something easier to use, you can define a new if variable and use it within the definition of commentary.

0

The comment package does just what you need.

\documentclass{article}
\usepackage{comment}

\excludecomment{commentary}

\begin{document}

Problems and solutions

\begin{commentary}
This is commentary
\end{commentary}

Process commentary from now on.

\includecomment{commentary}

\begin{commentary}
This should print.
\end{commentary}
\end{document}
Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69
  • Can I do this with several different environments? Sometimes I might want to include problems, but neither solutions nor commentary. (I suppose I should look at the documentation of the comment package.) – Aaron Hill Oct 07 '16 at 18:59
  • Yes, you can do it with as many different environments as you like. If you want to put the answers at the end or in another document, see the answers package. – Ethan Bolker Oct 08 '16 at 00:25