slatex / sTeX

A semantic Extension of TeX/LaTeX
49 stars 9 forks source link

Tracker: redesign problem.sty #391

Closed kohlhase closed 9 months ago

kohlhase commented 1 year ago

We are using problem.sty more and more, it needs some serious redesign, I will collect ideas here.

There are also a lot of useful things maybe worth considering in George Goguadse's dissertation from 2010 which addresses task management in the ActiveMath System. I am not aware of something better since.

kohlhase commented 1 year ago

Here is a first idea for fillinsol environment:

\begin{sproblem}
  In 2019, Erlangen was a city of
  \begin{fillin}[type=int]
    \numrange[feedback={No,that would be a village}]{0-1000}
    \numrange[feedback={No,that would be a town}]{1001-100000}
    \exactanswer[T,feedback={Wow, you known your numbers, that is exactly correct according to wikipedia}]{111962}
    \numrange[T,feedback={Yes, it is close to 109000}]{100000-120000}
    \numrange[feedback={No, that is too large}]{1200001-}
    \regex[feedback={What do negative Inhabitants even mean?}]{-.[0-9]+}
    \otheranswer[feedback={Please give a natural number}]
  \end{fillin}
  inhabitants
\end{sproblem}

The {fillin} yields a text box, its type attribute may allow to reject ill-typed entries (that could also be a regular expression).

The children specify answer classes in various ways they all have the same keyword attributes as \mcc to arrange for feedback, grading, ... ;

Of course, names can still change, but this would work. I am not sure yet what the PDF is I want to generate for this. Have to implement it to play around with it.

The currently existing \fillinsol{4} is equivalent to

\begin{fillin}
\exactanswer[T]{4}
\otheranswer
\end{fillin}
kohlhase commented 1 year ago

As a general design I am leaning towards generalizing all the functionality into the concept of an "answer set" (a set of answer class representations) that have different interactions and styles. Let's hash this out a bit The current

\begin{mcb}
  \mcc[T]{some description}

would become

\begin{answerset}[interaction=multiple-choice]
  \achoice[T]{some description}

and analogously for single-choice, making #389 obsolete. The {fillin} proposed above would become

\begin{answerset}[interaction=fillin,filter=remove-blanks]

And finally, the current {solution} envionment becomes

\begin{answerset}[interaction=manual]
  \begin{solution}

Admittedly, this is more verbose, but we could just leave the {answerset}[interaction=manual] for the OMDoc harvester to integrate by default.

kohlhase commented 1 year ago

I am also leaning towards re-organizing how we do subproblems. Currently we commonly use "corresponding enumeration", which is very implicit, like so:

\begin{sproblem}[id=thisnthat,title=This and That]
  Some general setup
  \begin{enumerate}
  \item do this
  \item do that based on this
  \item finally do something else
  \end{enumerate}
\begin{solution}
  \begin{enumerate}
  \item we do this
  \item we do that based on this
  \item we finally do something else
  \end{enumerate}
\end{solution}
\end{sproblem}

And I think that slightly more verbose but more more modularly the following would be much better.

\begin{sproblem}[id=thisnthat,title=This and That]
  Some general setup
  \begin{subproblems}[style=enumerate]
    \begin{sproblem}[id=this]
      do this
      \begin{solution}
        this is how we do this
      \end{solution}
    \end{sproblem}
    \begin{sproblem}[id=that,requires=this]
      do that based on this
      \begin{solution}
        this is how we do that based on this 
      \end{solution}
    \end{sproblem}
    \begin{sproblem}
      finally do something else
      \begin{solution}[id=else]
        and finally this is how we do something else
      \end{solution}
    \end{sproblem}
  \end{subproblems}
\end{sproblem}

This is quite obvious, and should be very easy to realize. But we can already see an advantage: The modularity allows us to leave out some subproblems, e.g. we could specify them in

