summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/examples/xsim.texsx-466584.tex
blob: 1f30d3c1b8d2e8cfdab64fe4cd4b1e7f626d1a76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% https://tex.stackexchange.com/q/466584
\documentclass{article}
\usepackage{xsim}
\usepackage{needspace}
\usepackage{tasks}

\DeclareExerciseEnvironmentTemplate{exandsol}{%
  \par\vspace{\baselineskip}
  \Needspace*{2\baselineskip}
  \noindent\sffamily
  \textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}}%
  \GetExercisePropertyT{subtitle}{\hspace{3em}{\small#1}}\par
  \normalfont
}{}

\DeclareExerciseEnvironmentTemplate{flushright}{%
  \begin{flushright}
  \begin{minipage}{.4\linewidth}
    \textsf{Solutions:}\par\normalfont
}{%
  \end{minipage}%
  \end{flushright}%
}

\xsimsetup{
  exercise/within = section ,
  exercise/template = exandsol ,
  solution/template = flushright ,
  solution/print = true
}

\renewcommand*\theexercise{\thesection-\arabic{exercise}}
\newcommand\QA[2]{\IfInsideSolutionTF{#2}{#1}}

\newcommand*\answer[1]{%
  \begingroup
  \def\ExerciseType{exercise}%
  \IfSolutionPrintT{\printsolution{exercise}{#1}}%
  \endgroup
}

\begin{document}

\setcounter{section}{1}
\setcounter{exercise}{30}

\begin{exercise}[ID=one,solution,subtitle=Factorize as much as possible the following expressions.]
  \begin{tasks}
    \task \QA{$(2x-3)^2 - (3x-2)^2 =$}{$-(x+5)(5x-1)$}
    \task \QA{$(x^2-25) - 2(5-x)(x+6) =$}{$(x+5)(3x-17)$}
    \task \QA{$2x(x+2) + (x+1)^2 + 2 =$}{$3(x+1)^2$}
  \end{tasks}
\end{exercise}
\answer{one}

\end{document}