14

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?

  • 3
    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
  • 2
    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
17

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

\documentclass{article}
\usepackage{comment}
\excludecomment{confidential}
\begin{document}
Some text

\begin{confidential}
Some secret text
\end{confidential}

\end{document}
1

One option is to use newcommand and renewcommand in conjunction:

\documentclass{article}
\newcommand{\confidential}[1]{#1}
\renewcommand{\condidential}[1]{} %Comment out this whole line to surpress exclusion.
\begin{document}
    His name was \confidential{Frank}.
\end{document}

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:

\newcommand{\confidential}[1]{\textbf{#1}}

makes all the included, confidential information appear in bold.

Further,

\renewcommand{\condidential}[1]{\textbf{CONFIDENTIAL}}

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.

0

If you find the comment package (as suggested by Joseph Wright's answer) giving you trouble when using its comment environment inside some complex structures like footnotes, use the version package which appears to be a drop-in replacement:

\documentclass{article}
\usepackage{version}
\excludeversion{confidential}
\begin{document}
Some text

\begin{confidential}
Some secret text
\end{confidential}

\end{document}

It also works inside a footnote:

\documentclass{article}
\usepackage{version}
\excludeversion{confidential}
\begin{document}
Some text

\begin{confidential}
Some secret text
\end{confidential}

\footnote{A footnote.
\begin{confidential}
\item Some secret text
\end{confidential}
}

\end{document}

Thanks to muk.li for sharing this in another post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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