TransWikia.com

xsim and questions in columns within tasks

TeX - LaTeX Asked by Yves C on August 27, 2021

I would do with xsim, successor of exsheets, the same I do with it: lists of questions inside a tasks environment.

Is that possible?

Something like this:

documentclass{article}
usepackage{exsheets, tasks}

makeatletter
defsol{relax}
newcommand*{@exoSol}[1]{%
ES@Line #1 solsol%
}

ExplSyntaxOn
cs_set_eq:NN exsheets_par: scan_stop:
ExplSyntaxOff

SetupExSheets{
  headings=inline-nr,
  counter-format=$cdot$qu$cdot$,
  question/no-skip-below = true,
  question/post-hook={},
  solution/post-hook={hspace{1em}},
  solution/pre-hook={}
  }

longdefES@Line#1sol#2sol{%
begin{question}#1end{question}%
longdef@test{#2}ifx@testemptyelsebegin{solution}#2                    
end{solution}fi%

}


NewTasks[
   label={relax},
   label-width=0em,
   item-indent=0em,
   label-offset=0em,
   item-format={@exoSol},
   before-skip = 0pt]{series}[?]
makeatother

begin{document}

Solve with natural numbers, when possible:
begin{series}(3)
  ? $1+5$ sol $6$
  ? $4-2$ sol $2$
  ? $3-4$ sol impossible
  ? $8+2$ sol $10$
  ? $0+0$
  ? $6times 0$ sol $0$
end{series}

Solutions:par
printsolutions

end{document}

example with exsheets

One Answer

Here is a solution using up to date versions of tasks (2020/01/11 v1.1a) and xsim (2020/02/21 v0.17). It needs xsim to be loaded with the no-files option in order to use the environments inside of other macros. It also utilizes ifblank from the etoolbox package (which is loaded, anyway) for the sake of convenience.

First I slightly change your custom macros (mostly as a matter of taste):

newcommand*sol{}
newcommand*exsol[1]{ESLine#1solsol}
longdefESLine#1sol#2sol{%
  begin{exercise}#1end{exercise}%
  ifblank{#2}{}{begin{solution}#2end{solution}}%
}

Now I define a suitable template for exercises and solutions (note the spaces, they are significant):

DeclareExerciseEnvironmentTemplate{dotted}
  {textbf{$cdot$GetExerciseProperty{counter}$cdot$} }
  { }

Then I tell xsim to use the new template and to omit the heading of printsolutions:

xsimsetup{
  exercise/template = dotted ,
  solution/template = dotted ,
  print-solutions/headings = false
}

And at last I define the tasks environment with an empty label, the numbering comes from xsim:

NewTasksEnvironment[
  label =  ,
  label-width = 0em ,
  item-indent = 0em ,
  label-offset = 0em ,
  item-format = exsol
]{series}[?]

That's it. The document body is the same as in the OP.

enter image description here

The complete code:

documentclass{article}
usepackage[no-files]{xsim}[2020/02/21]
usepackage{tasks}

newcommand*sol{}
newcommand*exsol[1]{ESLine#1solsol}
longdefESLine#1sol#2sol{%
  begin{exercise}#1end{exercise}%
  ifblank{#2}{}{begin{solution}#2end{solution}}%
}

DeclareExerciseEnvironmentTemplate{dotted}
  {textbf{$cdot$GetExerciseProperty{counter}$cdot$} }
  { }

xsimsetup{
  exercise/template = dotted ,
  solution/template = dotted ,
  print-solutions/headings = false
}

NewTasksEnvironment[
  label =  ,
  label-width = 0em ,
  item-indent = 0em ,
  label-offset = 0em ,
  item-format = exsol
]{series}[?]

begin{document}

Solve with natural numbers, when possible:
begin{series}(3)
  ? $1+5$ sol $6$
  ? $4-2$ sol $2$
  ? $3-4$ sol impossible
  ? $8+2$ sol $10$
  ? $0+0$
  ? $6times 0$ sol $0$
end{series}

Solutions:par
printsolutions

end{document}

Answered by cgnieder on August 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP