As mentioned in the comments the exsheets
package can be used for this. The titles/names of the exercises can be given as a subtitle using the question
environment's subtitle
option. To actually print the subtitles a headings instance must be used that typesets it. The predefined block-subtitle
instance nearly looks the same as your own defined headings so it can be used.
This means we set
\SetupExSheets{
headings = block-subtitle ,
headings-format = \large\bfseries\sffamily ,
% needs v0.16 2014/09/14 to work:
subtitle-format = \large\bfseries\sffamily
}
which mimics the definitions in your question.
Next thing we need is obviously some mainquestion
counter which can be used to print the question numbers as 1.1, 1.2, 2.1, etc. Like you I use the section
counter for the task. Then we need
\SetupExSheets{
counter-within = section ,
counter-format = se.qu\IfQuestionSubtitleT{:} ,
}
\IfQuestionSubtitleT{:}
ensures that the colon only is typeset when a subtitle is given.
For managing the exercises they can be defined in an external file, myexercises.tex
, say. For the example below I saved it with the following contents:
\begin{question}[subtitle=This is the Name of the first Exercise,ID=Q1]
This is the problem given for the first Exercise.
\end{question}
\begin{solution}
This is the first solution.
\end{solution}
\begin{question}[subtitle=This is the Name of the second Exercise,ID=Q2]
This is the problem given for the second Exercise.
\end{question}
\begin{solution}
This is the second solution.
\end{solution}
\begin{question}[subtitle=This is the Name of the third Exercise,ID=Q3]
This is the problem given for the third Exercise.
\end{question}
\begin{solution}
This is the third solution.
\end{solution}
If we put everything together we get:
\documentclass{scrartcl}
\usepackage{exsheets}[2014/09/14] % v0.16 or newer
\SetupExSheets{
headings = block-subtitle ,
headings-format = \large\bfseries\sffamily ,
subtitle-format = \large\bfseries\sffamily ,
counter-within = section ,
counter-format = se.qu\IfQuestionSubtitleT{:} ,
% solution/print = true % uncomment for tutors
}
% needed in earlier versions of exsheets:
% \DeclareInstance{exsheets-heading}{block-subtitle}{default}{
% subtitle-format = \large\bfseries\sffamily ,
% join = {
% title[r,B]number[l,B](.333em,0pt) ;
% title[r,B]subtitle[l,B](1em,0pt)
% } ,
% attach = {
% main[l,vc]title[l,vc](0pt,0pt) ;
% main[r,vc]points[l,vc](\marginparsep,0pt)
% }
% }
\begin{document}
\stepcounter{section}
\includequestions[IDs={Q1,Q2}]{myexercises}
\stepcounter{section}
\includequestions[IDs=Q3]{myexercises}
\end{document}
If you uncomment the line
% solution/print = true
in the above example you'll get
If you instead add \printsolutions
at the end you'll get
Unfortunately there's currently no way to add subtitles to solutions.
I suggest to you to read exercise
package documentation.
There are the package options:
lastexercise
if no references is given for an answer, then the answer
is supposed to refer to the last exercise (see section 2.1).
and
answerdelayed
save the answers instead of typeset them. The answers
can be included later in the document with the command \shipoutAnswer
.
and the Exercise
environment option:
difficulty
The difficulty of the exercise (a number). It will be
available later with the counter \ExerciseDifficulty
.
You can start with this simple example and then make your customization.
As you can see, if you write your Answer
environment immediately after the corresponding Exercise
, the answer is automatically joined to the previous exercise.
\documentclass[11pt]{book}
\usepackage[lastexercise,answerdelayed]{exercise}
\usepackage{lipsum}
\begin{document}
\chapter{Test 1}
\lipsum[1]
\section{Problems}
\begin{Exercise}[difficulty={1}]
My easy exercise.
\end{Exercise}
\begin{Answer}
My answer to my easy exercise.
\end{Answer}
\chapter{Test 2}
\lipsum[1]
\section{Problems}
\begin{Exercise}[difficulty={2}]
My difficult exercise.
\end{Exercise}
\begin{Answer}
My answer to my difficult exercise.
\end{Answer}
\chapter{Solutions}
\shipoutAnswer
\end{document}
Best Answer
The internals of the
exercise
package are not well designed for this and need some patching to print custom counters correctly in all situations (the heading of the Exercise, the entry in the list of exercises and in any cross references). Here is such a collection of patches in a test document.The main problem is that the package defines
\theExercise
to do something other than just produce a printed form for theExercise
counter. In most situations was is needed is a command producing the printed representation of the counter for this environment. The name of that counter is stored in\@ExerciseCounter
and the printed form should be accessed via a macro\the...
where...
is that counter name; one can get this by the constructMost of the patches above implement this, replacing instances of
\theExercise
with the above code. At another point the associated macro\p@Exercise
is used and this has been patched too to adjust to the chosen counter.Lastly the starred form
Exercise*
of the environment did not behave as advertised, it produced an entry in the list of exercises, I have fixed this too via the last two patches applied to\@@@ExeEnv
.Note that I have adjusted your definition of
\thepbone
to only produces the relevant characters. The bold face formatting should only be applied when it is used in a bold context, not at every reference.