major edit -> new answer:
The Goal
Writing a textbook using the exsheets package and be able to copy & paste the exercises and solutions as they are in a document using the exam class for creating exams.
Requirements
- The
exsheets package has no parts environment. It needs to be defined so it can be used with the same syntax as required by exam.
- a
solution environment should be available to be used once or more for a question. For this exsheets' own solution environment needs to be redefined. This also requires a suitable replacement for the environment so exsheets can still save solutions to print them later in the textbook.
- adapt
exsheets' question environment in the exam document.
The Definitions
The parts Environment:
Since in the textbook no points need to be assigned to questions a simple wrapper for enumerate will do. We will use enumitem because it's comfortable.
\usepackage{enumitem}
\newenvironment{parts}{%
\renewcommand*\part[1][]{\item}%
\begin{enumerate}[label=(\alph*)]
}{\end{enumerate}}
Redefinition of the solution Environment:
The first thing we do is create a new question/solution pair for exsheets. This will provide a replacement for the original solution. This requires exsheets version 0.3 which should be on CTAN in a week or so. The beta version can be downloaded here.
\NewQuSolPair{Question}{Solution}
The following is a little bit longer. The goal will be to define solution in a way that will store the solution for exsheets. The manual way would be to write the solution a second time in the newly defined Solution environment:
\begin{Question}
Main question goes here
\begin{parts}
\part $1+1=$
\begin{solution}
$2$
\end{solution}
\end{parts}
\end{Question}
% the following should be unnecessary:
\begin{Solution}
\begin{parts}
\part $1+1=$
\end{parts}
\end{Solution}
Since I don't have a perfect solution for the automization I'll present the basic solution that requires the double input first.
\usepackage{environ}
\makeatletter
% no idea why these are necessary:
\def\env@solution@save@env{}
\def\env@solution@process{}
% the actual redefinition into a dummy environment
% that gobbles its body:
\RenewEnviron{solution}{}
\makeatother
The Documents
Now the textbook can look like this:
% this is textbook.tex
\documentclass[12pt,a4paper]{book}
\usepackage{exsheets}
\usepackage[inline]{enumitem}
\newenvironment{parts}{%
\renewcommand*\part[1][]{\item}%
\begin{enumerate}[label=(\alph*)]
}{%
\end{enumerate}%
}
\NewQuSolPair{Question}{Solution}
\usepackage{environ}
\makeatletter
\def\env@solution@save@env{}
\def\env@solution@process{}
\RenewEnviron{solution}{}
\makeatother
\begin{document}
\chapter{foo}
\section{questions}\exlabel{sec:questions:foo}
\begin{Question}
Main question goes here
\begin{parts}
\part $1+1=$
\begin{solution}
$2$
\end{solution}
\part $8-3=$
\begin{solution}
$5$
\end{solution}
\end{parts}
\end{Question}
\begin{Solution}
\begin{enumerate*}[label=(\alph*)]
\item $2$
\item $5$
\end{enumerate*}
\end{Solution}
\begin{Question}
Another question.
\begin{solution}
Another answer.
\end{solution}
\end{Question}
\begin{Solution}
Another answer
\end{Solution}
\section{solutions}
\printsolutions[section=\S{sec:questions:foo}]
\end{document}

The corresponding exam:
% this is exam.tex
\documentclass[answers]{exam}
\newenvironment{Question}{\question}{}
\begin{document}
\begin{questions}
\begin{Question}
Main question goes here
\begin{parts}
\part $1+1=$
\begin{solution}
$2$
\end{solution}
\part $8-3=$
\begin{solution}
$5$
\end{solution}
\end{parts}
\end{Question}
\begin{Question}
Another question.
\begin{solution}
Another answer.
\end{solution}
\end{Question}
\end{questions}
\end{document}

