[Tex/LaTex] How to include exam class features in book class

document-classesexam

I am currently writing up notes using the book class with three parts, one for lecturers notes, one for mine, and one for practice questions. I love the exam class for formatting questions, but I want the book class for all the formatting. Is there some way to integrate the question environment into this book class without just copying the needed parts from exam.cls or book.cls into my document/into a new package?

\documentclass{book} % I want it formatted like a book
%\documentclass[answers]{exam} % But have questions formatted like exam

\begin{document}
\title{My Revision Book}
\maketitle

\part{Notes}

% 'normal' LaTeX

\part{Practice questions/past exam papers}
\begin{questions}
\question
How long is a piece of string

\begin{solution}
This long $\leftarrow\rightarrow$ (not to scale).
\end{solution}
\end{questions}

\end{document}

Best Answer

If you want the question and solution environments to behave exactly like they do in the exam document class then you'll need to copy the relevant code from exam.cls.

However, if you just want something that looks similar, then you could define your own environment, perhaps something like the following, which uses the enumitem to do the hard work:

\newlist{questions}{enumerate}{3}
\setlist[questions]{label=\arabic*.}
\newcommand{\question}{\item}

Similarly, you can define your own solution environment:

\newenvironment{solution}{ {\bfseries Solution}:}{}

Of course, you could get more adventurous by using a theorem package, e.g amsthm if you wanted more formatting.

Finally, another idea is to simply include the pdf version of your previous exams using the pdfpages, in which case you don't need to worry about these environments at all!

Here's a complete MWE to build from:

\documentclass{book} % I want it formatted like a book
%\documentclass[answers]{exam} % But have questions formatted like exam
\usepackage{enumitem}

\newlist{questions}{enumerate}{3}
\setlist[questions]{label=\arabic*.}
\newcommand{\question}{\item}

\newenvironment{solution}{ {\bfseries Solution}:}{}

\begin{document}
\title{My Revision Book}
\maketitle

\part{Notes}

% 'normal' LaTeX

\part{Practice questions/past exam papers}
\begin{questions}
\question
How long is a piece of string

\begin{solution}
This long $\leftarrow\rightarrow$ (not to scale).
\end{solution}
\end{questions}

\end{document}
Related Question