1. To centre the Part names on their title page.
2. I wanted to have each problem and each solution start on a new page but hints could be continuous.
The base code is given below:
Code: Select all
\documentclass{article}
\usepackage[english]{babel}
\usepackage{mathtools}
\usepackage{environ}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}
\newcounter{problem}
\newenvironment{problem}[1]
{\refstepcounter{problem}%
{\textbf{Problem \theproblem\ (#1)}\par}\nopagebreak\noindent\ignorespaces}
{}
\makeatletter
\newtoks\late@hintstoks
\newtoks\late@solutiontoks
\NewEnviron{hints}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@hintstoks % the previous contents
\noexpand\late@hint{\theproblem}{\the\toks@}%
}%
\global\late@hintstoks=\expandafter{\@tempa}%
}
\NewEnviron{solution}{%
\toks@=\expandafter{\BODY}%
\protected@edef\@tempa{%
\the\late@solutiontoks % the previous contents
\noexpand\late@solution{\theproblem}{\the\toks@}%
}%
\global\late@solutiontoks=\expandafter{\@tempa}%
}
\newcommand{\late@hint}[2]{%
\paragraph*{Hints for problem #1}#2%
}
\newcommand{\late@solution}[2]{%
\subsubsection*{Solution for problem #1}#2%
}
\newcommand{\printhints}{%
\part{Hints}
\the\late@hintstoks
}
\newcommand{\printsolutions}{%
\part{Solutions}
\the\late@solutiontoks
}
\makeatother
\begin{document}
\part{Problems}
\section{Puzzle 1}
\begin{problem}{Pythagoras}
This problem is about Pythagoras' theorem
\begin{hints}
These are the hints about Pythagoras.
\end{hints}
\begin{solution}
Pythagoras' theorem is easy!
\end{solution}
\end{problem}
\section{Puzzle 2}
\begin{problem}{Riemann}
Prove the zeros of the $\zeta$ functions are on the critical line.
\begin{hints}
Try first with a few cases.
\end{hints}
\begin{solution}
Oh, well!
\end{solution}
\end{problem}
\printhints
\printsolutions
\end{document}