Preliminary Attempt to avoid Double Input of Solutions
The following definition of the solution environment tries to automate things but has some obvious shortcomings. Flexibility in creating the solutions is mainly lost.
Every call of solution within a question will save its body and at the end of the Question environment a Solution environment will automatically called if the solution env has been used. In order to do this comfortably the etoolbox package is used:
\usepackage{etoolbox,environ}
\makeatletter
\def\addto@solution{}
\def\env@solution@save@env{}
\def\env@solution@process{}
\RenewEnviron{solution}{%
\ifdefvoid{\BODY}{}
{%
\xdef\addto@solution
{%
\expandonce\addto@solution
\ifnum\value{enumi}>0\theenumi\space\fi
\expandonce\BODY\space
}%
}}
\AtBeginEnvironment{Question}{\gdef\addto@solution{}}
\AtEndEnvironment{Question}{%
\ifdefvoid\addto@solution{}
{\begin{Solution}\addto@solution\end{Solution}}%
}
With this the textbook.tex now looks as follows:
% this is textbook.tex
\documentclass[12pt,a4paper]{book}
\usepackage{exsheets}
\usepackage{enumitem}
\newenvironment{parts}{%
\renewcommand*\part[1][]{\item}%
\begin{enumerate}[label=(\alph*)]
}{%
\end{enumerate}%
}
\NewQuSolPair{Question}{Solution}
\usepackage{etoolbox,environ}
\makeatletter
\def\addto@solution{}
\def\env@solution@save@env{}
\def\env@solution@process{}
\RenewEnviron{solution}{%
\ifdefvoid{\BODY}{}
{%
\xdef\addto@solution
{%
\expandonce\addto@solution
\ifnum\value{enumi}>0\theenumi\space\fi
\expandonce\BODY\space
}%
}}
\AtBeginEnvironment{Question}{\gdef\addto@solution{}}
\AtEndEnvironment{Question}{%
\ifdefvoid\addto@solution{}
{\begin{Solution}\addto@solution\end{Solution}}%
}
\makeatother
\begin{document}
\chapter{foo}
\section{questions}\exlabel{sec:questions:foo}
\begin{Question}
Main question goes here
\begin{parts}
\part $1+1=$
\begin{solution}
$2$
\end{solution}
\part $8-3=$
\begin{solution}
$5$
\end{solution}
\end{parts}
\end{Question}
\begin{Question}
Another question.
\begin{solution}
And another answer.
\end{solution}
\end{Question}
\section{solutions}
\printsolutions[section=\S{sec:questions:foo}]
\end{document}
The result looks the same as above.
original answer:
You are saying in the comments that exsheets would do the trick for you if it had a parts environment. If this really is the only thing you're missing: it could easily be defined.
I'm assuming that in the textbook you do not want to assign points to the exercises so the only thing needed is a simple wrapper for an enumerate environment. I'm using enumitem to format the labels. The redefinition of \part should be kept local since you might want to divide the textbook into parts.
\documentclass{scrartcl}
\usepackage{exsheets}
\SetupExSheets{headings-format=\normalsize\bfseries\sffamily}
\usepackage{enumitem}
\newenvironment{parts}{%
\renewcommand*\part[1][]{\item}%
\begin{enumerate}[label=(\alph*)]
}{%
\end{enumerate}%
}
\begin{document}
\part{A demonstration}
\begin{question}
Why is there air?
\end{question}
\begin{question}
What if there were no air?
\begin{parts}
\part Describe the effect on the balloon industry.
\part Describe the effect on the aircraft industry.
\end{parts}
\end{question}
\end{document}

The corresponding exam document:
\documentclass{exam}
\begin{document}
\begin{questions}
% the following part is the same as in the other document:
\begin{question}
Why is there air?
\end{question}
\begin{question}
What if there were no air?
\begin{parts}
\part Describe the effect on the balloon industry.
\part Describe the effect on the aircraft industry.
\end{parts}
\end{question}
\end{questions}
\end{document}

examdocclass from\questionto\begin{question}\end{question}by using\newevironment, so that works out. But unfortunately,exsheetsdoesn't provide\begin{parts}... – long tom Oct 21 '12 at 12:53exsheetsthe way you want. The wayexsheetsis designed one can only add a solution to a whole question. – cgnieder Oct 22 '12 at 11:10exsheetsboth for the textbook and the exams. – cgnieder Oct 23 '12 at 14:10