My question is quite similar to this one, but I think a slightly different approach is needed.
I have a document with a lot of exercices and I'd like to add aswers and hints to them in a certain section.
I don't want to do this manually, since, if I add an exercice, I'll have to make that the answers and hints keep the right order. Also, it's possible that not all exercices have an answer and a hint with them, so the numbering of answers and hints should be completely dependent of the numbering of exercices.
I.e, things like
1. Some hint for exercice 1
2. Some hint for exercice 2
4. Some hint for exercice 4
99. Some hint for exercice 99
should be possible.
For example:
\documentclass[12pt,a4paper]{article}
\usepackage[dutch]{babel}
\usepackage{amsthm}
\newtheorem{ex}{Exercice}
\newtheorem{ans}{} % Abbreviation for answer. No text needed because I just want numbers with the answers next to them.
\newtheorem{hi}{} % Same here.
\begin{document}
\section{Algebra}
\begin{ex}What is $1+3$?\end{ex}
\begin{hi}First consider $1+0$, $1+1$, $1+2$ and try to find a pattern.\end{hi}
\begin{ans}It's $4$!\end{ans}
\section{Grammar}
\setcounter{ex}{0} % So the counter is set to zero when a new section begins.
\begin{ex}The first letter of the alphabet?\end{ex}
%No hint given here
\begin{ans}A\end{ans}
\section*{Answers}
\subsection{Section Algebra}
%Answer should be here, but of course it isn't.
\subsection{Section Grammar}
%Same.
\section*{Hints}
\subsection{Section Algebra}
%Hint here.
\subsection{Section Grammar}
% No hint because I didn't ask Latex to do so.
\end{document}
So in fact I need some \magicCommandThatPutsAnswersAndHintsSomewhereElse
. If there's more then one answer in a section, I'd like them to be numbered like theorems.
As you may have noticed in the example, I want the answers and hints in a subsection that refers to their section.