6

Is there any command which allows me to make some blocks of text invisible only if initially I said so?

I.e., I would like to mark some lines throughout the text that would only appear in the compiled pdf if in the beggining of the document I said something like: "those blocks of text ON"; and I don't want them to appear if I said something like "those blocks of text OFF".

The purpose of this is to generate two different documents: one with more deitailed information and another one without those details.

Note that this is not the same as the phantom or comment commands.

4
  • Should the space of such blocks be preserved ? Which documentclass do you use? Does these blocks contain things like labels which are necessary in the remaining text? Commented Dec 18, 2018 at 15:50
  • No, the space should not be preserved, i.e., when I say that I don't want those lines to appear, I really don't want any trace of that text in the compiled document. Also: these blocks of text which I'm refering to are simple text lines: no labels, no pics, etc.
    – AJHC
    Commented Dec 18, 2018 at 15:55
  • I think that the comment package is perfect for this... osl.ugr.es/CTAN/macros/latex/contrib/comment/comment.pdf
    – Rmano
    Commented Dec 18, 2018 at 16:14
  • Be aware that making the text "invisible" is not the same as making it "not there." If the text in question has private content. some methods for making it "invisible" will still leave the text in the PDF, where it can be extracted. The accepted answer is OK, as is use of comment package.
    – user287367
    Commented Jan 24 at 22:27

5 Answers 5

3

The simplest way would be to do something like this in the preamble:

\newcommand{\additionalInfo}[1]{#1}

and then put all of those lines into that macro like this:

\additionalInfo{I am additional}

If you don't want the lines to show up just replace above macro definition with

\newcommand{\additionalInfo}[1]{}

Not as elegant as the other answers but in my opinion the simplest solution...


\documentclass{article}

% switch comment to disable additional info
\newcommand{\additionalInfo}[1]{#1}
% \newcommand{\additionalInfo}[1]{}

\begin{document}
I am always here

\additionalInfo{I am additional}
\end{document}
8

One possibility is the multiaudience package:

\documentclass{article}

\usepackage{multiaudience}
\SetNewAudience{long}
% remove comment from the following line for the long version
%\DefCurrentAudience{long}

\begin{document}

normal text
\begin{shownto}{long}
   Text for execs
\end{shownto}
normal text 

\end{document}
5

You could use the ifthen package to implement this:

\documentclass{minimal}

\usepackage{ifthen}
\newboolean{somevariable}
\setboolean{somevariable}{false}

\begin{document}

\ifthenelse{\boolean{somevariable}}{Text if somevariable is true.}{Text if somevariable is false.}

\end{document}
5

I usually do this using new ifs:

\documentclass{article}
\newif\ifprintsolution
\printsolutiontrue
\begin{document}
Assignment.

\ifprintsolution
Solution.
\fi
\end{document}

See e.g. https://www.bersling.com/2016/05/22/programming-in-latex/

1

An approach using the version package:

\documentclass{article}

\usepackage{version}
%\excludeversion{foo}
\includeversion{foo}

\begin{document}

all versions

\begin{foo}
only in version foo
\end{foo}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .