1

I have set up a document with a structure like this

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{exsheets}
\usepackage{tasks}

\newcommand{\righty}{$\checkmark$}
\newcommand{\checky}{$\Box$}

\SetupExSheets{counter-format=se.qu,counter-within=section}
\settasks{label={\checky}}

\begin{document}

\begin{question}
    How much do you like your teacher?
    \begin{tasks}
        \task[\righty] I'm indifferent to this
        \task I hate them to death
        ...
    \end{tasks}
\end{question}

\end{document}

As you can see, this document is generating the solutions to the questions at the moment. I would now like to add a switch to generate the unanswered questions as well, randomizing the items in the task environments.

Is something like this possible without changing the current structure? I have right about 250 questions inside that document, so it would be in my best interest not to change each of these, but best practice is always appreciated. I'm sorry for that kind of request, but I'm far too new to such tasks that I would knew where to start.

2

Adding the switch is as easy as this:

\newif\ifanswers
% \answerstrue % uncomment to display answers

\newcommand{\righty}{\ifanswers$\checkmark$\else\checky\fi}

With this you only need to comment or uncomment \answerstrue for the two versions of the document.

Shuffling the items of the tasks environment is not that hard either albeit a hack because it requires a redefinition of a tasks internal. Be aware that the order will be shuffled differently each time you re-compile:

\ExplSyntaxOn
\cs_set_protected:Npn \tasks_environment:nnnn #1#2#3#4
  {
    \bool_if:NT \l__tasks_debug_bool { \dim_set:Nn \fboxsep {0pt} }
    \seq_set_split:Nnn \l__tasks_seq {#3} {#4}
    \seq_pop_left:NN \l__tasks_seq \l__tasks_tmpa_tl
    \seq_shuffle:N \l__tasks_seq % <<< this is added
    \tl_if_blank:VF \l__tasks_tmpa_tl
      { \msg_warning:nnVn {tasks}{no-item} \l__tasks_tmpa_tl {#3} }
    \int_gset:Nn \g__tasks_total_items_int
      { \seq_count:N \l__tasks_seq }
    \UseInstance {tasks} {#1}
      { \g__tasks_total_items_int }
      {#2}
      { }
    \seq_clear:N \l__tasks_seq
  }
\ExplSyntaxOff

The complete example:

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amssymb}
\usepackage{exsheets}
\usepackage{tasks}

\newif\ifanswers
% \answerstrue % uncomment to display answers

\newcommand{\righty}{\ifanswers$\checkmark$\else\checky\fi}
\newcommand{\checky}{$\Box$}

\SetupExSheets{counter-format=se.qu,counter-within=section}
\settasks{label={\checky}}

\ExplSyntaxOn
\cs_set_protected:Npn \tasks_environment:nnnn #1#2#3#4
  {
    \bool_if:NT \l__tasks_debug_bool { \dim_set:Nn \fboxsep {0pt} }
    \seq_set_split:Nnn \l__tasks_seq {#3} {#4}
    \seq_pop_left:NN \l__tasks_seq \l__tasks_tmpa_tl
    \seq_shuffle:N \l__tasks_seq % <<< this is added
    \tl_if_blank:VF \l__tasks_tmpa_tl
      { \msg_warning:nnVn {tasks}{no-item} \l__tasks_tmpa_tl {#3} }
    \int_gset:Nn \g__tasks_total_items_int
      { \seq_count:N \l__tasks_seq }
    \UseInstance {tasks} {#1}
      { \g__tasks_total_items_int }
      {#2}
      { }
    \seq_clear:N \l__tasks_seq
  }
\ExplSyntaxOff

\begin{document}

\begin{question}
  How much do you like your teacher?
  \begin{tasks}
  \task[\righty] I'm indifferent to this
  \task I hate them to death
  \task What is Love?
  \task I have a crush.
  \end{tasks}
\end{question}

\end{document}

enter image description here

1
  • Nothing to add, just that I like your sense of humour
    – dakralex
    Jan 26 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.