# Hiding description part of item in description environment

How can one hide/display all descriptions in a description environment at the same time.

\documentclass[]{article}

\begin{document}

\begin{description}
\end{description}

\end{document}

• it's not clear what your question is really, you just have one begin end pair around each answer, so given latex syntax that's "normal" rather than "painstaking" isn't it? What markup do you want? – David Carlisle Dec 18 '14 at 21:32
• You may have to consider capturing the contents between \item and another \item (with special care taken for the last one). However, how do you handle [A] and [B] in the above case? Do you include both the problem and the answer in the same \item? Perhaps we need to see a more comprehensive example... – Werner Dec 18 '14 at 21:32
• [A] and [B] should always be there, whereas the answers should selectively be there. One option (perhaps?) would be a modified description environment where item labels are always visible, but the items themselves can be selectively (as a group!) hidden or displayed. – Henry Dec 18 '14 at 21:36
• @DavidCarlisle in the same way a description environment simplifies writing a typical list of items and their description, I'm sure an environment exists or can be created to do precisely the same thing where the descriptions can be hidden en masse... – Henry Dec 18 '14 at 21:38
• @Henry: Do you have anything following [A] or [B] that does not belong inside the answer environment? – Werner Dec 18 '14 at 21:43

One option would be to redefine the way description works, capturing all its \item[<stuff>] content and disregarding everything else. This catch-and-release is possible through a local redefinition of \item and placing the entire environment inside a box. That way things are not set to the page, but you can process the environment.

The above brief discussion is implemented below:

\documentclass{article}

\let\olddescription\description% Store \description (\begin{description})
\let\endolddescription\enddescription% Store \enddescription (\end{description})
\newsavebox{\descriptionbox}
\makeatletter
\renewenvironment{description}
{\gdef\descriptionlist{}% Clear description list
\begingroup% Begin local scope
\def\item[####1]{\g@addto@macro\descriptionlist{\item[####1]}}% Redefine \item[.] to capture its argument
% and store it in \descriptionlist
\begin{lrbox}{\descriptionbox}}% Start capturing elements
{\end{lrbox}% End capturing elements
\endgroup% Close local scope
\begin{olddescription}\descriptionlist\end{olddescription}}% Set captured items in regular description
}
\newcommand{\restoredescription}{%
\let\description\olddescription% Restore \description (\begin{description})
\let\enddescription\endolddescription% Restore \enddescription (\end{description})
}
\makeatother

\begin{document}

\begin{description}
\item[Keep this] Definitely keep this
\item[Keep that] Definitely keep that
\end{description}

\begin{description}
\end{description}

\restoredescription

\begin{description}
\item[Keep this] Definitely keep this
\item[Keep that] Definitely keep that
\end{description}

\end{document}


Switches are provided to discard description content (via \discarddescription) and restore its original functionality (via \restoredescription).

If you want to completely hide all description environments you can simply redefine the description environment to ignore anything in its body via the environ package. So with \RenewEnviron{description}{}{}: you obtain:

If you still want the \item labels form the description environments then you can hide the answer environment in the same manner via \RenewEnviron{answer}{}:

Then, when you want the ansers you can use \NewEnviron{answer}{\BODY} to obtain:

## Code: Hide description environment

\documentclass[]{article}
\usepackage{environ}
\usepackage{comment}

\RenewEnviron{description}{}{}

\begin{document}
Some text before.
\begin{description}
\item[A]
\item[B]
\end{description}
Some text after.
\end{document}


## Code: Hide answer environment

\documentclass[]{article}
\usepackage{environ}

\begin{document}
Some text before.
\begin{description}
\item[A]
\item[B]
\end{description}
Some text after.
\end{document}

• Hi Peter, I may have been unclear - I want [A] and [B] labels to remain (so a list of bold A, B, ... should be the result). – Henry Dec 18 '14 at 21:50
• @Henry: As you still want the labels, I have updated solution to hide just the answer environment. – Peter Grill Dec 18 '14 at 21:53
• I'm sorry ok I'm going to update my question to be as clear as possible on this one!! – Henry Dec 18 '14 at 21:54
• please see my updated question. The 'answer' environment was just my attempt (I tried to show my approach, but really I should have started with just my original problem). – Henry Dec 18 '14 at 21:56
• @Henry: The alternate solution (which does not use the comment pacakge) already provides for this (but does requite the \item content to be an environment). – Peter Grill Dec 18 '14 at 22:00

You can switch easily between different definitions of a command, added a % and deleting another one. I do this a lot, to change layout. Think of your tex document as a kind of database, keeping as much formatting information as possible in the header.

\documentclass[]{article}

%\newcommand*{\thing}[2]{\item[#1] #2}
\newcommand*{\thing}[2]{\item[#1]}

\begin{document}

\begin{description}
\thing{A}{A}
\thing{B}{B}
\end{description}

\end{document}


This exploits the fact that in a description one has to specify the optional argument. It's better to give personal environments a name different from the generic one anyway, so I defined an answers environment; each item is introduced by \answer.

\documentclass{article}
\usepackage{environ}

\begin{description}
\BODY
\else
\fi
\end{description}
}

\makeatletter
\item[#1]%
\if\relax\detokenize{#3}\relax
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
}

\begin{document}