# Environment for writing solutions in amsbook

Basically, what I want is exactly asked in Showing Solutions of the Questions "separately", except that I'm using amsbook. So, I want to write a series of questions, by writing something like

\begin{question}

\question 1+1=?

1+1=2

\question What is 1+2=?

1+2=3

\end{question}


The code above should display the questions only:

Question 1: 1+1=?

Question 2: 1+2=?

Then the command

\showanswers


I also want the enumeration style "Question 1, Question 2, ..." to be customizable.

-
I think this might help. tex.stackexchange.com/questions/60771/… –  R. Schumacher Jul 9 '12 at 14:31
I don't seem to find the answer to my question. –  greg Jul 9 '12 at 14:36
Another option, use the exercise.sty style file. It will give you both an exercise and and answer environment. You have the options of either one, both, or none. I use this to put questions into beamer presentations with or without answers. –  R. Schumacher Jul 9 '12 at 14:40

Here's a solution using the answers package.

You can toggle the answers appearing or not by using

\usepackage{answers}


to write the answers to a file (answers.tex in the code below) or

\usepackage[nosolutionfiles]{answers}


to show the answers in the document.

I've used the enumitem package to create a list-type environment called questions, and defined the \question command as \item (although it doesn't take an optional argument- not sure if this matters or not here though).

\documentclass{amsbook}

\usepackage{enumitem}   % for custom lists

\newlist{questions}{enumerate}{5}
\setlist[questions]{label*=Question \arabic*.}
\newcommand{\question}{\item}

\begin{document}

\begin{questions}
\question $1+1=?$
$1+1=2$

\question What is $1+2=?$
$1+2=3$
\end{questions}


You can do a lot with the answers package, particularly if you combine it with the hyperref, as shown in a few answers on this site, for example in Adding another answer hyperlinked to the question itself