-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamS2M.sty
309 lines (244 loc) · 8.44 KB
/
examS2M.sty
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{examS2M}[27/12/2019]
% Package écrit par Pariterre pour le laboratoire S2M
% Version 1 - 18/04/2016
% Première version, les questions vrais ou faux, à choix multiple, à développement et custom pour les deux derniers sont possibles
% Version 1.1 - 04/09/2016
% Ajout de la possibilité de mettre des réponses pour les questions custom et gestion légère d'un layout
% Version 1.2 - 27/12-2019
% Les bonnes réponses sont maintenant toutes labellées bonneReponse
% Tous ces packages sont nécessaires
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{xparse}
\RequirePackage{soulutf8,color}
\RequirePackage{tabularx}
\RequirePackage{amssymb}
\RequirePackage{etoolbox}
\RequirePackage{array}
\RequirePackage{enumitem}
\RequirePackage{pgffor}
\RequirePackage{xparse}
\RequirePackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\RequirePackage{lastpage}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\RequirePackage{totcount}
%%%%% OPTIONS %%%%%
% Dessiner la bonne réponse
\newcommand{\hlAnswer}{}
\newcommand\bonneReponse[1]{}
\DeclareOption{corrige}{
\let\hlAnswer\hl
\renewcommand\bonneReponse[1]{\hlAnswer{Réponse:} #1}
}
\ProcessOptions
%%%%%%%%%%%%%%%%%%%
%%%%% GESTION DE L'EN-TÊTE %%%%%
% Département et université
% Commandes d'en-tête
\def\universiteVar{}
\def\departementVar{}
\newcommand{\universite}[1]{\def\universiteVar{#1}}
\newcommand{\departement}[1]{\def\departementVar{#1}}
% Nom du cours
\def\sigleCoursVar{}
\newcommand{\sigleCours}[1]{\def\sigleCoursVar{\uppercase{#1}}}
\def\nomCoursVar{}
\newcommand{\nomCours}[1]{\def\nomCoursVar{\uppercase{#1}}}
% Infos sur l'exam
\def\typeExamenVar{}
\def\dateExamenVar{}
\def\nomProfVar{}
\def\ponderationVar{}
\newcommand{\typeExamen}[1]{\def\typeExamenVar{#1}}
\newcommand{\dateExamen}[1]{\def\dateExamenVar{#1}}
\newcommand{\nomProf}[1]{\def\nomProfVar{#1}}
\newcommand{\ponderation}[1]{\def\ponderationVar{#1}}
% Définition de l'environnement directive
\NewDocumentEnvironment{directives}{}{
\begin{center}
\uppercase{Directives}
\end{center}
\begin{enumerate}[leftmargin=*,itemsep=0mm]
\small
}
{
\end{enumerate}
}
% Définition de l'environnement autres infos
\NewDocumentEnvironment{autresInfos}{}{
\begin{flushleft}
\rule{\textwidth}{2px}
Inscrire votre nom, code permanent et signer l'examen. \linebreak
Rendre ce document sinon $0/100$ \linebreak
Vous pouvez détailler vos calculs à côté des questions \linebreak
\begin{table}[!h]
\vspace{-17px}
}
{
\end{table}
\begin{table}[!h]
\vspace{-17px}
\begin{tabularx}{\linewidth}{Xr}
\hspace{-9px} Assurez-vous d'avoir \pageref{LastPage} pages dans votre questionnaire. & \textsc{Bon examen !} \\
\end{tabularx}
\rule{\textwidth}{2px}
\end{table}
\end{flushleft}
}
\newcommand\entete{
% Département et université
\begin{table}
\hspace{-15px}
\begin{tabularx}{\linewidth}{Xr}
\textbf{\departementVar} & \textbf{\universiteVar} \\
\end{tabularx}
\end{table}
% Nom du cours
\begin{center}
\sigleCoursVar \ - \nomCoursVar
\end{center}
% Infos sur l'exam
\begin{table}[!h]
\hspace{-15px}
\begin{tabularx}{\linewidth}{Xr}
\textbf{Examen \typeExamenVar} & \textbf{\dateExamenVar} \\
\textbf{Professeur : } \nomProfVar & \\
\textbf{Pondération : } \ponderationVar\% & Total \rule{20px}{1px} / 100
\end{tabularx}
\end{table}
% Infos de l'étudiant
\begin{table}[!h]
\hspace{-15px}
\begin{tabularx}{\linewidth}{Xr}
\textbf{Nom de l'étudiant : } \rule{175px}{1px} & \textbf{Matricule : } \rule{75px}{1px} \\
\end{tabularx}
\end{table}
}
%%%0%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Écrire 1 point ou x points
\newcommand\points[1]{#1~\ifnumgreater{#1}{1}{points}{point}}
% Définition de l'environnement questions
\newenvironment{questions}{\begin{enumerate}[leftmargin=*,itemsep=0mm] \def\Mycurrentvir{questions}}{\end{enumerate}}
% S'assurer que l'utilisateur est dans la section question (Pour incrémenter questions)
\makeatletter
\def\Mycurrentvir{document}
\def\ifenv#1{
\def\@tempa{#1}%
\ifx\@tempa\Mycurrentvir
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\newcommand\checkForEnvironnementQuestion{\ifenv{questions}{}{\PackageError{}{Une question dois etre dans un environnement question}{}}}
% Préparer une question, la minipage s'assure que la question ne span pas sur plusieurs pages
\newcommand\prepareQuestion{\begin{minipage}{\linewidth} }
\newcommand\terminateQuestion{\end{minipage}}
%%%%%% QUESTION VRAI OU FAUX %%%%%%
\newtotcounter{NombreVraiOuFaux}
\newcommand\carre{\vspace{-18px}$\square$}
\newcommand\carreBonneReponse{\vspace{-18px}\hlAnswer{$\square$}}
% Définition de nouvelles colonnes. Sera utile pour aligner les cases de vrai et faux
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
% Dessiner une ligne, l'argument 1 est le nombre de points
\newcommand\enteteSectionVraiOuFaux[1]{
\vspace{15px}
\rule{.5\linewidth}{2px} \\
\begin{tabularx}{\linewidth}{XC{.08\linewidth}C{.08\linewidth}}
\large \textbf{Vrai ou faux} (\points{#1} par bonne réponse) & \normalsize Vrai & Faux \\
\end{tabularx}
}
% Définition de l'environnement en soit, l'argument 1 est la question, l'argument deux est 'vrai', 'faux' ou vide
\NewDocumentEnvironment{vraiOuFaux}{mm}{
\stepcounter{NombreVraiOuFaux}
\checkForEnvironnementQuestion
\prepareQuestion
\begin{tabularx}{\linewidth}{XC{.08\linewidth}C{.08\linewidth}}
\item #1 & \ifstrequal{#2}{vrai}{\carreBonneReponse & \carre}{\ifstrequal{#2}{faux}{\carre & \carreBonneReponse}{\carre & \carre}}
\end{tabularx}
}
{
\terminateQuestion
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% QUESTION À CHOIX MULTIPLES %%%%%%
\newtotcounter{NombreChoixMultiples}
% Dessiner une ligne, l'argument 1 est le nombre de points
\newcommand\enteteSectionChoixMultiples[1]{
\vspace{15px}
\rule{.5\linewidth}{2px} \\
\begin{tabularx}{\linewidth}{X}
\large \textbf{Choisir la meilleure réponse} (\points{#1} par bonne réponse) \\
\end{tabularx}
}
% Définition de l'environnement. L'argument 1 est la question
\NewDocumentEnvironment{choixMultiples}{m}{
\let\reponse\item
\renewcommand\bonneReponse{
\addtocounter{enumii}{1}
\item[\hlAnswer{(\theenumii)}]
}
\stepcounter{NombreChoixMultiples}
\checkForEnvironnementQuestion
\prepareQuestion
\item #1
\vspace{10px}
\begin{enumerate}
\begin{minipage}{.9\linewidth}
\small
}
{
\end{minipage} \end{enumerate}
\terminateQuestion
\vspace{15px}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% QUESTION À DÉVELOPPEMENT %%%%%
\newtotcounter{NombreDeveloppement}
\newcommand\enteteSectionDeveloppement{
\vspace{15px}
\rule{.5\linewidth}{2px} \\
\begin{tabularx}{\linewidth}{X}
\large \textbf{Ecrivez la meilleure réponse} \\
\end{tabularx}
}
% Définition de l'environnement, l'argument 1 est la question, l'argument 2 est le nombre de lignes
\NewDocumentEnvironment{Developpement}{mm}{
\stepcounter{NombreDeveloppement}
\checkForEnvironnementQuestion
\prepareQuestion
\item #1
}
{
\vspace{15px}
\foreach \x in {1,...,#2}{\hrule \vspace{15px}}
\terminateQuestion
\vspace{15px}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% QUESTION CUSTOM %%%%%%
% Définition de l'environnement. L'argument 1 est la question
\NewDocumentEnvironment{customQuestion}{mm}{
\checkForEnvironnementQuestion
\ifstrequal{#2}{choixMultiples}{
\stepcounter{NombreChoixMultiples}
\let\reponse\item
}{
\ifstrequal{#2}{vraiOuFaux}{\stepcounter{NombreVraiOuFaux}}{
\ifstrequal{#2}{Developpement}{\stepcounter{NombreDeveloppement}}{}}}
\prepareQuestion
\item #1
}
{
\terminateQuestion
\vspace{15px}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Écrire le nombre de page total à chaque page
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{15pt}
\cfoot{\thepage\ / \pageref{LastPage}}