| 1 |
% https://tex.stackexchange.com/q/466584 |
| 2 |
\documentclass{article} |
| 3 |
\usepackage{xsim} |
| 4 |
\usepackage{needspace} |
| 5 |
\usepackage{tasks} |
| 6 |
|
| 7 |
\DeclareExerciseEnvironmentTemplate{exandsol}{% |
| 8 |
\par\vspace{\baselineskip} |
| 9 |
\Needspace*{2\baselineskip} |
| 10 |
\noindent\sffamily |
| 11 |
\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}% |
| 12 |
\GetExercisePropertyT{subtitle}{\hspace{3em}{\small#1}}\par |
| 13 |
\normalfont |
| 14 |
}{} |
| 15 |
|
| 16 |
\DeclareExerciseEnvironmentTemplate{flushright}{% |
| 17 |
\begin{flushright} |
| 18 |
\begin{minipage}{.4\linewidth} |
| 19 |
\textsf{Solutions:}\par\normalfont |
| 20 |
}{% |
| 21 |
\end{minipage}% |
| 22 |
\end{flushright}% |
| 23 |
} |
| 24 |
|
| 25 |
\xsimsetup{ |
| 26 |
exercise/within = section , |
| 27 |
exercise/template = exandsol , |
| 28 |
solution/template = flushright , |
| 29 |
solution/print = true |
| 30 |
} |
| 31 |
|
| 32 |
\renewcommand*\theexercise{\thesection-\arabic{exercise}} |
| 33 |
\newcommand\QA[2]{\IfInsideSolutionTF{#2}{#1}} |
| 34 |
|
| 35 |
\newcommand*\answer[1]{% |
| 36 |
\begingroup |
| 37 |
\def\ExerciseType{exercise}% |
| 38 |
\IfSolutionPrintT{\printsolution{exercise}{#1}}% |
| 39 |
\endgroup |
| 40 |
} |
| 41 |
|
| 42 |
\begin{document} |
| 43 |
|
| 44 |
\setcounter{section}{1} |
| 45 |
\setcounter{exercise}{30} |
| 46 |
|
| 47 |
\begin{exercise}[ID=one,solution,subtitle=Factorize as much as possible the following expressions.] |
| 48 |
\begin{tasks} |
| 49 |
\task \QA{$(2x-3)^2 - (3x-2)^2 =$}{$-(x+5)(5x-1)$} |
| 50 |
\task \QA{$(x^2-25) - 2(5-x)(x+6) =$}{$(x+5)(3x-17)$} |
| 51 |
\task \QA{$2x(x+2) + (x+1)^2 + 2 =$}{$3(x+1)^2$} |
| 52 |
\end{tasks} |
| 53 |
\end{exercise} |
| 54 |
\answer{one} |
| 55 |
|
| 56 |
\end{document} |