Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
add comment

4 Answers 4

up vote 8 down vote accepted

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.

share|improve this answer
    
That should be \renewenvironment{\comment}{}{} shouldn't it? I think I prefer this solution to mine... –  Seamus Sep 12 '10 at 19:48
1  
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
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
2  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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