Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

making contents of an environment disappear

5 views
Skip to first unread message

Tamas K Papp

unread,
Nov 26, 2009, 2:03:41 AM11/26/09
to
Hi,

I am writing exam questions in LaTeX, with the solutions in the same
file, meant to appear in a different color (using the color package).
I defined this environment:

\newenvironment{solution}{\par\noindent\color{blue}\textbf{Solution.}\ }
{\normalcolor}

Eg

\begin{solution}
This is the answer to the question.
\end{solution}

Now I would like to generate a version of the exam without the
solutions. Is there a way to redefine the environment above so that
the contents just disappear? I know how to do this with commands, eg

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

vs

\newcommand{\gobble}[1]{}

but not with environments.

Thanks,

Tamas

Ulrike Fischer

unread,
Nov 26, 2009, 3:47:47 AM11/26/09
to
Am 26 Nov 2009 07:03:41 GMT schrieb Tamas K Papp:


> Now I would like to generate a version of the exam without the
> solutions. Is there a way to redefine the environment above so that
> the contents just disappear?

E.g. comment.sty
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=conditional


--
Ulrike Fischer

Kumaresh PS

unread,
Nov 26, 2009, 6:12:36 AM11/26/09
to
On Nov 26, 12:03 pm, Tamas K Papp <tkp...@gmail.com> wrote:
>
> Is there a way to redefine the environment above so that the contents just disappear?
>
> Tamas

Hi,

Based on the below method you can achieve your task:

\newif\ifsolution\global\solutiontrue%
\DeclareOption{ANS}{\global\solutionfalse}% THESE TWO LINES SHOULD BE
BEFORE \ProcessOptions

\newbox\tempbox%
\newenvironment{solution}{%
\setbox\tempbox\vbox\bgroup\par\noindent\color{blue}\textbf
{Solution.}\ %
}{%
\normalcolor\egroup%
\ifsolution%
\phantom{\copy\tempbox}%
\else%
\copy\tempbox%
\fi%
}%


Usage:
\documentclass[ANS]{cls}%
% Whenever using "ANS" in the class option, you can get solution in
your output, if this is not available in the document class option
then Solution will occur in your display.

Best of Luck!!!

Kumaresh PS

0 new messages