Sign up ×
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.

I'm writing a document where some text portions are confidential and would therefore like to create an environment (e.g. confidential) which I can then exclude from the PDF by simply setting a variable or option.

Is there any way of doing this in LaTeX, or better yet, is there a package for this?

share|improve this question
If you want to simply remove/skip such environments then Joseph's solution is the way to go. If you want to replace the text with something else, e.g. empty space, than have a look at Phantom and line break, which could be modified to not even draw the underlining. – Martin Scharrer Sep 11 '11 at 10:16
Here are some attempts as solving this for inline or paragraph text that maintains the paragraph typesetting (hyphenation at line breaks - not supported by \phantom): Censor text spanning multiple lines. The soul package provided a good solution to tapping into the line breaking. – Werner Sep 11 '11 at 14:24

2 Answers 2

up vote 14 down vote accepted

You want the comment package. This provides the \includecomment and \excludecomment macros:

Some text

Some secret text

share|improve this answer
Nice, this works perfectly! Thanks! – gablin Sep 11 '11 at 15:05
I ran into a problem where I got a lot of errors about too many }s or missing \endgroups and it took a while to find out how to fix it: How to fix issues with closing the commented out environment – LJNielsenDk May 5 '13 at 11:08

One option is to use newcommand and renewcommand in conjunction:

\renewcommand{\condidential}[1]{} %Comment out this whole line to surpress exclusion.
    His name was \confidential{Frank}.

One advantage with this method is that you easily can style the text in different ways, and you can put a standard message to appear whenever something is excluded.

For example:


makes all the included, confidential information appear in bold.



makes all the confidential information, when excluded, replaced with a placeholder which says: CONFIDENTIAL.

You can also easily set up different environments for different needs. For example, if you want to have different levels of confidentiality, you can have a \superConfidential environment in addition to the \confidential environment.

share|improve this answer

Your Answer


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.