Typesetting exercise sheets

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:

enter image description here

\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

enter image description here

If you instead add \printsolutions at the end you'll get

enter image description here

Unfortunately there's currently no way to add subtitles to solutions.


This is a reduced/simplified version of my package, which is still not ready for publication (update: It's progressing, but still not available!).

This code defines a command

\Exercise[2][]

where the mandatory argument holds the exercise text and the optional argument with value solution={....}, which is optional.

The solution should be specified in {} for grouping.

The solution content is then written to a file.

(Very simple) Example:

\Exercise[solution={2}]{What is 1 + 1}

All exercises can be in an external file or directly in the preamble, or in the document body.

They are not printed, however, as long as there is no list declared, which allows for selecting particular exercises.

\DeclareExerciseList{1,3,4,5} will choose the exercises 1,3,4 and 5, omitting number two and any other. Non existing exercise numbers will be ignored!

Driver *.tex/package code

\documentclass{scrartcl}

\usepackage{tcolorbox}%
\usepackage{xkeyval}%
\usepackage{blindtext}%
\usepackage{etoolbox}%
\usepackage{assoccnt}%



\newcounter{realexercisecounter}%
\newcounter{exercise}%
\newcounter{solution}%


\DeclareAssociatedCounters{exercise}{realexercisecounter}%

% Some definitions
\newcommand{\SolutionName}{Solution}
\newcommand{\SolutionPageName}{Solutions}
\newcommand{\ExerciseName}{Exercise}%


\AtBeginDocument{%
  \immediate\openout\exerfile=\jobname.solutions
  \immediate\write\exerfile{%
    \string\setcounter{solution}{0}%
  }%
  \immediate\write\exerfile{%
    \string\clearpage
    \string\section*{\SolutionPageName}%
  }%
}%


\newwrite\exerfile%

\makeatletter

\define@key{exerkeys}{exercise}{%
  \def\exerkeys@@exercise{#1}%
}%

\define@key{exerkeys}{solution}{%
  \def\exerkeys@@solution{#1}%
}%

\newcommand{\writesolutiontofile}[1]{%
  \immediate\write\exerfile{%
    \string\begin{Solution}^^J%
      \unexpanded\expandafter{#1}^^J%
      \string\end{Solution}^^J%
  }%
}%


\newcommand{\Exercise}[2][]{%
  \setlength{\parindent}{0pt}%
  \refstepcounter{exercise}%
  \xifinlist{\number\value{realexercisecounter}}{\exerciselist}{%
  \setkeys{exerkeys}{#1}%
  \begin{tcolorbox}[width=\textwidth,colbacktitle=red,coltitle=black,title={\ExerciseName~\theexercise}]
    #2%  
    \ifdef{\exerkeys@@solution}{%
      \xifinlist{\number\value{realexercisecounter}}{\exerciselist}{%
        \immediate\write\exerfile{%
          \string\setcounter{solution}{\number\value{exercise}}^^J%
          \string\addtocounter{solution}{-1}%
        }%
      }{}%
      \writesolutiontofile{\exerkeys@@solution}%
    }{}%
    \end{tcolorbox}%
  }{}%
  \undef\exerkeys@@solution% Must be outside/at the end!
}%



\newenvironment{Solution}{%
  \setlength{\parindent}{0pt}%
  \refstepcounter{solution}
  \begin{tcolorbox}[width=\textwidth,colbacktitle=green,coltitle=black,
    title={\SolutionName~\thesolution}]
}{\end{tcolorbox}}%

\makeatother%





\AtEndDocument{%
  \immediate\closeout\exerfile%
  \cleardoublepage%
  \InputIfFileExists{\jobname.solutions}{}{}%
}%


\newcommand{\DeclareExerciseList}[1]{%
\undef{\exerciselist}{}%
\listgadd{\exerciselist}{}%
\forcsvlist{\listgadd{\exerciselist}}{#1}%
}%

\begin{document}

\DeclareExerciseList{1,3,4,5}%

\InputIfFileExists{exercises}{}{Ooopps!}



\end{document}

exercises.tex

\Exercise[solution={Yes, it's a question}]{First Question}


\Exercise[solution={They are thin at one end, thick in the middle and thin on the end again}]{%

Question: What is special about Brontosaurs?
}%


\Exercise[solution={to be done}]{%


Proof 
\begin{equation}
  a^2 + b^2 = c^2
\end{equation}
}%


\Exercise[solution={\textcolor{blue}{\blindtext}}]{%
Cite a Latin Text
}%


\Exercise[]{%
\textcolor{red}{\textbf{Cite a Latin text again}} % Won't be shown as solution
}%

enter image description here

enter image description here


To solve your problem, I would provide every single exercise sheet in a single document (tex-file) like this:

-- sheet1.tex:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

% generate blindtext
\usepackage{blindtext}

% add dot after section number
\makeatletter
\g@addto@macro\thesection.
\makeatother

% define command for exercise and solution
\newcommand{\problem}[1]{\section{Exercise}\subsection*{Problem}{#1}}
\newcommand{\solution}[1]{\subsection*{Solution for Problem \arabic{section}}{#1}}


\begin{document}
\title{Sheet 1}
\maketitle


% testing without own commands
\section{Exercise}

\subsection*{Problem}
\blindtext

\subsection*{Solution for Problem \arabic{section}}
\blindtext


% using own commands defined above
\problem{insert your exercise, task, problem here}

\solution{insert your solution here}


\end{document}

Save the second sheet in a file like the first one (in this example here it is just a renamed copy of "sheet1.tex):

-- sheet2.tex:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

% generate blindtext
\usepackage{blindtext}

% add dot after section number
\makeatletter
\g@addto@macro\thesection.
\makeatother

% define command for exercise and solution
\newcommand{\problem}[1]{\section{Exercise}\subsection*{Problem}{#1}}
\newcommand{\solution}[1]{\subsection*{Solution for Problem \arabic{section}}{#1}}


\begin{document}
\title{Sheet 2}
\maketitle


% testing without own commands
\section{Exercise}

\subsection*{Problem}
\blindtext

\subsection*{Solution for Problem \arabic{section}}
\blindtext


% using own commands defined above
\problem{insert your exercise, task, problem here}

\solution{insert your solution here}


\end{document}

To produce an "overall document" with all exercise sheets ever handed out, you can use the standalone package to ignore the preamble of external files when using input or include to import that external file. So for the "overall document" you need to compile "allsheets.tex" only:

-- allsheets.tex:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

% input external file but ignore the preamble
\usepackage{standalone}

% generate blindtext
\usepackage{blindtext}

% add dot after section number
\makeatletter
\g@addto@macro\thesection.
\makeatother

% define command for exercise and solution
\newcommand{\problem}[1]{\section{Exercise}\subsection*{Problem}{#1}}
\newcommand{\solution}[1]{\subsection*{Solution for Problem \arabic{section}}{#1}}



\begin{document}
\title{All Sheets}
\maketitle

\input{sheet1.tex}
\input{sheet2.tex}


\end{document}

This approach will provide single exercise sheets during the semester/course and a "overall document" at the end of the semester/course.