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


\question 1+1=?


\question What is 1+2=?



The code above should display the questions only:

Question 1: 1+1=?

Question 2: 1+2=?

Then the command


displays the answers:

Answer 1: 1+1=2

Answer 2: 1+2=3

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

  • I think this might help. tex.stackexchange.com/questions/60771/… Commented Jul 9, 2012 at 14:31
  • I don't seem to find the answer to my question.
    – greg
    Commented Jul 9, 2012 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. Commented Jul 9, 2012 at 14:40

1 Answer 1


Here's a solution using the answers package.

You can toggle the answers appearing or not by using


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


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


\usepackage{enumitem}   % for custom lists
\usepackage{answers}    % for separating solutions

\setlist[questions]{label*=Question \arabic*.}

% open the answer file


\question $1+1=?$

\question What is $1+2=?$

% close the answer file

% use this line if you'd like to include the answers separately
\IfFileExists{answers.tex}{\input{answers.tex}}{no file!}

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .