# Latex optional text and footnotes

Sometimes I am writing for two audiences. I have a complete document with extra footnotes and perhaps extra background paragraphs for an ordinary reader. And another version that omits this background detail which is considered assumed knowledge in the other audience.

Is there a latexy way to handle this kind of thing that is not overly cumbersome?

UPDATE: Sorry if this was a little unclear. I am not interested in working out how to manually 'comment out' sections of text. I want to be able to setup a 'flag' of some sort which outputs a condensed version of the document with fewer footnotes, and an expanded version of the document with additional footnotes.

• Technically you have two documents, and in one you want to remove (or comment) large sections of text. For this see Commenting out large sections. – Werner May 27 '17 at 2:11
• Do you intend having a sort of switch between the commented version and the ordinary one? – CarLaTeX May 27 '17 at 2:40
• I suggest write the background sutff y in another files, so you can focus in the main content. For the long version include them, but not using \input but some alternative command as \xxx (Add \let\xxx\input in preamble, then \xxx{filename1} ..\xxx{filename2} ... in the document body. For the short version, simply add a line to the preamble with \renewcommand\xxx[1]{}  and comment it with % to return to the long version. – Fran May 27 '17 at 4:20
• There's a package that addresses your need: multiaudience. – TeXnician May 28 '17 at 7:45

Here using multiaudience. There is one audience for those who need background and those who don't. Two outputs (only change in current audience):

You can use that package to define even new environments and commands only visible to some audiences (predefined f.i. \Footnote and Section). And of course you can define as many audiences as you need.

\documentclass{article}

\usepackage{multiaudience}

\SetNewAudience{ducks}
\SetNewAudience{thosewhoknow}
\DefCurrentAudience{thosewhoknow}

\begin{document}
Text for all\Footnote{ducks}{Details for those who don't know}\par
\begin{shownto}{ducks}
Text for those who need background.
\end{shownto}
\begin{Section}{ducks}{DETAILS}
Here a real section with details
\end{Section}
\end{document}


As you want to "turn off" a background environment and (all?) footnotes, this is not quite the same as Commenting out large sections, although in the end it is very similar.

The easiest way to do this is to define a new "switch statement" using

\newif\ifComplete


You can then use \ifComplete to decide whether to print or hide text. Using \ifComplete and the environ package you can define a background environment that will ignore its contents after \Completefalse. To define \footnote you can "save" a copy of the "real" \footnote command with

\let\realfootnote=\footnote


and then redefine \footnote so that it will ignore its contents after \Completefalse. As \footnote takes an optional argument we might as well support this to.

Putting this all together, I think that the following code does what you want:

\documentclass{article}
\usepackage[textheight=20mm]{geometry}% for display purposes only
\newif\ifComplete% if true print the whole document
\usepackage{environ}
\NewEnviron{background}{\ifComplete\BODY\fi}% print only when \Completetrue
\let\realfootnote=\footnote% save a copy of the original \footnote
\renewcommand\footnote[2][\relax]{% hijack footnote
\ifComplete% print foot notes only in complete document
\ifx#1\relax\relax\realfootnote{#2}\else\realfootnote[#1]{#2}\fi%
\fi%
}
\begin{document}

\Completetrue
\begin{background}
This is some background material
\end{background}

This is some normal text with a footnote\footnote{What a lovely footnote!}

\end{document}


In the WME, \Completetrue means that everything will be printed, so this produces:

If we change \Completetrue to \Completefalse then the output is: