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
> 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
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