| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2014 by Henry Menke <[email protected]> |
| 4 |
% Copyright (C) 2019 by Benjamin Berg <[email protected]> |
| 5 |
% |
| 6 |
% This work may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% This work has the LPPL maintenance status `maintained'. |
| 13 |
% |
| 14 |
% The Current Maintainer of this work is Benjamin Berg. |
| 15 |
% |
| 16 |
% \fi |
| 17 |
% |
| 18 |
% \iffalse |
| 19 |
%<*driver> |
| 20 |
\ProvidesFile{sdapslayout.dtx} |
| 21 |
%</driver> |
| 22 |
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 23 |
%<package>\ProvidesPackage{sdapslayout} |
| 24 |
%<*package> |
| 25 |
[2015/04/10 v0.1 Initial version of SDAPS layout package] |
| 26 |
%</package> |
| 27 |
% |
| 28 |
%<*driver> |
| 29 |
\documentclass{l3doc} |
| 30 |
\usepackage{sdapslayout}[2015/04/10] |
| 31 |
\EnableCrossrefs |
| 32 |
%\CodelineIndex |
| 33 |
\RecordChanges |
| 34 |
\begin{document} |
| 35 |
\DocInput{sdapslayout.dtx} |
| 36 |
\end{document} |
| 37 |
%</driver> |
| 38 |
% \fi |
| 39 |
% |
| 40 |
% \CheckSum{0} |
| 41 |
% |
| 42 |
% \CharacterTable |
| 43 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 44 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 45 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 46 |
% Exclamation \! Double quote \" Hash (number) \# |
| 47 |
% Dollar \$ Percent \% Ampersand \& |
| 48 |
% Acute accent \' Left paren \( Right paren \) |
| 49 |
% Asterisk \* Plus \+ Comma \, |
| 50 |
% Minus \- Point \. Solidus \/ |
| 51 |
% Colon \: Semicolon \; Less than \< |
| 52 |
% Equals \= Greater than \> Question mark \? |
| 53 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 54 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 55 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 56 |
% Right brace \} Tilde \~} |
| 57 |
% |
| 58 |
% |
| 59 |
% \changes{v0.1}{2015/01/14}{Initial version} |
| 60 |
% |
| 61 |
% \GetFileInfo{sdapslayout.dtx} |
| 62 |
% |
| 63 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 64 |
% |
| 65 |
% |
| 66 |
% \title{The \textsf{sdapslayout} package\thanks{This document |
| 67 |
% corresponds to \textsf{sdapslayout}~\fileversion, dated \filedate.}} |
| 68 |
% \author{Benjamin Berg \\ \texttt{[email protected]}} |
| 69 |
% |
| 70 |
% \maketitle |
| 71 |
% |
| 72 |
% \section{Documentation} |
| 73 |
% |
| 74 |
% Please refer to \url{https://sdaps.org/class-doc} for documentation. |
| 75 |
% |
| 76 |
% \section{Implementation} |
| 77 |
% |
| 78 |
% This package uses the \LaTeX3 language internally, so we need to enable it. |
| 79 |
% \begin{macrocode} |
| 80 |
% We need at least 2011-08-23 for \keys_set_known:nnN |
| 81 |
\RequirePackage{expl3}[2011/08/23] |
| 82 |
%\RequirePackage{xparse} |
| 83 |
\ExplSyntaxOn |
| 84 |
% \end{macrocode} |
| 85 |
% |
| 86 |
% And we need a number of other packages. |
| 87 |
% \begin{macrocode} |
| 88 |
\ExplSyntaxOff |
| 89 |
|
| 90 |
\RequirePackage{sdapsbase} |
| 91 |
\RequirePackage{sdapsarray} |
| 92 |
\RequirePackage{xparse} |
| 93 |
|
| 94 |
|
| 95 |
\ExplSyntaxOn |
| 96 |
|
| 97 |
% \end{macrocode} |
| 98 |
% |
| 99 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 100 |
% |
| 101 |
% |
| 102 |
% \subsection{Choice Question Layout} |
| 103 |
% |
| 104 |
% \subsubsection{Choice Question Matrix Layout} |
| 105 |
% |
| 106 |
% The following macros provide the funcitonality to layout choice questions in |
| 107 |
% a matrix like fashion. |
| 108 |
% |
| 109 |
% \begin{macrocode} |
| 110 |
|
| 111 |
\tl_new:N \l_sdaps_choicearray_qobject_type_tl |
| 112 |
\bool_new:N \l_sdaps_choicearray_horizontal_bool |
| 113 |
\tl_new:N \l_sdaps_choicearray_layouter_tl |
| 114 |
\tl_new:N \l_sdaps_choicearray_align_tl |
| 115 |
\tl_new:N \l_sdaps_choicearray_extra_tl |
| 116 |
\tl_new:N \l_sdaps_choicearray_type_tl |
| 117 |
\tl_new:N \l_sdaps_choice_var_tl |
| 118 |
\tl_new:N \l_sdaps_choice_val_tl |
| 119 |
\tl_new:N \l_sdaps_choice_text_tl |
| 120 |
\tl_new:N \l_sdaps_question_var_tl |
| 121 |
\tl_new:N \l_sdaps_question_text_tl |
| 122 |
\clist_new:N \l_sdaps_question_range_clist |
| 123 |
\int_new:N \g_sdaps_choices_box_int |
| 124 |
\seq_new:N \g_sdaps_choices_filter_seq |
| 125 |
\seq_new:N \g_sdaps_choices_cell_seq |
| 126 |
\seq_new:N \g_sdaps_choices_text_seq |
| 127 |
|
| 128 |
\keys_define:nn { sdaps / choicearray } |
| 129 |
{ |
| 130 |
horizontal .bool_set:N = \l_sdaps_choicearray_horizontal_bool, |
| 131 |
horizontal .default:n = true, |
| 132 |
horizontal .initial:n = true, |
| 133 |
vertical .bool_set_inverse:N = \l_sdaps_choicearray_horizontal_bool, |
| 134 |
vertical .default:n = true, |
| 135 |
layouter .tl_set:N = \l_sdaps_choicearray_layouter_tl, |
| 136 |
layouter .initial:n = default, |
| 137 |
align .tl_set:N = \l_sdaps_choicearray_align_tl, |
| 138 |
align .initial:n = { }, |
| 139 |
|
| 140 |
type .choices:nn = { multichoice, singlechoice } { \tl_set:Nx \l_sdaps_choicearray_type_tl { \l_keys_choice_tl } }, |
| 141 |
type .initial:n = { multichoice }, |
| 142 |
|
| 143 |
singlechoice .meta:n = { type=singlechoice }, |
| 144 |
multichoice .meta:n = { type=multichoice }, |
| 145 |
|
| 146 |
noalign .meta:n = { align= }, |
| 147 |
} |
| 148 |
|
| 149 |
\keys_define:nn { sdaps / choicearray / choice } |
| 150 |
{ |
| 151 |
var .tl_set:N = \l_sdaps_choice_var_tl, |
| 152 |
val .tl_set:N = \l_sdaps_choice_val_tl, |
| 153 |
text .tl_set:N = \l_sdaps_choice_text_tl, |
| 154 |
} |
| 155 |
|
| 156 |
\keys_define:nn { sdaps / choicearray / question } |
| 157 |
{ |
| 158 |
var .tl_set:N = \l_sdaps_question_var_tl, |
| 159 |
text .tl_set:N = \l_sdaps_question_text_tl, |
| 160 |
|
| 161 |
range .clist_set:N = \l_sdaps_question_range_clist, |
| 162 |
range .initial:n = {...} |
| 163 |
} |
| 164 |
|
| 165 |
\cs_new_protected_nopar:Npn \_sdaps_choicearray_preprocess:n #1 |
| 166 |
{ |
| 167 |
\keys_set_known:nnN { sdaps / choicearray } { #1 } \l_sdaps_choicearray_extra_tl |
| 168 |
|
| 169 |
\sdaps_checkbox_set_type:V \l_sdaps_choicearray_type_tl |
| 170 |
\tl_if_eq:VnTF \l_sdaps_choicearray_type_tl { multichoice } { |
| 171 |
\tl_set:Nn \l_sdaps_choicearray_qobject_type_tl { Choice } |
| 172 |
} { |
| 173 |
\tl_set:Nn \l_sdaps_choicearray_qobject_type_tl { Option } |
| 174 |
} |
| 175 |
} |
| 176 |
\cs_generate_variant:Nn \_sdaps_choicearray_preprocess:n { V } |
| 177 |
|
| 178 |
\cs_new_protected_nopar:Npn \_sdaps_choicearray_process_choice_insert_tail_after:w { |
| 179 |
\bgroup |
| 180 |
\group_insert_after:N \_sdaps_choicearray_process_choice_tail: |
| 181 |
\sdaps_array_nested_alignenv: |
| 182 |
\tex_let:D\next= |
| 183 |
} |
| 184 |
|
| 185 |
\cs_new_protected_nopar:Nn \_sdaps_choicearray_process_choice_tail: { |
| 186 |
\ignorespaces |
| 187 |
} |
| 188 |
|
| 189 |
\cs_new_nopar:Nn \_sdaps_choicearray_grab_choice:n { |
| 190 |
\seq_gput_right:Nn \g_sdaps_choices_text_seq { #1 } |
| 191 |
\group_begin: |
| 192 |
\sdaps_array_nested_alignenv: |
| 193 |
#1 |
| 194 |
\group_end: |
| 195 |
\_sdaps_choicearray_process_choice_tail: |
| 196 |
} |
| 197 |
|
| 198 |
\cs_new_nopar:Npn \_sdaps_choicearray_process_choice:nw #1 |
| 199 |
{ |
| 200 |
% This modifies grouping so it has to be at the start |
| 201 |
\sdaps_array_alignment: |
| 202 |
\leavevmode |
| 203 |
|
| 204 |
\tl_clear:N \l_sdaps_choice_var_tl |
| 205 |
\tl_clear:N \l_sdaps_choice_val_tl |
| 206 |
\tl_clear:N \l_sdaps_choice_text_tl |
| 207 |
|
| 208 |
\keys_set:nn { sdaps / choicearray / choice } { #1 } |
| 209 |
|
| 210 |
\int_gincr:N \g_sdaps_choices_box_int |
| 211 |
|
| 212 |
\tl_if_empty:NT \l_sdaps_choice_var_tl { |
| 213 |
% Prefix with _ to force prefixing with generated variable |
| 214 |
\tl_set:Nx \l_sdaps_choice_var_tl { \int_use:N \g_sdaps_choices_box_int } |
| 215 |
} |
| 216 |
\tl_if_empty:NT \l_sdaps_choice_val_tl { |
| 217 |
\tl_set:Nx \l_sdaps_choice_val_tl { \int_use:N \g_sdaps_choices_box_int } |
| 218 |
} |
| 219 |
|
| 220 |
\tl_if_eq:VnTF \l_sdaps_choicearray_type_tl { multichoice } { |
| 221 |
\seq_gput_right:NV \g_sdaps_choices_filter_seq \l_sdaps_choice_var_tl |
| 222 |
} { |
| 223 |
\seq_gput_right:NV \g_sdaps_choices_filter_seq \l_sdaps_choice_val_tl |
| 224 |
} |
| 225 |
|
| 226 |
\seq_gput_right:Nx \g_sdaps_choices_cell_seq { \exp_not:n { \sdaps_checkbox:nn } { _ \l_sdaps_choice_var_tl } { \l_sdaps_choice_val_tl } } |
| 227 |
|
| 228 |
\tl_if_empty:NTF \l_sdaps_choice_text_tl { |
| 229 |
% We need to leave a command in the stream that grabs the next parameter |
| 230 |
% and outputs it immediately |
| 231 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_choicearray_grab_choice:n |
| 232 |
} { |
| 233 |
% Nothing else to do |
| 234 |
\seq_gput_right:NV \g_sdaps_choices_text_seq { \l_sdaps_choice_text_tl } |
| 235 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_choicearray_process_choice_insert_tail_after:w |
| 236 |
} |
| 237 |
\l_tmpa_token |
| 238 |
} |
| 239 |
\cs_generate_variant:Nn \_sdaps_choicearray_process_choice:nw { Vw } |
| 240 |
|
| 241 |
\cs_new_protected_nopar:Nn \_sdaps_choicearray_process_question_grab:n { |
| 242 |
\tl_set:Nn \l_sdaps_question_text_tl { #1 } |
| 243 |
|
| 244 |
\_sdaps_choicearray_process_question_head: |
| 245 |
|
| 246 |
\group_begin: |
| 247 |
\sdaps_array_nested_alignenv: |
| 248 |
#1 |
| 249 |
\group_end: |
| 250 |
|
| 251 |
\_sdaps_choicearray_process_question_tail: |
| 252 |
} |
| 253 |
|
| 254 |
\cs_new_protected_nopar:Npn \_sdaps_choicearray_process_question_inline:w { |
| 255 |
\_sdaps_choicearray_process_question_head: |
| 256 |
\bgroup |
| 257 |
\group_insert_after:N \_sdaps_choicearray_process_question_tail: |
| 258 |
\sdaps_array_nested_alignenv: |
| 259 |
\tex_let:D\next= |
| 260 |
} |
| 261 |
|
| 262 |
\cs_new_protected_nopar:Nn \_sdaps_choicearray_process_question_head: { |
| 263 |
\sdaps_qobject_begin:nnV { choicearray_question } \l_sdaps_choicearray_qobject_type_tl \l_sdaps_question_text_tl |
| 264 |
|
| 265 |
\tl_if_empty:NF \l_sdaps_question_var_tl { |
| 266 |
\sdaps_qobject_append_var:V \l_sdaps_question_var_tl |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
\cs_new_protected_nopar:Nn \_sdaps_choicearray_process_question_tail: { |
| 271 |
\seq_gclear:N \g_tmpa_seq |
| 272 |
% l_tmpa_bool is whether we are in a run (i.e. ...) |
| 273 |
\bool_set_false:N \l_tmpa_bool |
| 274 |
|
| 275 |
\clist_gset_eq:NN \g_tmpa_clist \l_sdaps_question_range_clist |
| 276 |
\clist_gpop:NN \g_tmpa_clist \l_tmpa_tl |
| 277 |
|
| 278 |
\seq_map_inline:Nn \g_sdaps_choices_filter_seq { |
| 279 |
\tl_if_eq:VnT \l_tmpa_tl { ... } { |
| 280 |
\bool_set_true:N \l_tmpa_bool |
| 281 |
\clist_gpop:NN \g_tmpa_clist \l_tmpa_tl |
| 282 |
} |
| 283 |
|
| 284 |
\tl_if_eq:VnTF \l_tmpa_tl { ##1 } { |
| 285 |
\seq_gput_right:Nn \g_tmpa_seq { \c_true_bool } |
| 286 |
\bool_set_false:N \l_tmpa_bool |
| 287 |
\clist_gpop:NN \g_tmpa_clist \l_tmpa_tl |
| 288 |
} { |
| 289 |
% Append if we are handling a run of items and the current item is not |
| 290 |
% the last one. |
| 291 |
\bool_if:NTF \l_tmpa_bool { |
| 292 |
\seq_gput_right:Nn \g_tmpa_seq { \c_true_bool } |
| 293 |
} { |
| 294 |
% Otherwise, ignore this item |
| 295 |
\seq_gput_right:Nn \g_tmpa_seq { \c_false_bool } |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
\seq_gset_eq:NN \g_tmpb_seq \g_tmpa_seq |
| 301 |
|
| 302 |
\seq_map_inline:Nn \g_sdaps_choices_text_seq { |
| 303 |
\seq_gpop_left:NN \g_tmpa_seq \l_tmpa_tl |
| 304 |
\tl_if_eq:VnT \l_tmpa_tl { \c_true_bool } { |
| 305 |
\sdaps_answer:f { ##1 } |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
\seq_map_inline:Nn \g_sdaps_choices_cell_seq { |
| 310 |
\sdaps_array_alignment: |
| 311 |
|
| 312 |
\seq_gpop_left:NN \g_tmpb_seq \l_tmpa_tl |
| 313 |
\tl_if_eq:VnT \l_tmpa_tl { \c_true_bool } { |
| 314 |
##1 |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
\sdaps_qobject_end:n { choicearray_question } |
| 319 |
\ignorespaces |
| 320 |
} |
| 321 |
|
| 322 |
\cs_new_nopar:Npn \_sdaps_choicearray_process_question:nw #1 |
| 323 |
{ |
| 324 |
\sdaps_array_newline: |
| 325 |
\leavevmode |
| 326 |
|
| 327 |
\keys_set:nn { sdaps / choicearray / question } { #1 } |
| 328 |
|
| 329 |
\tl_if_empty:NTF \l_sdaps_question_text_tl { |
| 330 |
% We need to leave a command in the stream that grabs the next parameter, |
| 331 |
% outputs it again, and finishes the question. |
| 332 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_choicearray_process_question_grab:n |
| 333 |
} { |
| 334 |
% Insert the question around the next argument |
| 335 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_choicearray_process_question_inline:w |
| 336 |
} |
| 337 |
\l_tmpa_token |
| 338 |
} |
| 339 |
\cs_generate_variant:Nn \_sdaps_choicearray_process_question:nw { Vw } |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
% |
| 344 |
% \end{macrocode} |
| 345 |
% |
| 346 |
% |
| 347 |
% \subsection{Range Question Layout} |
| 348 |
% |
| 349 |
% \subsubsection{Range Question Matrix Layout} |
| 350 |
% |
| 351 |
% The following macros provide the functionality to layout range/option |
| 352 |
% questions in a matrix like fashion. |
| 353 |
% |
| 354 |
% \begin{macrocode} |
| 355 |
|
| 356 |
|
| 357 |
\tl_new:N \l_sdaps_rangearray_align_tl |
| 358 |
\tl_new:N \l_sdaps_rangearray_extra_tl |
| 359 |
\int_new:N \l_sdaps_rangearray_rangecount_int |
| 360 |
\bool_new:N \l_sdaps_rangearray_other_bool |
| 361 |
\tl_new:N \g_sdaps_question_var_tl |
| 362 |
\tl_new:N \g_sdaps_question_text_tl |
| 363 |
\tl_new:N \g_sdaps_question_lowertext_tl |
| 364 |
\tl_new:N \g_sdaps_question_uppertext_tl |
| 365 |
\tl_new:N \g_sdaps_question_othertext_tl |
| 366 |
|
| 367 |
\msg_new:nnn { sdapslayout } { option_not_supported } { The~#1~option~is~not~supported~by~this~environment. } |
| 368 |
|
| 369 |
\keys_define:nn { sdaps / rangearray } |
| 370 |
{ |
| 371 |
count .int_set:N = \l_sdaps_rangearray_rangecount_int, |
| 372 |
count .initial:n = 5, |
| 373 |
align .tl_set:N = \l_sdaps_rangearray_align_tl, |
| 374 |
align .initial:n = { }, |
| 375 |
% Override and disallow flipping; it does not work currently |
| 376 |
flip .code:n = { \msg_error:nnn { sdapslayout } { option_not_supported } { flip } }, |
| 377 |
other .bool_set:N = \l_sdaps_rangearray_other_bool, |
| 378 |
other .default:n = true, |
| 379 |
other .initial:n = false, |
| 380 |
} |
| 381 |
|
| 382 |
\keys_define:nn { sdaps / rangearray / question } |
| 383 |
{ |
| 384 |
var .tl_gset:N = \g_sdaps_question_var_tl, |
| 385 |
text .tl_gset:N = \g_sdaps_question_text_tl, |
| 386 |
upper .tl_gset:N = \g_sdaps_question_uppertext_tl, |
| 387 |
lower .tl_gset:N = \g_sdaps_question_lowertext_tl, |
| 388 |
other .tl_gset:N = \g_sdaps_question_othertext_tl, |
| 389 |
} |
| 390 |
|
| 391 |
\cs_new_protected_nopar:Npn \_sdaps_rangearray_preprocess:n #1 |
| 392 |
{ |
| 393 |
\keys_set_known:nnN { sdaps / rangearray } { #1 } \l_sdaps_rangearray_extra_tl |
| 394 |
|
| 395 |
\sdaps_checkbox_set_type:n { singlechoice } |
| 396 |
} |
| 397 |
\cs_generate_variant:Nn \_sdaps_rangearray_preprocess:n { V } |
| 398 |
|
| 399 |
% Before/After the different parts |
| 400 |
|
| 401 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_before_question: { |
| 402 |
\sdaps_array_newline: |
| 403 |
% Note: This needs to be after sdaps_array_newline as the command may be |
| 404 |
% discarded otherwise (i.e. it does not make it into the output stream) |
| 405 |
% We also need to leave vmode here |
| 406 |
\leavevmode |
| 407 |
\sdaps_qobject_begin:nnV { rangearray_question } { Range } \g_sdaps_question_text_tl |
| 408 |
|
| 409 |
\tl_if_empty:NF \g_sdaps_question_var_tl { |
| 410 |
\sdaps_qobject_append_var:V \g_sdaps_question_var_tl |
| 411 |
} |
| 412 |
|
| 413 |
\ignorespaces |
| 414 |
} |
| 415 |
|
| 416 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_before_lower: { |
| 417 |
% right align |
| 418 |
\sdaps_array_alignment: |
| 419 |
\leavevmode |
| 420 |
\sdaps_range:nnV { lower } { 0 } \g_sdaps_question_lowertext_tl |
| 421 |
\sdaps_if_rtl:F { |
| 422 |
\hfill |
| 423 |
} |
| 424 |
\ignorespaces |
| 425 |
} |
| 426 |
|
| 427 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_before_upper: { |
| 428 |
\sdaps_array_alignment: |
| 429 |
\leavevmode |
| 430 |
\sdaps_range:nnV { upper } { \l_sdaps_rangearray_rangecount_int - 1 } \g_sdaps_question_uppertext_tl |
| 431 |
\sdaps_if_rtl:T { |
| 432 |
\hfill |
| 433 |
} |
| 434 |
\ignorespaces |
| 435 |
} |
| 436 |
|
| 437 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_before_other: { |
| 438 |
% Insert an extra empty column for further spacing |
| 439 |
\sdaps_array_alignment: |
| 440 |
\sdaps_array_alignment: |
| 441 |
\leavevmode |
| 442 |
\sdaps_answer:V \g_sdaps_question_othertext_tl |
| 443 |
\sdaps_if_rtl:TF { |
| 444 |
\hfill |
| 445 |
} { |
| 446 |
\sdaps_checkbox:nn { } { 0 } {} ~ {} |
| 447 |
} |
| 448 |
\ignorespaces |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_after_question: { |
| 454 |
% Insert an extra empty column for further spacing |
| 455 |
\sdaps_array_alignment: |
| 456 |
\tl_if_empty:NTF \g_sdaps_question_lowertext_tl { |
| 457 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_grab_lower:n |
| 458 |
} { |
| 459 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_inline_lower:w |
| 460 |
} |
| 461 |
\l_tmpa_token |
| 462 |
} |
| 463 |
|
| 464 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_after_lower: { |
| 465 |
% Insert the option checkbox column |
| 466 |
\sdaps_if_rtl:T { |
| 467 |
\hfill\kern 0pt |
| 468 |
} |
| 469 |
\sdaps_array_alignment: |
| 470 |
\leavevmode |
| 471 |
% Seems like right to left writing mode is not started without a paragraph |
| 472 |
\sdaps_if_rtl:T { \beginR } |
| 473 |
% Assume we have at least one checkbox |
| 474 |
\sdaps_checkbox:nn { } { 1 } |
| 475 |
\int_step_inline:nnnn { 2 } { 1 } { \l_sdaps_rangearray_rangecount_int } { |
| 476 |
\hspace{1em} \sdaps_checkbox:nn { } { ##1 } |
| 477 |
} |
| 478 |
\sdaps_if_rtl:T { \endR } |
| 479 |
|
| 480 |
\tl_if_empty:NTF \g_sdaps_question_uppertext_tl { |
| 481 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_grab_upper:n |
| 482 |
} { |
| 483 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_inline_upper:w |
| 484 |
} |
| 485 |
\l_tmpa_token |
| 486 |
} |
| 487 |
|
| 488 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_after_upper: { |
| 489 |
\sdaps_if_rtl:F { |
| 490 |
\hfill\kern 0pt |
| 491 |
} |
| 492 |
|
| 493 |
\bool_if:NTF \l_sdaps_rangearray_other_bool { |
| 494 |
\tl_if_empty:NTF \g_sdaps_question_othertext_tl { |
| 495 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_grab_other:n |
| 496 |
} { |
| 497 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_inline_other:w |
| 498 |
} |
| 499 |
} { |
| 500 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_finish: |
| 501 |
} |
| 502 |
\l_tmpa_token |
| 503 |
} |
| 504 |
|
| 505 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_after_other: { |
| 506 |
\sdaps_if_rtl:TF { |
| 507 |
{} ~ \sdaps_checkbox:nn { } { 0 } {} |
| 508 |
} { |
| 509 |
\hfill\kern 0pt |
| 510 |
} |
| 511 |
\ignorespaces |
| 512 |
} |
| 513 |
|
| 514 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_finish: { |
| 515 |
\sdaps_qobject_end:n { rangearray_question } |
| 516 |
\ignorespaces |
| 517 |
} |
| 518 |
|
| 519 |
% Processors for inline processing/grabbing the argument |
| 520 |
|
| 521 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_grab_question:n { |
| 522 |
\tl_gset:Nn \g_sdaps_question_text_tl { #1 } |
| 523 |
|
| 524 |
\_sdaps_rangearray_process_question_before_question: |
| 525 |
\group_begin: |
| 526 |
\sdaps_array_nested_alignenv: |
| 527 |
#1 |
| 528 |
\group_end: |
| 529 |
\_sdaps_rangearray_process_question_after_question: |
| 530 |
} |
| 531 |
|
| 532 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_grab_lower:n { |
| 533 |
\tl_gset:Nn \g_sdaps_question_lowertext_tl { #1 } |
| 534 |
|
| 535 |
\_sdaps_rangearray_process_question_before_lower: |
| 536 |
\group_begin: |
| 537 |
\sdaps_array_nested_alignenv: |
| 538 |
#1 |
| 539 |
\group_end: |
| 540 |
\_sdaps_rangearray_process_question_after_lower: |
| 541 |
} |
| 542 |
|
| 543 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_grab_upper:n { |
| 544 |
\tl_gset:Nn \g_sdaps_question_uppertext_tl { #1 } |
| 545 |
|
| 546 |
\_sdaps_rangearray_process_question_before_upper: |
| 547 |
\group_begin: |
| 548 |
\sdaps_array_nested_alignenv: |
| 549 |
#1 |
| 550 |
\group_end: |
| 551 |
\_sdaps_rangearray_process_question_after_upper: |
| 552 |
} |
| 553 |
|
| 554 |
\cs_new_protected_nopar:Nn \_sdaps_rangearray_process_question_grab_other:n { |
| 555 |
\tl_gset:Nn \g_sdaps_question_othertext_tl { #1 } |
| 556 |
|
| 557 |
% If the text is empty, assume that this particular question does not have |
| 558 |
% an alternative choice. Note that this column might not exist and this |
| 559 |
% macro will not even be called in that case. |
| 560 |
% If we skip the optional "other" option then we still need to insert the |
| 561 |
% alignment to create the column. |
| 562 |
\tl_if_empty:NTF \g_sdaps_question_othertext_tl { |
| 563 |
\sdaps_array_alignment: |
| 564 |
\leavevmode |
| 565 |
\ignorespaces |
| 566 |
} { |
| 567 |
\_sdaps_rangearray_process_question_before_other: |
| 568 |
\group_begin: |
| 569 |
\sdaps_array_nested_alignenv: |
| 570 |
#1 |
| 571 |
\group_end: |
| 572 |
\_sdaps_rangearray_process_question_after_other: |
| 573 |
} |
| 574 |
\_sdaps_rangearray_process_question_finish: |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
\cs_new_protected_nopar:Npn \_sdaps_rangearray_process_question_inline_question:w { |
| 580 |
\_sdaps_rangearray_process_question_before_question: |
| 581 |
\bgroup |
| 582 |
\group_insert_after:N \_sdaps_rangearray_process_question_after_question: |
| 583 |
\sdaps_array_nested_alignenv: |
| 584 |
\tex_let:D\next= |
| 585 |
} |
| 586 |
|
| 587 |
\cs_new_protected_nopar:Npn \_sdaps_rangearray_process_question_inline_lower:w { |
| 588 |
\_sdaps_rangearray_process_question_before_lower: |
| 589 |
\bgroup |
| 590 |
\group_insert_after:N \_sdaps_rangearray_process_question_after_lower: |
| 591 |
\tex_let:D\next= |
| 592 |
} |
| 593 |
|
| 594 |
\cs_new_protected_nopar:Npn \_sdaps_rangearray_process_question_inline_upper:w { |
| 595 |
\_sdaps_rangearray_process_question_before_upper: |
| 596 |
\bgroup |
| 597 |
\group_insert_after:N \_sdaps_rangearray_process_question_after_upper: |
| 598 |
\tex_let:D\next= |
| 599 |
} |
| 600 |
|
| 601 |
\cs_new_protected_nopar:Npn \_sdaps_rangearray_process_question_inline_other:w { |
| 602 |
\_sdaps_rangearray_process_question_before_other: |
| 603 |
% If we reach this macro then a text has been set for the other item. This |
| 604 |
% means we never need to ignore the "other" parameter at this point. |
| 605 |
\bgroup |
| 606 |
\group_insert_after:N \_sdaps_rangearray_process_question_after_other: |
| 607 |
\group_insert_after:N \_sdaps_rangearray_process_question_finish: |
| 608 |
\tex_let:D\next= |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
\cs_new_nopar:Npn \_sdaps_rangearray_process_question:nw #1 |
| 615 |
{ |
| 616 |
% Is there a better way other than clearing these before parsing? |
| 617 |
\tl_gclear:N \g_sdaps_question_var_tl |
| 618 |
\tl_gclear:N \g_sdaps_question_text_tl |
| 619 |
\tl_gclear:N \g_sdaps_question_uppertext_tl |
| 620 |
\tl_gclear:N \g_sdaps_question_lowertext_tl |
| 621 |
\tl_gclear:N \g_sdaps_question_othertext_tl |
| 622 |
|
| 623 |
\keys_set:nn { sdaps / rangearray / question } { #1 } |
| 624 |
|
| 625 |
\tl_if_empty:NTF \g_sdaps_question_text_tl { |
| 626 |
% We need to leave a command in the stream that grabs the next parameter, |
| 627 |
% outputs it again, and finishes the question. |
| 628 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_grab_question:n |
| 629 |
} { |
| 630 |
% We need to generate the question after the next group stops |
| 631 |
\cs_set_eq:NN \l_tmpa_token \_sdaps_rangearray_process_question_inline_question:w |
| 632 |
} |
| 633 |
\l_tmpa_token |
| 634 |
} |
| 635 |
\cs_generate_variant:Nn \_sdaps_rangearray_process_question:nw { Vw } |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
% |
| 640 |
% \end{macrocode} |
| 641 |
% |
| 642 |
% |
| 643 |
% |
| 644 |
% \subsection{Export user facing environments} |
| 645 |
% |
| 646 |
% \begin{macrocode} |
| 647 |
% |
| 648 |
|
| 649 |
|
| 650 |
\newenvironment { choicearray } [ 1 ] [] |
| 651 |
{ |
| 652 |
\group_begin: |
| 653 |
|
| 654 |
\sdaps_context_get:nN { choicearray } \l_tmpa_tl |
| 655 |
\tl_if_eq:NNT \l_tmpa_tl \q_no_value { |
| 656 |
\tl_set:Nn \l_tmpa_tl {} |
| 657 |
} |
| 658 |
|
| 659 |
\tl_if_empty:nF { #1 } { |
| 660 |
\tl_if_empty:NTF \l_tmpa_tl { |
| 661 |
\tl_set:Nn \l_tmpa_tl { #1 } |
| 662 |
} { |
| 663 |
\tl_set:Nf \l_tmpa_tl { \l_tmpa_tl, #1 } |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
\_sdaps_choicearray_preprocess:V \l_tmpa_tl |
| 668 |
% Clear the variables |
| 669 |
\seq_gclear:N \g_sdaps_choices_filter_seq |
| 670 |
\seq_gclear:N \g_sdaps_choices_cell_seq |
| 671 |
\seq_gclear:N \g_sdaps_choices_text_seq |
| 672 |
|
| 673 |
\int_gzero:N \g_sdaps_choices_box_int |
| 674 |
|
| 675 |
% Define new commands |
| 676 |
\newcommand \choice [ 1 ] [] { |
| 677 |
\_sdaps_choicearray_process_choice:nw { ##1 } |
| 678 |
} |
| 679 |
\newcommand \question [ 1 ] [] { |
| 680 |
\_sdaps_choicearray_process_question:nw { ##1 } |
| 681 |
} |
| 682 |
|
| 683 |
\group_begin: |
| 684 |
|
| 685 |
\tl_set:Nx \l_tmpb_tl {keepenv,layouter=\tl_use:N\l_sdaps_choicearray_layouter_tl,align=\l_sdaps_choicearray_align_tl\bool_if:NF\l_sdaps_choicearray_horizontal_bool{,flip},\l_sdaps_choicearray_extra_tl} |
| 686 |
\expandafter\sdapsarray\expandafter[\l_tmpb_tl] |
| 687 |
} |
| 688 |
{ |
| 689 |
\endsdapsarray |
| 690 |
\group_end: |
| 691 |
|
| 692 |
\group_end: |
| 693 |
} |
| 694 |
|
| 695 |
\newenvironment { optionarray } [ 1 ] [] |
| 696 |
{ |
| 697 |
\choicearray[singlechoice,#1] |
| 698 |
} |
| 699 |
{ |
| 700 |
\endchoicearray |
| 701 |
} |
| 702 |
|
| 703 |
\newenvironment { rangearray } [ 1 ] [] |
| 704 |
{ |
| 705 |
\group_begin: |
| 706 |
|
| 707 |
\sdaps_context_get:nN { rangearray } \l_tmpa_tl |
| 708 |
\tl_if_eq:NNT \l_tmpa_tl \q_no_value { |
| 709 |
\tl_set:Nn \l_tmpa_tl {} |
| 710 |
} |
| 711 |
|
| 712 |
\tl_if_empty:nF { #1 } { |
| 713 |
\tl_if_empty:NTF \l_tmpa_tl { |
| 714 |
\tl_set:Nn \l_tmpa_tl { #1 } |
| 715 |
} { |
| 716 |
\tl_set:Nf \l_tmpa_tl { \l_tmpa_tl, #1 } |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
\_sdaps_rangearray_preprocess:V \l_tmpa_tl |
| 721 |
|
| 722 |
\newcommand \range [ 1 ] [] { |
| 723 |
\_sdaps_rangearray_process_question:nw { ##1 } |
| 724 |
} |
| 725 |
|
| 726 |
\group_begin: |
| 727 |
|
| 728 |
\tl_set:Nx \l_tmpb_tl {keepenv,align=\l_sdaps_rangearray_align_tl,no_header,\l_sdaps_rangearray_extra_tl} |
| 729 |
\expandafter\sdapsarray\expandafter[\l_tmpb_tl] |
| 730 |
} |
| 731 |
{ |
| 732 |
\endsdapsarray |
| 733 |
\group_end: |
| 734 |
|
| 735 |
\group_end: |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
\ExplSyntaxOff |
| 740 |
|
| 741 |
% |
| 742 |
% \end{macrocode} |
| 743 |
% |
| 744 |
% \iffalse |
| 745 |
% \PrintChanges |
| 746 |
% \PrintIndex |
| 747 |
% \fi |
| 748 |
% |
| 749 |
% \Finale |
| 750 |
\endinput |