# Latex tag for making a comment appear or disappear in pdf?

Is it possible to tag sections of your .tex file so that you can make text appear or not?

I have a long document and would like to be able to comment a certain section in each chapter, and produce two different pdfs, one with the comments, and one without.

I read about the \begin{comment} tag in the verbatim package. Is it possible to make this appear if I redefined the comment tag? How is this done?

(On suggestion, migrated this question from StackOverflow: http://stackoverflow.com/questions/3696128/latex-tag-for-making-a-comment-appear-or-disappear-in-pdf)

-

Yes, this is indeed possible, and it’s very simple, too: just redefine the comment environment as follows:

\renewenvironment{comment}{}{}


This will cause the comment text to be included as normal text.

-
That should be \renewenvironment{\comment}{}{} shouldn't it? I think I prefer this solution to mine... – Seamus Sep 12 '10 at 19:48
Thanks, that's perfect! – celenius Sep 12 '10 at 19:52
Actually, you don't want the backslash. Never mind. – Seamus Sep 12 '10 at 19:53

I'd recommend the comment package. You can use it something like this:

\usepackage{comment}
\includecomment{myspecial}


or

\excludecomment{myspecial}


then

\begin{myspecial}
I only want this paragraph in the special version of the output
\end{myspecial}


This will allow you to have multiple variations, should you ever need them. Each \includecomment{...} or \excludecomment{...} defines a new environment {...}. Everything placed in one of these environments can be "turned on or off" by switching between \includecomment and \excludecomment in the preamble.

-

The (relatively new) xcomment package has the ability to selectively typeset existing environments such as the table environment or the tikzpicture environment. Simply place the text

\usepackage{xcomment}
\xcomment{table,tikzpicture}


in the preamble, and then only the table environment and tikzpicture environment will be compiled.

-
I like this. Is there a way to have it the other way around? I mean, to specify environments to exclude rather than those to include? – mrbrich Sep 30 '14 at 21:55
I don't know of a method. The closest I have seen is to define environments that can be included or excluded using the comment package as highlighted in the answer above by Brent.Longborough. – Serge Oct 1 '14 at 22:44

You could use the ifdraft package, and compile the pdf once with the draft option, once without.

So have the text you only want to appear in one version inside \ifdraft{comment here}{}

The draft option causes some other stuff to work differently (hyperref doesn't include clickable links, for instance, unless you give it the final option when you call the package). So this option isn't as versatile as the currently accepted one. But if actually having several things happen differently when making draft version is desirable, then this is a viable approach.

-
This has a high likelihood of producing unintended consequences, as quite a few packages respond differently with the draft option. For instance, the microtype package doesn't do its magic when draft is in force. (It can be worked around: \usepackage[final]{microtype} but the chances of missing one such package seem high.) – vanden Sep 13 '10 at 3:55
I was kind of assuming that the two different versions were some kind of draft version and a "real" version. This is how I work, and it's actually useful to have other draft type stuff happen as well if this is the case. (e.g. included pictures appearing as blank space: saves printer ink for printed drafts...) I've edited my answer to give a warning. – Seamus Sep 13 '10 at 11:22