\includeproblem[leaveout={that,else}]{...

which would give us a problem with only one subproblem (where we could leave out the enumerate altogether). Currently Florian "solves" this situation by commenting out the respective \items in the source code.

And there is another advantage: in the second subproblem we have specified a requires=this, which means that there is a conceptual dependency, so that we could raise an exception when we try leaveout={this} which would result in a dangling second subroblem.

kohlhase commented 1 year ago

Dennis just convinced me that the leaveout idea is dangerous and very hard to realize. We will have to develop a practice with \inputref to get this done, i.e. instead of

\includeproblem[leaveout={that,else}]{...

we would have a separate problem file that inputrefs the shared snippets to get around the copy/paste problems.

kohlhase commented 1 year ago

Also Dennis comments that instead of nesting {sproblem} we should use a new environment {subproblem}.

kohlhase commented 1 year ago

I have a first impementation for the {fillin} environment:

\documentclass{article}
\usepackage{keyval,amssymb}
%\usepackage[hints,notes]{problem}
\usepackage[solutions,hints,notes]{problem}
\newenvironment{fillin}[2][]{%
  \fbox{\ifsolutions#2\else\phantom{\Huge{#2}}\fi}%
  \ifsolutions\par%
  \begin{tabular}{|l|l|l|p{6cm}|}\hline%
    \multicolumn{4}{|c|}{Autocorrection Rules}\\\hline%
    rel & what & verdict & Feedback\\\hline%
    \fi}
{\ifsolutions\end{tabular}\fi}
\makeatletter
\def\answer@verdict{Incorrect}
\define@key{answer}{T}[t]{\gdef\answer@verdict{Correct}}
\define@key{answer}{feedback}{\gdef\answer@feedback{#1}}
\newcommand\exactanswer[2][]{\setkeys{answer}{#1}%
\ifsolutions =& #2&\answer@verdict & \answer@feedback\\\hline\fi}
\newcommand\numrange[2][]{\setkeys{answer}{#1}%
\ifsolutions range & #2&\answer@verdict & \answer@feedback\\\hline\fi}
\newcommand\regex[2][]{\setkeys{answer}{#1}%
\ifsolutions regex & #2&\answer@verdict & \answer@feedback\\\hline\fi}
\newcommand\otheranswer[1][]{\setkeys{answer}{#1}%
\ifsolutions other &answer &\answer@verdict & \answer@feedback\\\hline\fi}
\makeatother 
\begin{document}
\begin{sproblem}
  In 2019, Erlangen is a city of
  \begin{fillin}[type=int,width=3cm,height=1cm]{111962}
    \exactanswer[T,feedback={Wow, you known your numbers, that is exactly correct according to wikipedia}]{111962}
    \numrange[feedback={No,that would be a village}]{0-1000}
    \numrange[feedback={No,that would be a town}]{1001-100000}
   \numrange[T,feedback={Yes, it is close to 109000}]{100000-120000}
    \numrange[feedback={No, that is too large}]{1200001-}
    \regex[feedback={What do negative Inhabitants even mean?}]{-.[0-9]+}
    \otheranswer[feedback={Please give a natural number}]
 \end{fillin}
  inhabitants
\end{sproblem}
\end{document}
kohlhase commented 1 year ago

With the solutions option given it gives

Screenshot 2023-06-30 at 09 46 49

without the expected

Screenshot 2023-06-30 at 09 47 17
kohlhase commented 1 year ago

Jonas just made me aware of the fact that the last three should be incorrect. Have to see.

kohlhase commented 1 year ago

OK, fixed that in my private version, it was just the naive way of handling keyword arguments. Shoudl be fixed in a real implementation.

kohlhase commented 1 year ago

The more I think about the {subproblems} approach, the more it seems right to me. I am starting to use it in the problems. I only had to add

\newif\ifinsubproblems\insubproblemsfalse
\newenvironment{subproblems}[1][]{\begin{enumerate}\insubproblemstrue}{\end{enumerate}}
\newenvironment{subproblem}[1][]{\ifinsubproblems\item\fi}{}

to MathHub/MiKoProblems/meta-inf/lib/preamble.tex to get it to run. The conditional is to allow {subproblem} environments to be snippetized into their own documents. The problem there is that this does not allow {solution} environments yet. That still has to be restored.

I am also ignoring the keyword arguments for the moment, but they are quite natural, the ones for {subproblem} should be the same as for {sproblem}. Then we can replace the common

\item\pts4

with

\begin{subproblem}[pts=4]
Jazzpirate commented 1 year ago

Protocol over what I'm doing:

kohlhase commented 1 year ago

Do I understand correctly that the {subproblems} environment is no longer needed?

Jazzpirate commented 1 year ago

cont'd:

kohlhase commented 1 year ago

cool, what is still missing?

Jazzpirate commented 1 year ago

The MMT side of things and answer classes in general problems we discussed - but since we can't exploit the latter for now anyway, I should probably just implement the superficials so we have something to work with for now

kohlhase commented 1 year ago

I agree. After you have completed problem.sty, then I have to do a lot of work on the sTeX sources.

Jazzpirate commented 1 year ago

Pushed sTeX and MMT (on the newrelational branch). Will restart buildserver on staging soon

kohlhase commented 1 year ago

Can this work? I have not done anything to the problems to adapt the syntax yet.

Jazzpirate commented 1 year ago

Oh. Right. Nevermind then - I'll leave you to it first :D Let me know when to do the thing :)

kohlhase commented 9 months ago

We have a first stable release, it even has documentation.