This is a very, very small version of a quick - and dirty question/solution
approach. The tcolorbox
stuff is rather eye-candy then really needed. (Apart from advancing counters)
Each \Question
has a mandatory argument (for the question) and a 3rd. optional argument for the solution content. The 1st. opt. argument is for options (not used here, due lack of time).
The solution is written to an external file named \jobname.sol
, the question file is (again) not used here.
(Admittedly, I grabbed from a non-working package of mine, which is not ready to be published :-()
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{morewrites}
\usepackage{xparse}
\newcounter{QuestionBox}[section]
\newcounter{AnswerBox}[section]
\newtcolorbox[use counter=QuestionBox,number within=section]{QuestionBox}{title={Question~\theQuestionBox},colbacktitle={green},coltitle=black}
\newtcolorbox[use counter=AnswerBox,number within=section]{AnswerBox}{title={Answer~\theAnswerBox},colbacktitle={yellow},coltitle=black}
\newwrite\questionfile
\newwrite\solutionfile
\NewDocumentCommand{\Answer}{+O{}+m}{%
\begin{AnswerBox}
#2
\end{AnswerBox}
}
\NewDocumentCommand{\Question}{+O{}+m+O{}}{%
\immediate\write\solutionfile{%
\string\setcounter{section}{\number\value{section}}
\string\setcounter{AnswerBox}{\number\value{QuestionBox}}
}
\begin{QuestionBox}
#2
\end{QuestionBox}
\IfValueTF{#3}{%
\immediate\write\solutionfile{%
\string\Answer{\unexpanded{#3}}
}
}{}
}
\AtBeginDocument{%
\immediate\openout\questionfile=\jobname.quest
\immediate\openout\solutionfile=\jobname.sol
}
\NewDocumentCommand{\CollectSolutions}{+O{}}{%
\clearpage
\immediate\closeout\questionfile%
\immediate\closeout\solutionfile%
\setcounter{QuestionBox}{0}
\setcounter{AnswerBox}{0}
\section*{Solutions}
\InputIfFileExists{\jobname.sol}{}{}
}
\AtEndDocument{%
\immediate\closeout\questionfile%
}%
\begin{document}
\section{Relativity}
\Question{What's the meaning of \(E=mc^2\)}[It's the total relativistic energy (of a particle)]
\Question{Proof that \textcolor{red}{\[\gamma = \dfrac{1}{\sqrt{1-\dfrac{v^2}{c^2}}}\]}}[\textbf{It's completely straightforward}]
\section{Other stuff}
\Question{Find the anti-derivative of \[e^{-x^2}\]}[Ooops...]
\CollectSolutions
\end{document}

answers
orexsheets
,probsoln
could be of helpexsheets
seems pretty well-suited to this task. I think I'll give it a try.