2

I'm creating a problem set with a hint for each problem. I want to have the list of hints separated from the list of problems. Something like this:

Problem 1
Problem 2
Problem 3

Hint 1
Hint 2
Hint 3

There're gonna be 42 problems. I'm not sure about their order yet. I could simply create separate enviroments with counters for problems and hints. But then when I switch problems, I need to switch hints as well.

I'm just curious if it's possible to create such an enviroment that allows me to keep problem statement and hint together even if they will be rendered in different sections.

2
  • If you are using exam class, one can add extraneous materials using \fullwidth. Jun 2, 2017 at 2:03
  • It is a job for the answers package. Jun 2, 2017 at 2:42

1 Answer 1

4

A version with expl3, storing the problem and hint content in different property lists and extracting them later either in sequence or only a selected subset of it.

\DefineProblem{foo}[foo hint] will define the problem and its hint, \ProblemDisplay* will show all problems, \ProblemDisplay[select={1,3}] will show only problems 1 and 3. This fills the list of hints to be shown as well. Problems with no hints won't be shown.

Use \HintDisplay to display the hints later on.

\documentclass{article}

\usepackage{xparse}

\usepackage[most]{tcolorbox}

\newcounter{prbcntr}
\newcounter{prbdefcntr}


\newtcolorbox[auto counter]{problembox}[1][]{colback=white,enhanced,sharp corners,colbacktitle={yellow},coltitle=black,title={Problem \thetcbcounter},#1}
\newtcolorbox{hintbox}[1][]{colback=white,enhanced,sharp corners,colbacktitle={green},coltitle=black,title={Hint \theprbcntr},#1}

\ExplSyntaxOn

\prop_new:N \g_patrik_problem_prop
\prop_new:N \g_patrik_hint_prop





\cs_generate_variant:Nn \prop_gput:Nnn {Nxn}

\NewDocumentCommand{\DefineProblem}{O{}+m+o}{%
  \refstepcounter{prbdefcntr}%
  \prop_gput:Nxn \g_patrik_problem_prop {defproblem\theprbdefcntr}{#2}
  \IfValueT{#3}{%
    \prop_gput:Nxn \g_patrik_hint_prop {hintproblem\theprbdefcntr}{#3}
  }
}

\keys_define:nn {patrik} {
  select .code:n={\seq_set_from_clist:Nn \l_tmpa_seq {#1}},
  tcolorbox .code:n={\cs_set:Npn \localtcolorboxoptions {#1}}
}

\NewDocumentCommand{\ProblemDisplay}{sO{}}{%
  \group_begin:
  \cs_set:Npn \localtcolorboxoptions {}
  \keys_set:nn {patrik}{#2}
  \IfBooleanTF{#1}{%
    \int_zero:N \l_tmpa_int
    \prop_map_inline:Nn \g_patrik_problem_prop {%
      \int_incr:N \l_tmpa_int
      \seq_gput_right:NV \g_patrik_display_seq {\l_tmpa_int}
      \begin{problembox}[code={\pgfkeysalsofrom{\localtcolorboxoptions}}]
        ##2
      \end{problembox}
    }
  }{%
    \seq_gset_eq:NN \g_patrik_display_seq \l_tmpa_seq
    \seq_map_inline:Nn \g_patrik_display_seq {%
      \begin{problembox}[code={\pgfkeysalsofrom{\localtcolorboxoptions}}]
        \prop_item:Nn \g_patrik_problem_prop {defproblem##1}
      \end{problembox}
    }
  }
  \group_end:
}


\NewDocumentCommand{\HintDisplay}{O{}}{%
  \setcounter{prbcntr}{0}
  \seq_map_inline:Nn \g_patrik_display_seq {%
    \stepcounter{prbcntr}%
    \prop_if_in:NnT \g_patrik_hint_prop {hintproblem##1} {
      \begin{hintbox}[#1]
        \prop_item:Nn \g_patrik_hint_prop {hintproblem##1}
      \end{hintbox}
    }
  }
}





\seq_new:N \g_patrik_display_seq% Stores the number of the displayed problems

\ExplSyntaxOff


\DefineProblem{%
  Proove $E=mc^{2}$
}[Use your brain]

\DefineProblem{%
  Proove that in any rectangular triangle with hypotenuse $c$ and cathetes $a$ and $b$ the theorem of Pythagoras holds: \begin{align}c^{2} &= a^{2} + b^{2}\end{align}
}[Make a sketch]


\begin{document}

\ProblemDisplay*[tcolorbox={colback=yellow!40!white}]

% Or select some of the problems:

%\ProblemDisplay[select={2},tcolorbox={colback=yellow!40!white}]

\HintDisplay





\end{document}

enter image description here

You must log in to answer this question.

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