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?
Asked
Active
Viewed 361 times
1
-
Related/duplicate: Commenting out large sections – Werner Oct 07 '16 at 17:02
2 Answers
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.
Marco Lombardi
- 1,415
-
should be
{\iffalse\fi}{}instead of{\iffalse}{\fi}, but the edit is too short – Jo Mo Nov 17 '21 at 06:39 -
@JoMo Why? To me it seems that with your definition commentary does nothing. – Marco Lombardi Nov 18 '21 at 09:01
-
Hm, weird. And yours gave a compile error for me, if I remember correctly – Jo Mo Nov 18 '21 at 09:50
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
answerspackage. – Ethan Bolker Oct 08 '16 at 00:25