summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/quiz2socrative/quiz2socrative.sty
blob: f03b5d9dbd6fa65fa517047ba74aa6fb6d6a9f80 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
%
% quiz2socrative.sty -- preparing questions for socrative quizzes
% by Paolo Lella <paolo.lella@polimi.it>
%
% quiz2socrative.sty is a LaTeX package for preparing
% multiple choice, true/false and short answer questions.
% The main purpouse is to offer a tool to easily insert rather complicated 
% mathematical stuff in socrative quizzes (see https://socrative.com).
%
% This is quiz2socrative version 1.0, October 2019. 
% quiz2socrative is distributed under the LaTeX Project Public License 1.3c.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{quiz2socrative}[2019/10/01 version 1.0 (Paolo Lella)]

\RequirePackage{calc}
\RequirePackage{tikz}
\RequirePackage{etoolbox}
\RequirePackage{pgfmath}
\RequirePackage{graphicx}
\RequirePackage{xcolor}
\RequirePackage{moresize}
\RequirePackage{listofitems}
\RequirePackage{xparse}
\RequirePackage{ifthen}

\setsepchar{\!\!}

\usetikzlibrary{positioning,shapes.misc,shapes.geometric,backgrounds,fit}

\newcommand{\@showBorder}{0}
\newcommand{\showBorder}{\renewcommand{\@showBorder}{1}}
\newcommand{\hideBorder}{\renewcommand{\@showBorder}{0}}

\newcommand{\@mode}{0}

\DeclareOption{pdfQuiz}{
  \renewcommand{\@mode}{1}
  \renewcommand{\@showBorder}{1}
}

\DeclareOption{socrativeQuiz}{
  \renewcommand{\@mode}{0}
  \renewcommand{\@showBorder}{0}
}

\newcommand{\usePdf}{\renewcommand{\@mode}{1}}
\newcommand{\useSocrative}{\renewcommand{\@mode}{0}}

\newcommand{\@enumType}{}

\DeclareOption{numbers}{
  \renewcommand{\@enumType}{\arabic}
}

\DeclareOption{letters}{
  \renewcommand{\@enumType}{\Alph}
}

\newcommand{\useNumbers}{\renewcommand{\@enumType}{\arabic}}
\newcommand{\useLetters}{\renewcommand{\@enumType}{\Alph}}

\newcommand{\@trueLabel}{}
\newcommand{\@falseLabel}{}

\DeclareOption{italian}{
  \renewcommand{\@trueLabel}{VERO}
  \renewcommand{\@falseLabel}{FALSO}
}

\DeclareOption{english}{
  \renewcommand{\@trueLabel}{TRUE}
  \renewcommand{\@falseLabel}{FALSE}
}

\newcommand{\useItalian}{ 
	\renewcommand{\@trueLabel}{VERO}
	  \renewcommand{\@falseLabel}{FALSO}
	 }
\newcommand{\useEnglish}{
	\renewcommand{\@trueLabel}{TRUE}
  	\renewcommand{\@falseLabel}{FALSE}
	}

\ExecuteOptions{letters,italian,socrativeQuiz}
\ProcessOptions\relax

\newcommand{\@showSolution}{0}
\newcommand{\showSolution}{\renewcommand{\@showSolution}{1} \renewcommand{\@mode}{1}}
\newcommand{\hideSolution}{\renewcommand{\@showSolution}{0}}

\newcounter{rispostaCorrente}
\newcounter{rispostaGiusta}


\NewDocumentCommand{\socrativeTF}{O{8cm} m o}{
\begin{tikzpicture}[node distance = 0mm]
\node (Q) at (0,0) [rectangle,minimum width=#1,inner ysep=0.25cm] {\parbox{#1-.5cm}{#2}};
\ifnumcomp{\@mode}{=}{1}{
	\node (V) [below=of Q,xshift=-0.25*#1,minimum width=0.5*#1-0.5cm,minimum height=1cm,draw,rectangle,inner ysep=0.25cm] {\large\bf \@trueLabel};
	\node (F) [below=of Q,xshift=0.25*#1,minimum width=0.5*#1-0.5cm,minimum height=1cm,draw,rectangle,inner ysep=0.25cm] {\large\bf \@falseLabel};
	\ifnumcomp{\@showSolution}{=}{1}{
		\IfNoValueTF{#3}{
			\PackageError{quiz2socrative}{missing solution}{add [0] if the answer is FALSE and [1] if the answer is TRUE at the end of the command string}
		}{
			\ifnumcomp{#3}{=}{1}{%
				\node [below=of Q,xshift=-0.25*#1,minimum width=0.5*#1-0.5cm,minimum height=1cm,draw,cross out,thick] {};
			}{}%
			\ifnumcomp{#3}{=}{0}{%
				\node [below=of Q,xshift=0.25*#1,minimum width=0.5*#1-0.5cm,minimum height=1cm,draw,cross out,thick] {};
			}{}%
		}
	}{}%
}{}
\ifnumcomp{\@showBorder}{=}{1}{
	\ifnumcomp{\@mode}{=}{1}{
		\node (A) [below=of Q,minimum width=#1,minimum height=1.25cm,rectangle] {};
		\draw (Q.north east) -- (Q.north west) -- (A.south west) -- (A.south east) -- cycle;
	}{
		\draw (Q.north east) -- (Q.north west) -- (Q.south west) -- (Q.south east) -- cycle;
	}
}{}
\end{tikzpicture}
}% end \socrativeTF

\NewDocumentCommand{\socrativeMC}{O{8cm} m m o}{
\setsepchar{\!\!}
\readlist*\listaRisposte{#3}
\ifnumcomp{\@showSolution}{=}{1}{
	\IfNoValueTF{#4}{
		\PackageError{quiz2socrative}{missing solution}{add the list [ , ... , ] of the correct answers at the end of the command string}
	}{
		\setsepchar{,}
		\readlist*\listaRisposteCorrette{#4}
	}
}{}
\setcounter{rispostaCorrente}{0}
\begin{tikzpicture}[node distance=0mm]
\node (0) at (0,0) [] {};
\node (Q) [above=of 0,yshift=-0.3cm,rectangle,minimum width=#1,inner ysep=0.3cm] {\parbox[t]{#1-0.5cm}{#2}};

\foreach \i in {1,...,\listaRispostelen}{
\addtocounter{rispostaCorrente}{1}
\node (0) [below=of 0,rectangle, minimum width=#1,minimum height=1cm,inner ysep=0.3cm] {\hspace*{0.75cm}\parbox[t]{#1-1.25cm}{\listaRisposte[\i]}};
\node at (0.north west) [xshift=0.5cm,yshift=-0.5cm,rectangle,draw,minimum width=0.6cm,minimum height=0.6cm] {\bf\large \@enumType{rispostaCorrente}};
\ifnumcomp{\@showSolution}{=}{1}{
	\setcounter{rispostaGiusta}{0}
	\foreach \j in {1,...,\listaRisposteCorrettelen}{
		\ifnumcomp{\listaRisposteCorrette[\j]}{=}{\value{rispostaCorrente}}{\breakforeach}{\addtocounter{rispostaGiusta}{1}}
	}
	\ifnumcomp{\value{rispostaGiusta}}{<}{\listaRisposteCorrettelen}{
		\node at (0.north west) [xshift=0.5cm,yshift=-0.5cm,cross out,thick,draw,minimum width=0.5cm,minimum height=0.5cm] {\bf \phantom{\@enumType{rispostaCorrente}}};
	}{}
}{}
}

\ifnumcomp{\@showBorder}{=}{1}{
		\draw (Q.north east) -- (Q.north west) -- (0.south west) -- (0.south east) -- cycle;
}{}
\end{tikzpicture}
}% end \socrativeMC

\NewDocumentCommand{\socrativeTwoMC}{O{8cm} m m m o}{
\IfNoValueTF{#5}{
	\socrativeMC[#1]{#2}{#3 \!\! #4}
}{
	\socrativeMC[#1]{#2}{#3 \!\! #4}[#5]
}
}

\NewDocumentCommand{\socrativeThreeMC}{O{8cm} m m m m o}{
\IfNoValueTF{#6}{
	\socrativeMC[#1]{#2}{#3 \!\! #4 \!\! #5}
}{
	\socrativeMC[#1]{#2}{#3 \!\! #4 \!\! #5}[#6]
}
}

\NewDocumentCommand{\socrativeFourMC}{O{8cm} m m m m m o}{
\IfNoValueTF{#7}{
	\socrativeMC[#1]{#2}{#3 \!\! #4 \!\! #5 \!\! #6}
}{
	\socrativeMC[#1]{#2}{#3 \!\! #4 \!\! #5 \!\! #6}[#7]
}
}

\NewDocumentCommand{\socrativeFiveMC}{O{8cm} m m m m m m o}{
\IfNoValueTF{#8}{
	\socrativeMC[#1]{#2}{#3 \!\! #4 \!\! #5 \!\! #6 \!\! #7}
}{
	\socrativeMC[#1]{#2}{#3 \!\! #4 \!\! #5 \!\! #6 \!\! #7}[#8]
}
}

\NewDocumentCommand{\socrativeSA}{O{8cm} m o}{
\begin{tikzpicture}[node distance = 0mm]
\node (Q) at (0,0) [rectangle,minimum width=#1,inner ysep=0.25cm] {\parbox{#1-.5cm}{#2}};
\ifnumcomp{\@mode}{=}{1}{
	\IfNoValueTF{#3}{
		\ifnumcomp{\@showSolution}{=}{1}{
			\PackageError{quiz2socrative}{missing solution}{add the answer in square brackets at the end of the command string}		
		}{
			\node (A) [below=of Q,minimum width=#1-0.5cm,minimum height=1cm,rectangle,draw] {};	
		}
	}{
		\ifnumcomp{\@showSolution}{=}{1}{
			\node (A) [below=of Q,minimum width=#1-0.5cm,minimum height=1cm,rectangle,draw] {\parbox{#1-1cm}{#3}};		
		}{
			\node (A) [below=of Q,minimum width=#1-0.5cm,minimum height=1cm,rectangle,draw,fill=white] {\parbox{#1-1cm}{\textcolor{white}{#3}}};				
		}
	}
}{}
\ifnumcomp{\@showBorder}{=}{1}{
	\ifnumcomp{\@mode}{=}{1}{
		\node (L) [below=of A,inner sep = 0pt,yshift=-0.15cm] {};
		\begin{pgfonlayer}{background}
   			\node [draw,rectangle,inner xsep=0,inner ysep=0.2pt,fit=(Q) (L)] {};
  		\end{pgfonlayer}	
	}{
		\begin{pgfonlayer}{background}
   			\node [draw,rectangle,inner sep=0,fit=(Q)] {};
  		\end{pgfonlayer}	
	}
}{}
\end{tikzpicture}
}% end \socrativeSA


\endinput