0

I have a problem environment where the counter is coupled to the subsection counter. However this doesn't work with automatic solutions. I tried to couple the solutions counter to the subsections as well but this doesn't produce the correct numbers for the solutions. How can I fix this. Here is a minimal example:

\documentclass[a4paper,12pt]{article}

\usepackage{etoolbox}
\usepackage{environ}


\newtheorem{pr}{Problem}[subsection]
\newtheorem{solinn}{ad Problem}[subsection]

\newtoks\prsoltoks

\NewEnviron{Solution}{%
  \global\prsoltoks=\expandafter{\the\prsoltoks\begin{solinn}}%
    \global\prsoltoks=\expandafter{\the\expandafter\prsoltoks\BODY\end{solinn}}%
}


\usepackage{multicol}
\AtEndDocument{\clearpage
  \section{Solutions}
  \setcounter{pr}{0}
  \begin{multicols}{2}
    \the\prsoltoks
  \end{multicols}
}

\begin{document}


\section{Section}

\subsection{Subsection}
\begin{pr}~

 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}

\subsection{Subsection}

\begin{pr}~

 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}

\begin{pr}~

 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}

\section{Section}

\subsection{Subsection}
\begin{pr}~

 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}


\end{document}

Output:

Output

Instead of adding the functionality to my code above, it would be ok, to use another package which does this if it can be made to get exactly the same output format and the same syntax (pr and Solution).

I played with exsheets but didn't get the correct numbering. answers provides another syntax: solutions inside of the problems environment (I don't want to change my large existing document; just the header).

If the new package works well together with tikz externalize it would be even better (but that is not a requirement for this question).

5
  • There's no subsection in your solution section -- and the information about the previous subsections isn't available in your Solution environment
    – user31729
    Mar 19, 2016 at 15:40
  • @ChristianHupfer The point is that the solution should have the same number as the corresponding problem independently if I have a subsection in the solutions section or not.
    – student
    Mar 19, 2016 at 16:50
  • 1
    If all you need is to display solutions at the end with same counters as problems we can give you other solutions. There are packages answers ctan.org/pkg/answers for example and more here ctan.org/topic/exercise
    – touhami
    Mar 19, 2016 at 17:44
  • Re: »I played with exsheets but didn't get the correct numbering.« you are a bit impatient :) I'll sent an update to CTAN today or tomorrow which enables the correct numbering (I'll answer your other question then, too)
    – cgnieder
    Mar 21, 2016 at 11:29
  • @clemens Sorry for beeing impatient.I need it for something with a deadline (the day after tomorrow). Thanks for your help!
    – student
    Mar 21, 2016 at 12:10

1 Answer 1

0

I managed to reproduce my style above roughly via exsheets with correct numbering (compiled with the latest (commit 367bf7b) exsheets version from the repository). I didn't manage to apply different styles to questions and solutions and also didn't see how to get the indentation as in my original post.

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{multicol}

\usepackage{exsheets}
\AddCounterPattern[exsheets]{subsection}{sub}


\DeclareInstance{exsheets-heading}{mystyle}{default}{
points-pre-code = [ ,
points-post-code = ) ,
join = 
{
title[r,B]number[l,B](0.333em,0pt) ;
number[r,B]points[l,B](0.333em,0pt)
} ,
attach = { main[l,vc]title[l,vc](0pt,0pt) }
}

\NewQuSolPair{pr}[name=Problem]{Solution}[name=ad Problem]

\SetupExSheets{
question/pre-body-hook=\itshape,
solution/pre-body-hook=\itshape,
counter-within={subsection},
headings=mystyle,
points/name=Punkt/e,counter-format=se.sub.qu}

\begin{document}


\section{Section}

\subsection{Subsection}
\begin{pr}
 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}

\subsection{Subsection}

\begin{pr}
 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}

\begin{pr}
 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}

\section{Section}

\subsection{Subsection}
\begin{pr}
 Problem
\end{pr}
\begin{Solution}
  Solution
\end{Solution}
\newpage


\section{Solutions}
\begin{multicols}{2}
  \printsolutions
\end{multicols}

\end{document}

Output:

output

You must log in to answer this question.

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