7

I have a set of problems and solutions, and I wish to include (some of) them in several different documents. I would like to be able to choose if the solutions should be presented last, or immediate after the problem formulation.

A possibility is to put each problem and solution in a separate file, and then have some command

\includepart{filename.tex}{problem}

and

\includepart{filename.tex}{solution}

where \includepart{file}{env} includes say everything between \begin{env}and \end{env}.

Is there a simple way to do this? Are there better solutions to this? This seems to be a common problem, but I have not found something that does exactly this.

13
  • Have, a look to the comment package and the definition of versions and the command \includecomment{} and \excludecomment{}. ctan.mirrorcatalogs.com/macros/latex/contrib/comment/…
    – Ludovic C.
    Aug 23, 2013 at 9:08
  • 3
    The exsheets package allows to include problems and their solutions from external files selectively.
    – cgnieder
    Aug 23, 2013 at 9:45
  • The exsheets looks nice, however, is there an easy way to install it on a linux system? It seems to rely on some experimental packages. Is exsheets considered stable? Aug 23, 2013 at 10:23
  • I tried installing exsheets (not particularly easy), Aug 23, 2013 at 11:26
  • 2
    If you use the answers package you can have all the problems and solutions in one file, then choose (in the preamble, with a switch or by commenting code) whether the answers appear with the problems, at the end of the document, or in a separate document. Aug 23, 2013 at 12:14

1 Answer 1

6

The exsheets provides means to selectively include problems and their respective solutions from external files.

Let's say we have an external file exercises.tex with the following contents:

% question `test1'
\begin{question}[ID=test1]
  First sample question
\end{question}
\begin{solution}
  First sample solution
\end{solution}

% question `test2'
\begin{question}[ID=test2]
  Second sample question
\end{question}
\begin{solution}
  Second sample solution
\end{solution}

% question `test3'
\begin{question}[ID=test3]
  Third sample question
\end{question}
\begin{solution}
  Third sample solution
\end{solution}

Then the main file

\documentclass{article}
\usepackage{exsheets}
\begin{document}
\includequestions[IDs={test1,test3}]{exercises.tex}
\end{document}

gives

enter image description here

The default behaviour is not to print the solutions. This can be changed by setting an option. The following file

\documentclass{article}
\usepackage{exsheets}
\SetupExSheets{solution/print=true}
\begin{document}
\includequestions[exclude={test2}]{exercises.tex}
\end{document}

gives

enter image description here

This also demonstrates that you can selectively exclude questions from being printed.

If you want to separate exercises and solutions that's also possible by calling \printsolutions where you want them:

\documentclass{article}
\usepackage{exsheets}
\begin{document}
\section*{Exercises}
\includequestions[IDs={test2,test3}]{exercises.tex}
\section*{Solutions}
\printsolutions
\end{document}

gives

enter image description here

10
  • 1
    @vesszabo There are two possibilities both described in the manual: a) there are options to set the names manually b) there is a way to add translations that will be used if the babel language is chosen. If you read the part about internationalization in the manual you might consider sending an email to the author (me) to add the translations to the package.
    – cgnieder
    Nov 2, 2014 at 0:09
  • 1
    That's quite easy. You just need to choose the appropriate headings instance. Look for the section about styling the exercises in the manual.
    – cgnieder
    Nov 12, 2014 at 14:31
  • 1
    @vesszabo of course you can reset the counter. It's a normal LaTeX counter named question. (This means \setcounter, \stepcounter and all the other commands can be used as with every other counter.)
    – cgnieder
    Nov 20, 2014 at 11:08
  • 1
    @vesszabo yes you can define your own headings instance. Indeed users are encouraged to do so. The long list of existing instances serves two purposes: a) show the existing instances b) serve as examples for defining own instances.
    – cgnieder
    Nov 20, 2014 at 11:09
  • 1
    @vesszabo You can use \RenewQuSolPair to set individual heading styles for questions and solutions: \RenewQuSolPair{question}[headings=foo]{solution}[headings=bar]. See section 18 of the manual.
    – cgnieder
    Jan 2, 2015 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .