| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2019 by Benjamin Berg <[email protected]> |
| 4 |
% |
| 5 |
% This work may be distributed and/or modified under the |
| 6 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 7 |
% of this license or (at your option) any later version. |
| 8 |
% The latest version of this license is in |
| 9 |
% http://www.latex-project.org/lppl.txt |
| 10 |
% |
| 11 |
% This work has the LPPL maintenance status `maintained'. |
| 12 |
% |
| 13 |
% The Current Maintainer of this work is Benjamin Berg. |
| 14 |
% |
| 15 |
% \fi |
| 16 |
% |
| 17 |
% \iffalse |
| 18 |
%<*driver> |
| 19 |
\ProvidesFile{sdapsclassic.dtx} |
| 20 |
%</driver> |
| 21 |
%<class>\NeedsTeXFormat{LaTeX2e}[1999/12/01] |
| 22 |
%<class>\ProvidesClass{sdapsclassic} |
| 23 |
%<*class> |
| 24 |
[2015/08/02 v0.1 Initial version of SDAPS classic class] |
| 25 |
%</class> |
| 26 |
% |
| 27 |
%<*driver> |
| 28 |
\documentclass{ltxdoc} |
| 29 |
%\EnableCrossrefs |
| 30 |
\CodelineIndex |
| 31 |
\RecordChanges |
| 32 |
\begin{document} |
| 33 |
\DocInput{sdapsclassic.dtx} |
| 34 |
\end{document} |
| 35 |
%</driver> |
| 36 |
% \fi |
| 37 |
% |
| 38 |
% \CheckSum{0} |
| 39 |
% |
| 40 |
% \CharacterTable |
| 41 |
% {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 |
| 42 |
% 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 |
| 43 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 44 |
% Exclamation \! Double quote \" Hash (number) \# |
| 45 |
% Dollar \$ Percent \% Ampersand \& |
| 46 |
% Acute accent \' Left paren \( Right paren \) |
| 47 |
% Asterisk \* Plus \+ Comma \, |
| 48 |
% Minus \- Point \. Solidus \/ |
| 49 |
% Colon \: Semicolon \; Less than \< |
| 50 |
% Equals \= Greater than \> Question mark \? |
| 51 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 52 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 53 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 54 |
% Right brace \} Tilde \~} |
| 55 |
% |
| 56 |
% |
| 57 |
% \changes{v0.1}{2015/01/14}{Initial version} |
| 58 |
% |
| 59 |
% \GetFileInfo{sdapsclassic.dtx} |
| 60 |
% |
| 61 |
% \DoNotIndex{\newcommand,\newenvironment} |
| 62 |
% |
| 63 |
% |
| 64 |
% \title{The \textsf{sdapsclassic} package\thanks{This document |
| 65 |
% corresponds to \textsf{sdapsclassic}~\fileversion, dated \filedate.}} |
| 66 |
% \author{Benjamin Berg \\ \texttt{[email protected]}} |
| 67 |
% |
| 68 |
% \maketitle |
| 69 |
% |
| 70 |
% \section{Documentation} |
| 71 |
% |
| 72 |
% Please refer to \url{https://sdaps.org/class-doc} for documentation. |
| 73 |
% |
| 74 |
% \StopEventually{\PrintChanges\PrintIndex} |
| 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 |
|
| 85 |
\RequirePackage{sdapsbase} |
| 86 |
\RequirePackage{sdapslayout} |
| 87 |
|
| 88 |
% We use verbatim to grab the content of the questionnaire envorinment into a |
| 89 |
% temporary file. This way we can input it multiple times for repeating the |
| 90 |
% the content. |
| 91 |
|
| 92 |
\RequirePackage{verbatim} |
| 93 |
|
| 94 |
|
| 95 |
% \end{macrocode} |
| 96 |
% Now a lot of LaTeX 2e stuff that is basically just a copy of the old class. |
| 97 |
% Would be nicer to redo this with xparse, but what the heck. |
| 98 |
% \begin{macrocode} |
| 99 |
|
| 100 |
\RequirePackage{scrkbase} |
| 101 |
|
| 102 |
|
| 103 |
%------------------------------------------------------------------------------- |
| 104 |
% option processing |
| 105 |
%------------------------------------------------------------------------------- |
| 106 |
|
| 107 |
% Whether the main SDAPS program will be used |
| 108 |
\DeclareOption{disable_recognition}{\bool_gset_false:N\g_sdaps_recognition_bool} |
| 109 |
|
| 110 |
% Whether sdaps should print the questionnaire id |
| 111 |
\DeclareOption{no_print_questionnaire_id}{\bool_gset_false:N\g_sdaps_print_questionnaire_id_bool\seq_gset_from_clist:Nn \g_sdaps_questionnaire_ids_seq {{}}} |
| 112 |
\DeclareOption{print_questionnaire_id}{\bool_gset_true:N\g_sdaps_print_questionnaire_id_bool\seq_gset_from_clist:Nn \g_sdaps_questionnaire_ids_seq {{NONE}}} |
| 113 |
|
| 114 |
% pass unknown options to scrartcl |
| 115 |
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}} |
| 116 |
|
| 117 |
% We need this if right now as it is set by sdaps.opt. |
| 118 |
\newif\if@sdaps@draft\@sdaps@drafttrue |
| 119 |
\DeclareOption{final}{\@sdaps@draftfalse} |
| 120 |
|
| 121 |
\tl_gset:Nn\g_sdaps_style_tl{qr}% |
| 122 |
|
| 123 |
|
| 124 |
\DefineFamily{SDAPS} |
| 125 |
\DefineFamilyMember{SDAPS} |
| 126 |
\DefineFamilyKey{SDAPS}{sdaps_style}[qr]% |
| 127 |
{% |
| 128 |
\KOMA@set@ncmdkey{sdaps_style}{@tempa}{% |
| 129 |
{code128}{0},% |
| 130 |
{custom}{1},% |
| 131 |
{qr}{2}% |
| 132 |
}{#1}% |
| 133 |
\ifcase \@tempa\relax |
| 134 |
\tl_gset:Nn\g_sdaps_style_tl{code128}% |
| 135 |
\or |
| 136 |
\tl_gset:Nn\g_sdaps_style_tl{custom}% |
| 137 |
\or |
| 138 |
\tl_gset:Nn\g_sdaps_style_tl{qr}% |
| 139 |
\fi |
| 140 |
} |
| 141 |
|
| 142 |
\DefineFamilyKey{SDAPS}{twoside_barcode}[both]% |
| 143 |
{% |
| 144 |
\KOMA@set@ncmdkey{twoside_barcode}{@tempa}{% |
| 145 |
{both}{0},% |
| 146 |
{front}{1},% |
| 147 |
{back}{2}% |
| 148 |
}{#1}% |
| 149 |
\ifcase \@tempa\relax |
| 150 |
\tl_gset:Nn\g_sdaps_twoside_barcode_tl{both}% |
| 151 |
\or |
| 152 |
\tl_gset:Nn\g_sdaps_twoside_barcode_tl{front}% |
| 153 |
\or |
| 154 |
\tl_gset:Nn\g_sdaps_twoside_barcode_tl{back}% |
| 155 |
\fi |
| 156 |
} |
| 157 |
|
| 158 |
\DefineFamilyKey{SDAPS}{checkmode}[checkcorrect]% |
| 159 |
{% |
| 160 |
\KOMA@set@ncmdkey{checkmode}{@tempa}{% |
| 161 |
{checkcorrect}{0},% |
| 162 |
{check}{1},% |
| 163 |
{fill}{2}% |
| 164 |
}{#1}% |
| 165 |
\ifcase \@tempa\relax |
| 166 |
\tl_gset:Nn\g_sdaps_checkmode_tl{checkcorrect}% |
| 167 |
\or |
| 168 |
\tl_gset:Nn\g_sdaps_checkmode_tl{check}% |
| 169 |
\or |
| 170 |
\tl_gset:Nn\g_sdaps_checkmode_tl{fill}% |
| 171 |
\fi |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
\DefineFamilyKey{SDAPS}{globalid}[] |
| 176 |
{ |
| 177 |
\tl_gset:Nn \g_sdaps_global_id_tl { #1 } |
| 178 |
} |
| 179 |
|
| 180 |
\DefineFamilyKey{SDAPS}{globalidlabel}[] |
| 181 |
{ |
| 182 |
\tl_gset:Nn \g_sdaps_global_id_label_tl { #1 } |
| 183 |
} |
| 184 |
|
| 185 |
% Set default options for scrartcl. Is this done correctly? |
| 186 |
\PassOptionsToClass{headings=small}{scrartcl} |
| 187 |
\PassOptionsToClass{twoside}{scrartcl} |
| 188 |
% Well, I don't think that this worked in the past ... |
| 189 |
%\PassOptionsToClass{10pt}{scrartcl} |
| 190 |
|
| 191 |
\seq_new:N \g_sdaps_questionnaire_ids_seq |
| 192 |
\seq_gset_from_clist:Nn \g_sdaps_questionnaire_ids_seq {{}} |
| 193 |
|
| 194 |
% process given options |
| 195 |
\FamilyProcessOptions{SDAPS}\relax |
| 196 |
|
| 197 |
%------------------------------------------------------------------------------- |
| 198 |
% load base-class |
| 199 |
%------------------------------------------------------------------------------- |
| 200 |
\LoadClass{scrartcl} |
| 201 |
|
| 202 |
|
| 203 |
%------------------------------------------------------------------------------- |
| 204 |
% required packages |
| 205 |
%------------------------------------------------------------------------------- |
| 206 |
% geometry package |
| 207 |
\RequirePackage{geometry} |
| 208 |
% Corner mark postions plus 2mm, except for the header |
| 209 |
\geometry{top=12mm} |
| 210 |
\geometry{bottom=14mm} |
| 211 |
\geometry{hmargin=12mm} |
| 212 |
\geometry{includeheadfoot} |
| 213 |
\geometry{headheight=\baselineskip} |
| 214 |
\geometry{headsep=\baselineskip} |
| 215 |
% QR code size plus 2mm |
| 216 |
\geometry{footskip=12mm} |
| 217 |
|
| 218 |
% ifthen package |
| 219 |
\RequirePackage{ifthen} |
| 220 |
|
| 221 |
% fontenc package |
| 222 |
\RequirePackage[T1]{fontenc} |
| 223 |
|
| 224 |
% color |
| 225 |
\RequirePackage{color} |
| 226 |
|
| 227 |
% Symbols (boxes) |
| 228 |
\RequirePackage{amssymb} |
| 229 |
|
| 230 |
% For writing out the page number of boxes |
| 231 |
\RequirePackage{refcount} |
| 232 |
|
| 233 |
% Defines the LastPage label |
| 234 |
\RequirePackage{lastpage} |
| 235 |
|
| 236 |
% Environment creation that gets the body as a macro |
| 237 |
\RequirePackage{environ} |
| 238 |
|
| 239 |
% headers and footers |
| 240 |
\usepackage{scrlayer-scrpage} |
| 241 |
\clearpairofpagestyles |
| 242 |
\chead*{\@title} |
| 243 |
\cfoot*{\sdapspagemark} |
| 244 |
|
| 245 |
% hyperrefs |
| 246 |
\RequirePackage{url} |
| 247 |
\RequirePackage{hyperref} |
| 248 |
\hypersetup{% |
| 249 |
breaklinks,% |
| 250 |
baseurl = http://,% |
| 251 |
pdfborder = 0 0 0,% |
| 252 |
pdfpagemode = UseNone,% |
| 253 |
pdfcreator = \LaTeX{} with `sdaps' class,% |
| 254 |
pdfproducer = \LaTeX{} |
| 255 |
} |
| 256 |
|
| 257 |
% graphics |
| 258 |
\RequirePackage{graphicx} |
| 259 |
|
| 260 |
% Section formatting |
| 261 |
\RequirePackage{sectsty} |
| 262 |
|
| 263 |
% table of fixed width |
| 264 |
\RequirePackage{tabularx} |
| 265 |
|
| 266 |
% Babel (needed for the translator) |
| 267 |
\RequirePackage{babel} |
| 268 |
|
| 269 |
% Translation |
| 270 |
\RequirePackage{translator} |
| 271 |
\usedictionary{translator-sdaps-dictionary} |
| 272 |
|
| 273 |
|
| 274 |
% Execute sdaps.opt file to allow SDAPS to override any options |
| 275 |
\InputIfFileExists{sdaps.opt}{}{} |
| 276 |
|
| 277 |
|
| 278 |
%------------------------------------------------------------------------------- |
| 279 |
% class definition |
| 280 |
%------------------------------------------------------------------------------- |
| 281 |
% minimal base settings |
| 282 |
|
| 283 |
\setlength\lineskip{1\p@} |
| 284 |
\setlength\normallineskip{1\p@} |
| 285 |
\renewcommand\baselinestretch{} |
| 286 |
\setlength{\parindent}{0pt} |
| 287 |
\setlength{\parskip}{1.0ex \@plus 1.5ex \@minus -0.25ex} |
| 288 |
%\setlength{\parskip}{0pt} |
| 289 |
\setlength\columnsep{10\p@} |
| 290 |
\setlength\columnseprule{0\p@} |
| 291 |
% Redefine the spacings for \subsection ie. \_sdaps_classic_question. |
| 292 |
\renewcommand\section{\@startsection {section}{1}{\z@}% |
| 293 |
{-\parskip}% |
| 294 |
{\parskip}% |
| 295 |
{\normalfont\Large\bfseries\SS@sectfont}} |
| 296 |
\renewcommand\subsection{ |
| 297 |
\@startsection{subsection}{2}{\z@}% |
| 298 |
{0.5\parskip}% |
| 299 |
{0.25\parskip}% These are deleted again for questions |
| 300 |
{}% |
| 301 |
} |
| 302 |
\pagestyle{scrheadings} |
| 303 |
\pagenumbering{arabic} |
| 304 |
\raggedbottom |
| 305 |
%\flushbottom |
| 306 |
\onecolumn |
| 307 |
|
| 308 |
% |
| 309 |
% Fonts for the "classic" class |
| 310 |
% |
| 311 |
|
| 312 |
%common font settings |
| 313 |
\newkomafont{questionfont}{} |
| 314 |
\newkomafont{choicefont}{} |
| 315 |
%singlemark |
| 316 |
\newkomafont{singlemarkquestionfont}{\usekomafont{questionfont}} |
| 317 |
\newkomafont{singlemarkchoicefont}{\usekomafont{choicefont}} |
| 318 |
%markgroup |
| 319 |
\newkomafont{marklinequestionfont}{\usekomafont{questionfont}} |
| 320 |
\newkomafont{marklinechoicefont}{\usekomafont{choicefont}} |
| 321 |
%choicequestion |
| 322 |
\newkomafont{choiceitemfont}{\usekomafont{choicefont}} |
| 323 |
%choicegroup |
| 324 |
\newkomafont{choicegroupchoicefont}{\usekomafont{questionfont}} |
| 325 |
\newkomafont{choicegrouplinefont}{\usekomafont{choicefont}} |
| 326 |
|
| 327 |
|
| 328 |
% \end{macrocode} |
| 329 |
% |
| 330 |
% \subsection{A bunch of old commands} |
| 331 |
% |
| 332 |
% |
| 333 |
% \begin{macrocode} |
| 334 |
|
| 335 |
|
| 336 |
\providecommand{\addinfo}[2]{ |
| 337 |
\sdaps_info_write:x{Info-\unexpanded{#1}=\unexpanded{#2}} |
| 338 |
} |
| 339 |
|
| 340 |
\newcommand\qid{\tl_use:N \g__sdaps_questionnaire_id_tl} |
| 341 |
|
| 342 |
\def\_sdaps_classic_question#1{% |
| 343 |
\tl_if_empty:nTF{#1}{ |
| 344 |
\refstepcounter{subsection}% |
| 345 |
\par% |
| 346 |
} { |
| 347 |
% #1 is nonempty |
| 348 |
\subsection{\usekomafont{questionfont}\strut\ignorespaces#1}% |
| 349 |
% This is extra spacing after the subsection is removed. By doing this we |
| 350 |
% get exactly one \parskip |
| 351 |
\nobreak% |
| 352 |
\vspace{-0.25\parskip}% |
| 353 |
\nobreak% |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
\newenvironment{info}{% |
| 358 |
\group_begin: |
| 359 |
{ |
| 360 |
\par |
| 361 |
% Prevent top skip glue from being inserted at the start of the page |
| 362 |
\topskip=0pt |
| 363 |
\noindent\hrule height 1pt% |
| 364 |
\nobreak |
| 365 |
\vspace{-\parskip} |
| 366 |
\nobreak |
| 367 |
\vspace{0.5ex} |
| 368 |
\nobreak |
| 369 |
} |
| 370 |
}{% |
| 371 |
\par |
| 372 |
\nobreak |
| 373 |
\vspace{-\parskip} |
| 374 |
\nobreak |
| 375 |
\vspace{0.5ex} |
| 376 |
\nobreak |
| 377 |
\noindent\hrule height 1pt |
| 378 |
\group_end: |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
\definecolor{sectionbgcolor}{gray}{0.8} |
| 383 |
\definecolor{sectionfgcolor}{gray}{0.0} |
| 384 |
|
| 385 |
\newcommand{\sectbox}[1]{% |
| 386 |
\noindent\protect\colorbox{sectionbgcolor}{% |
| 387 |
\@tempdima=\hsize |
| 388 |
\advance\@tempdima by-2\fboxsep |
| 389 |
\protect\parbox{\@tempdima}{% |
| 390 |
\smallskip |
| 391 |
\raggedright % extra commands here |
| 392 |
\color{sectionfgcolor}\usekomafont{section}{#1} \smallskip |
| 393 |
}% |
| 394 |
}% |
| 395 |
} |
| 396 |
|
| 397 |
\sectionfont{\sectbox} |
| 398 |
|
| 399 |
\setkomafont{disposition}{\normalfont} |
| 400 |
\addtokomafont{section}{\bfseries\sffamily} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
% Not sure why we even had this ... |
| 407 |
\def\smallskip{\vspace\smallskipamount} |
| 408 |
\def\medskip{\vspace\medskipamount} |
| 409 |
\def\bigskip{\vspace\bigskipamount} |
| 410 |
\newskip\smallskipamount \smallskipamount=3pt plus 1pt minus 1pt |
| 411 |
\newskip\medskipamount \medskipamount =6pt plus 2pt minus 2pt |
| 412 |
\newskip\bigskipamount \bigskipamount =12pt plus 4pt minus 4pt |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
\cs_generate_variant:Nn \sdaps_textbox_hstretch:nnnnn { nVVnn } |
| 417 |
\cs_generate_variant:Nn \sdaps_textbox_hstretch:nnnnn { VVVnn } |
| 418 |
\cs_generate_variant:Nn \int_set:Nn { NV } |
| 419 |
|
| 420 |
|
| 421 |
% \end{macrocode} |
| 422 |
% |
| 423 |
% \subsection{The different question environments} |
| 424 |
% |
| 425 |
% |
| 426 |
% \begin{macrocode} |
| 427 |
|
| 428 |
|
| 429 |
\bool_new:N \g__sdaps_classic_have_section |
| 430 |
\bool_gset_false:N \g__sdaps_classic_have_section |
| 431 |
\cs_new_eq:NN\_sdapsclassic_origsection\section |
| 432 |
\renewcommand{\section}[1]{ |
| 433 |
\bool_if:NT \g__sdaps_classic_have_section { |
| 434 |
\sdaps_qobject_end:n { section } |
| 435 |
} |
| 436 |
|
| 437 |
\_sdapsclassic_origsection{#1} |
| 438 |
\bool_gset_true:N \g__sdaps_classic_have_section |
| 439 |
\sdaps_qobject_begin:nnn { section }{ Head }{ #1 } |
| 440 |
} |
| 441 |
|
| 442 |
\cs_new_protected_nopar:Nn \sdaps_classic_ensure_section: { |
| 443 |
\bool_if:NF \g__sdaps_classic_have_section { |
| 444 |
% This is a bad hack to make the numbering start with zero |
| 445 |
\int_gdecr:N \g__sdaps_object_id_int |
| 446 |
\bool_gset_true:N \g__sdaps_classic_have_section |
| 447 |
\sdaps_qobject_begin:nnn { section }{ Head }{ } |
| 448 |
\sdaps_context_hook_end:n { \bool_gset_false:N \g__sdaps_classic_have_section } |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
\tl_new:N \l_sdaps_classic_textbox_var_tl |
| 454 |
\tl_new:N \l_sdaps_classic_textbox_text_tl |
| 455 |
\keys_define:nn { sdapsclassic / textbox } |
| 456 |
{ |
| 457 |
var .tl_set:N = \l_sdaps_classic_textbox_var_tl, |
| 458 |
text .tl_set:N = \l_sdaps_classic_textbox_text_tl, |
| 459 |
} |
| 460 |
|
| 461 |
% With star non-expanding, without start expanding |
| 462 |
\providecommand{\textbox}{\@ifstar |
| 463 |
{\bool_set_false:N \l_tmpa_bool \_sdaps_classic_textbox } |
| 464 |
{\bool_set_true:N \l_tmpa_bool \_sdaps_classic_textbox } |
| 465 |
} |
| 466 |
|
| 467 |
\providecommand{\_sdaps_classic_textbox}[3][] |
| 468 |
{ |
| 469 |
\keys_set:nn { sdapsclassic / textbox } { #1 } |
| 470 |
|
| 471 |
\sdaps_classic_ensure_section: |
| 472 |
\_sdaps_classic_question{#3} |
| 473 |
|
| 474 |
\tl_if_empty:NTF \l_sdaps_classic_textbox_text_tl { |
| 475 |
\sdaps_qobject_begin:nnn { textbox } { Text } { #3 } |
| 476 |
} { |
| 477 |
\sdaps_qobject_begin:nnV { textbox } { Text } \l_sdaps_classic_textbox_text_tl |
| 478 |
} |
| 479 |
|
| 480 |
\bool_if:NTF \l_tmpa_bool { |
| 481 |
\sdaps_textbox_vhstretch:Vnn \l_sdaps_classic_textbox_var_tl { #2 } { 1 } |
| 482 |
}{ |
| 483 |
\sdaps_textbox_vhstretch:Vnn \l_sdaps_classic_textbox_var_tl { #2 } { 0 } |
| 484 |
} |
| 485 |
|
| 486 |
\sdaps_qobject_end:n { textbox } |
| 487 |
} |
| 488 |
|
| 489 |
\newcounter{markcheckboxcount} |
| 490 |
\setcounter{markcheckboxcount}{5} |
| 491 |
|
| 492 |
|
| 493 |
\tl_new:N \l_sdaps_singlemark_var_tl |
| 494 |
\int_new:N \l_sdaps_singlemark_count_int |
| 495 |
|
| 496 |
\keys_define:nn { sdaps / singlemark } |
| 497 |
{ |
| 498 |
var .tl_set:N = \l_sdaps_singlemark_var_tl, |
| 499 |
|
| 500 |
% 0 is equivalent to using the markcheckboxcount counter |
| 501 |
count .int_set:N = \l_sdaps_singlemark_count_int, |
| 502 |
count .initial:n = 0, |
| 503 |
} |
| 504 |
|
| 505 |
\cs_new_protected_nopar:Nn \_sdaps_classic_dummy_checkbox_prepare:NN |
| 506 |
{ |
| 507 |
\group_begin: |
| 508 |
\sdaps_context_begin_local: |
| 509 |
\sdaps_context_disable_writing: |
| 510 |
\bool_if:NT #1 { |
| 511 |
\sdaps_context_append:nn { singlechoice } { draw_check=true } |
| 512 |
\sdaps_context_append:nn { multichoice } { draw_check=true } |
| 513 |
} |
| 514 |
\bool_if:NT #2 { |
| 515 |
\sdaps_context_append:nn { singlechoice } { fill=black } |
| 516 |
\sdaps_context_append:nn { multichoice } { fill=black } |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
\cs_new_protected_nopar:Nn \_sdaps_classic_dummy_checkbox_single: |
| 521 |
{ |
| 522 |
\sdaps_checkbox_set_type:n { singlechoice } |
| 523 |
\sdaps_checkbox:nn { } { } |
| 524 |
\group_end: |
| 525 |
\ignorespaces |
| 526 |
} |
| 527 |
|
| 528 |
\cs_new_protected_nopar:Nn \_sdaps_classic_dummy_checkbox_multi: |
| 529 |
{ |
| 530 |
\sdaps_checkbox_set_type:n { multichoice } |
| 531 |
\sdaps_checkbox:nn { } { } |
| 532 |
\group_end: |
| 533 |
\ignorespaces |
| 534 |
} |
| 535 |
|
| 536 |
\providecommand{\checkbox}{ |
| 537 |
\_sdaps_classic_dummy_checkbox_prepare:NN \c_false_bool \c_false_bool |
| 538 |
\@ifstar |
| 539 |
\_sdaps_classic_dummy_checkbox_single: |
| 540 |
\_sdaps_classic_dummy_checkbox_multi: |
| 541 |
} |
| 542 |
\providecommand{\checkedbox}{% |
| 543 |
\_sdaps_classic_dummy_checkbox_prepare:NN \c_true_bool \c_false_bool |
| 544 |
\@ifstar |
| 545 |
\_sdaps_classic_dummy_checkbox_single: |
| 546 |
\_sdaps_classic_dummy_checkbox_multi: |
| 547 |
} |
| 548 |
\providecommand{\filledbox}{% |
| 549 |
\_sdaps_classic_dummy_checkbox_prepare:NN \c_false_bool \c_true_bool |
| 550 |
\@ifstar |
| 551 |
\_sdaps_classic_dummy_checkbox_single: |
| 552 |
\_sdaps_classic_dummy_checkbox_multi: |
| 553 |
} |
| 554 |
\providecommand{\correctedbox}{% |
| 555 |
\_sdaps_classic_dummy_checkbox_prepare:NN \c_true_bool \c_true_bool |
| 556 |
\@ifstar |
| 557 |
\_sdaps_classic_dummy_checkbox_single: |
| 558 |
\_sdaps_classic_dummy_checkbox_multi: |
| 559 |
} |
| 560 |
|
| 561 |
\providecommand*{\singlemark}[4][]{% |
| 562 |
\sdaps_classic_ensure_section: |
| 563 |
|
| 564 |
\group_begin: |
| 565 |
|
| 566 |
\keys_set:nn { sdaps / singlemark } { #1 } |
| 567 |
|
| 568 |
\int_compare:nNnT { \l_sdaps_singlemark_count_int } = { 0 } { |
| 569 |
\int_set:Nn \l_sdaps_singlemark_count_int { \themarkcheckboxcount } |
| 570 |
} |
| 571 |
|
| 572 |
\_sdaps_classic_question{#2}% |
| 573 |
|
| 574 |
\sdaps_qobject_begin:nnn { singlemark } { range } { #2 } |
| 575 |
|
| 576 |
\sdaps_checkbox_set_type:n { singlechoice } |
| 577 |
|
| 578 |
\tl_if_empty:NF \l_sdaps_singlemark_var_tl { |
| 579 |
\sdaps_qobject_append_var:V \l_sdaps_singlemark_var_tl |
| 580 |
} |
| 581 |
|
| 582 |
\sdaps_range:nnn{lower}{0}{#3} |
| 583 |
\sdaps_range:nnn{upper}{\int_use:N\l_sdaps_singlemark_count_int-1}{#4} |
| 584 |
|
| 585 |
\begin{tabularx}{\linewidth}{X*{\int_use:N\l_sdaps_singlemark_count_int}{c}X} |
| 586 |
{\hfill\usekomafont{singlemarkchoicefont}\strut\ignorespaces#3} & |
| 587 |
\int_step_inline:nnnn { 1 } { 1 } { \int_use:N\l_sdaps_singlemark_count_int } { \sdaps_checkbox:nn { _ ##1 } { ##1 } & } |
| 588 |
{\usekomafont{singlemarkchoicefont}#4\hfill}\\% |
| 589 |
\end{tabularx}% |
| 590 |
|
| 591 |
\sdaps_qobject_end:n { singlemark } |
| 592 |
\group_end: |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
\providecommand*{\singlemarkother}[5][]{% |
| 597 |
\sdaps_classic_ensure_section: |
| 598 |
|
| 599 |
\group_begin: |
| 600 |
|
| 601 |
\keys_set:nn { sdaps / singlemark } { #1 } |
| 602 |
|
| 603 |
\int_compare:nNnT { \l_sdaps_singlemark_count_int } = { 0 } { |
| 604 |
\int_set:Nn \l_sdaps_singlemark_count_int { \themarkcheckboxcount } |
| 605 |
} |
| 606 |
|
| 607 |
\_sdaps_classic_question{#2}% |
| 608 |
|
| 609 |
\sdaps_qobject_begin:nnn { singlemark } { range } { #2 } |
| 610 |
|
| 611 |
\sdaps_checkbox_set_type:n { singlechoice } |
| 612 |
|
| 613 |
\tl_if_empty:NF \l_sdaps_singlemark_var_tl { |
| 614 |
\sdaps_qobject_append_var:V \l_sdaps_singlemark_var_tl |
| 615 |
} |
| 616 |
|
| 617 |
\sdaps_range:nnn{lower}{0}{#3} |
| 618 |
\sdaps_range:nnn{upper}{\int_use:N\l_sdaps_singlemark_count_int-1}{#4} |
| 619 |
\sdaps_answer:n{#5} |
| 620 |
|
| 621 |
\begin{tabularx}{\linewidth}{X*{\int_use:N\l_sdaps_singlemark_count_int}{c}XX} |
| 622 |
{\hfill\usekomafont{singlemarkchoicefont}\strut\ignorespaces#3} & |
| 623 |
\int_step_inline:nnnn { 1 } { 1 } { \int_use:N\l_sdaps_singlemark_count_int } { \sdaps_checkbox:nn { _ ##1 } { ##1 } & } |
| 624 |
{\usekomafont{singlemarkchoicefont}#4} & |
| 625 |
{\usekomafont{singlemarkchoicefont}\sdaps_checkbox:nn { _0 } { 0 } {} ~ #5\hfill}\\% |
| 626 |
\end{tabularx}% |
| 627 |
|
| 628 |
\sdaps_qobject_end:n { singlemark } |
| 629 |
\group_end: |
| 630 |
} |
| 631 |
|
| 632 |
\dim_new:N \l__sdaps_classic_choiceitem_pad_dim |
| 633 |
\int_new:N \l__sdaps_classic_choiceitem_cols_int |
| 634 |
\int_new:N \l__sdaps_classic_choiceitem_col_int |
| 635 |
\dim_new:N \l__sdaps_classic_choicequestion_prevdepth_dim |
| 636 |
\coffin_new:N \l__sdaps_classic_choicequestion_coffin |
| 637 |
|
| 638 |
\msg_new:nnn { sdapsclassic } { choicequestion_wrong_mode } { Mode~should~always~be~vertical~inside~a~choicequestion.\\ This~likely~means~that~the~choicequestion~contains~content~other~than~one~of~the~permissable~macros. } |
| 639 |
|
| 640 |
\msg_new:nnn { sdapsclassic } { choicequestion_no_text } { Textboxes~cannot~be~used~in~singlechoice~questions.\\ |
| 641 |
It~is~currently~not~supported~to~use~text~answers~in~single~choice~questions.~Until~support~is~added~ |
| 642 |
you~can~get~similar~results~by~temporarily~changing~the~checkbox~style. } |
| 643 |
|
| 644 |
\msg_new:nnn { sdapsclassic } { choicequestion_unknown_key } { The~key~'#1'~is~unknown.\\If~you~are~migrating~from~the~old~class~then~you~need~to~add~'cols='~to~specify~the~number~of~columns. } |
| 645 |
|
| 646 |
\tl_new:N \l_sdaps_choicquestion_type_tl |
| 647 |
\tl_new:N \l_sdaps_choicequestion_var_tl |
| 648 |
\tl_new:N \l_sdaps_choicequestion_text_tl |
| 649 |
\int_new:N \l_sdaps_choicequestion_cols_int |
| 650 |
|
| 651 |
\keys_define:nn { sdaps / choicequestion } |
| 652 |
{ |
| 653 |
var .tl_set:N = \l_sdaps_choicequestion_var_tl, |
| 654 |
text .tl_set:N = \l_sdaps_choicequestion_text_tl, |
| 655 |
colsep .dim_set:N = \l_sdaps_choicequestion_colsep_dim, |
| 656 |
colsep .initial:n = 6pt, |
| 657 |
rowsep .dim_set:N = \l_sdaps_choicequestion_rowsep_dim, |
| 658 |
rowsep .initial:n = 0pt, |
| 659 |
cols .int_set:N = \l_sdaps_choicequestion_cols_int, |
| 660 |
cols .initial:n = 3, |
| 661 |
|
| 662 |
type .choices:nn = { multichoice, singlechoice } { \tl_set:Nx \l_sdaps_choicquestion_type_tl { \l_keys_choice_tl } }, |
| 663 |
type .initial:n = { multichoice }, |
| 664 |
|
| 665 |
singlechoice .meta:n = { type=singlechoice }, |
| 666 |
multichoice .meta:n = { type=multichoice }, |
| 667 |
|
| 668 |
unknown .code:n = \msg_error:nnV { sdapsclassic } { choicequestion_unknown_key } \l_keys_key_tl |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
\tl_new:N \l_sdaps_choicequestion_choice_var_tl |
| 673 |
\tl_new:N \l_sdaps_choicequestion_choice_val_tl |
| 674 |
\tl_new:N \l_sdaps_choicequestion_choice_text_tl |
| 675 |
|
| 676 |
\keys_define:nn { sdaps / choicequestion / choice } |
| 677 |
{ |
| 678 |
var .tl_set:N = \l_sdaps_choicequestion_choice_var_tl, |
| 679 |
val .tl_set:N = \l_sdaps_choicequestion_choice_val_tl, |
| 680 |
text .tl_set:N = \l_sdaps_choicequestion_choice_text_tl, |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
\newenvironment{choicequestion}[2][]{ |
| 685 |
\group_begin: |
| 686 |
|
| 687 |
\sdaps_classic_ensure_section: |
| 688 |
|
| 689 |
\tl_clear:N \l_sdaps_choicequestion_var_tl |
| 690 |
\tl_clear:N \l_sdaps_choicequestion_text_tl |
| 691 |
|
| 692 |
\keys_set:nn { sdaps / choicequestion } { #1 } |
| 693 |
|
| 694 |
\_sdaps_classic_question{#2}% |
| 695 |
|
| 696 |
% Setup the context |
| 697 |
\tl_if_eq:VnTF \l_sdaps_choicquestion_type_tl { multichoice } { |
| 698 |
\tl_set:Nn \l_tmpa_tl { Choice } |
| 699 |
} { |
| 700 |
\tl_set:Nn \l_tmpa_tl { Option } |
| 701 |
} |
| 702 |
\tl_if_empty:NTF \l_sdaps_choicequestion_text_tl { |
| 703 |
\sdaps_qobject_begin:nVn { choicequestion } \l_tmpa_tl { #2 } |
| 704 |
} { |
| 705 |
\sdaps_qobject_begin:nVV { choicequestion } \l_tmpa_tl \l_sdaps_choicequestion_text_tl |
| 706 |
} |
| 707 |
|
| 708 |
\sdaps_checkbox_set_type:V \l_sdaps_choicquestion_type_tl |
| 709 |
|
| 710 |
\tl_if_empty:NF \l_sdaps_choicequestion_var_tl { |
| 711 |
\sdaps_qobject_append_var:V \l_sdaps_choicequestion_var_tl |
| 712 |
} |
| 713 |
|
| 714 |
\dim_set:Nn \l__sdaps_classic_choiceitem_pad_dim { 1ex } |
| 715 |
|
| 716 |
\int_set:NV \l__sdaps_classic_choiceitem_cols_int \l_sdaps_choicequestion_cols_int |
| 717 |
\int_set:Nn \l__sdaps_classic_choiceitem_col_int { 0 } |
| 718 |
\dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim { 1000pt } |
| 719 |
\coffin_clear:N \l__sdaps_classic_choicequestion_coffin |
| 720 |
|
| 721 |
% We have to be in vertical mode at this point. |
| 722 |
\if_mode_vertical: |
| 723 |
% Nothing |
| 724 |
\else: |
| 725 |
\msg_error:nn { sdapsclassic } { choicequestion_wrong_mode } |
| 726 |
\fi: |
| 727 |
|
| 728 |
% It is important to look like a paragraph, otherwise latex thinks there is |
| 729 |
% nothing between the two question sections and doesn't insert a voluntary |
| 730 |
% page break. |
| 731 |
\the\everypar |
| 732 |
|
| 733 |
% Paragraph like spacing |
| 734 |
\vspace{\parskip} |
| 735 |
|
| 736 |
\def\choicequestion_clubpenalty{\penalty\clubpenalty\def\choicequestion_clubpenalty{\relax}\def\choicequestion_clubpenalty{\penalty\widowpenalty}} |
| 737 |
\def\choicequestion_widowpenalty{} |
| 738 |
}{ |
| 739 |
\if_mode_vertical: |
| 740 |
% Nothing |
| 741 |
\else: |
| 742 |
\msg_error:nn { sdapsclassic } { choicequestion_wrong_mode } |
| 743 |
\fi: |
| 744 |
|
| 745 |
\choicequestion_widowpenalty |
| 746 |
\vbox:n { \skip_horizontal:N \@totalleftmargin \box_use:N \l__sdaps_classic_choicequestion_coffin } |
| 747 |
\prevdepth=\l__sdaps_classic_choicequestion_prevdepth_dim |
| 748 |
\coffin_clear:N \l__sdaps_classic_choicequestion_coffin |
| 749 |
\sdaps_qobject_end:n { choicequestion } |
| 750 |
|
| 751 |
\group_end: |
| 752 |
\vspace{\parskip} |
| 753 |
} |
| 754 |
|
| 755 |
\newenvironment{optionquestion}[2][]{ |
| 756 |
\choicequestion[singlechoice,#1]{#2} |
| 757 |
} { |
| 758 |
\endchoicequestion |
| 759 |
} |
| 760 |
|
| 761 |
\cs_new_protected_nopar:Nn \_sdaps_classic_line_shipout_add:NNn |
| 762 |
{ |
| 763 |
% We have to be in vertical mode at this point. |
| 764 |
\if_mode_vertical: |
| 765 |
% Nothing |
| 766 |
\else: |
| 767 |
\msg_error:nn { sdapsclassic } { choicequestion_wrong_mode } |
| 768 |
\fi: |
| 769 |
|
| 770 |
% Is linewidth the right thing here? |
| 771 |
\int_compare:nT { \l__sdaps_classic_choiceitem_col_int + #3 > \l__sdaps_classic_choiceitem_cols_int } { |
| 772 |
% We can only typeset a coffin in vertical mode if we use the box function |
| 773 |
\vbox:n { \skip_horizontal:N \@totalleftmargin \box_use:N \l__sdaps_classic_choicequestion_coffin } |
| 774 |
\prevdepth=\l__sdaps_classic_choicequestion_prevdepth_dim |
| 775 |
\skip_vertical:N \l_sdaps_choicequestion_rowsep_dim |
| 776 |
\coffin_clear:N \l__sdaps_classic_choicequestion_coffin |
| 777 |
\dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim { 1000pt } |
| 778 |
\choicequestion_clubpenalty |
| 779 |
\int_set:Nn \l__sdaps_classic_choiceitem_col_int { 0 } |
| 780 |
} |
| 781 |
|
| 782 |
\dim_set:Nn \l_tmpa_dim { \linewidth / \l__sdaps_classic_choiceitem_cols_int + \l__sdaps_classic_choiceitem_pad_dim / \l__sdaps_classic_choiceitem_cols_int } |
| 783 |
\dim_set:Nn \l_tmpa_dim { \l__sdaps_classic_choiceitem_col_int \l_tmpa_dim } |
| 784 |
|
| 785 |
\dim_compare:nNnTF { \coffin_dp:N \l__sdaps_classic_choicequestion_coffin } > { \coffin_dp:N #1 } { |
| 786 |
\dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim {\dim_min:nn { \l__sdaps_classic_choicequestion_prevdepth_dim } { #2 + \coffin_dp:N \l__sdaps_classic_choicequestion_coffin - \coffin_dp:N #1 } } |
| 787 |
} { |
| 788 |
\dim_set:Nn \l__sdaps_classic_choicequestion_prevdepth_dim {\dim_min:nn { \l__sdaps_classic_choicequestion_prevdepth_dim + \coffin_dp:N #1 - \coffin_dp:N \l__sdaps_classic_choicequestion_coffin } { #2 } } |
| 789 |
} |
| 790 |
|
| 791 |
\coffin_join:NnnNnnnn \l__sdaps_classic_choicequestion_coffin { l } { H } #1 { l } { H } { \l_tmpa_dim } { 0pt } |
| 792 |
\int_add:Nn \l__sdaps_classic_choiceitem_col_int { #3 } |
| 793 |
} |
| 794 |
|
| 795 |
\providecommand*{\choiceitem}[2][]{% |
| 796 |
\tl_clear:N \l_sdaps_choicequestion_choice_var_tl |
| 797 |
\tl_clear:N \l_sdaps_choicequestion_choice_val_tl |
| 798 |
\tl_clear:N \l_sdaps_choicequestion_choice_text_tl |
| 799 |
|
| 800 |
\keys_set:nn { sdaps / choicequestion / choice } { #1 } |
| 801 |
|
| 802 |
\tl_if_empty:NTF \l_sdaps_choicequestion_choice_text_tl { |
| 803 |
\sdaps_answer:n { #2 } |
| 804 |
} { |
| 805 |
\sdaps_answer:V \l_sdaps_choicequestion_choice_text_tl |
| 806 |
} |
| 807 |
|
| 808 |
\dim_set:Nn \l_tmpa_dim { \linewidth / \l__sdaps_classic_choiceitem_cols_int - \l__sdaps_classic_choiceitem_pad_dim + \l__sdaps_classic_choiceitem_pad_dim / \l__sdaps_classic_choiceitem_cols_int } |
| 809 |
|
| 810 |
\hcoffin_set:Nn \l_tmpa_coffin { |
| 811 |
\hbox_set:Nn \l_tmpa_box { \strut \sdaps_checkbox:VV \l_sdaps_choicequestion_choice_var_tl \l_sdaps_choicequestion_choice_val_tl {}\ } |
| 812 |
\dim_set:Nn \l_tmpb_dim { \box_wd:N \l_tmpa_box } |
| 813 |
\hskip \l_sdaps_choicequestion_colsep_dim |
| 814 |
\hbox_unpack:N \l_tmpa_box |
| 815 |
\begin{minipage}[t]{\dim_eval:n { \l_tmpa_dim - \l_tmpb_dim - 2\l_sdaps_choicequestion_colsep_dim}} |
| 816 |
\noindent \usekomafont{choiceitemfont} \tl_trim_spaces:n { #2 }\strut |
| 817 |
\par |
| 818 |
\dim_gset:Nn \g_tmpa_dim { \dim_max:nn { \box_dp:N \l_tmpa_box } { \prevdepth } } |
| 819 |
\unskip |
| 820 |
\end{minipage} |
| 821 |
} |
| 822 |
|
| 823 |
\_sdaps_classic_line_shipout_add:NNn \l_tmpa_coffin \g_tmpa_dim { 1 } |
| 824 |
\ignorespaces |
| 825 |
} |
| 826 |
|
| 827 |
\providecommand*{\choicemulticolitem}[3][]{ % |
| 828 |
\tl_clear:N \l_sdaps_choicequestion_choice_var_tl |
| 829 |
\tl_clear:N \l_sdaps_choicequestion_choice_val_tl |
| 830 |
\tl_clear:N \l_sdaps_choicequestion_choice_text_tl |
| 831 |
|
| 832 |
\keys_set:nn { sdaps / choicequestion / choice } { #1 } |
| 833 |
|
| 834 |
\tl_if_empty:NTF \l_sdaps_choicequestion_choice_text_tl { |
| 835 |
\sdaps_answer:n { #3 } |
| 836 |
} { |
| 837 |
\sdaps_answer:V \l_sdaps_choicequestion_choice_text_tl |
| 838 |
} |
| 839 |
|
| 840 |
\dim_set:Nn \l_tmpa_dim { #2\linewidth / \l__sdaps_classic_choiceitem_cols_int - \l__sdaps_classic_choiceitem_pad_dim + #2 \l__sdaps_classic_choiceitem_pad_dim / \l__sdaps_classic_choiceitem_cols_int } |
| 841 |
|
| 842 |
\hcoffin_set:Nn \l_tmpa_coffin { |
| 843 |
\hbox_set:Nn \l_tmpa_box { \strut \sdaps_checkbox:VV \l_sdaps_choicequestion_choice_var_tl \l_sdaps_choicequestion_choice_val_tl {}\ } |
| 844 |
\dim_set:Nn \l_tmpb_dim { \box_wd:N \l_tmpa_box } |
| 845 |
\hskip \l_sdaps_choicequestion_colsep_dim |
| 846 |
\hbox_unpack:N \l_tmpa_box |
| 847 |
\begin{minipage}[t]{\dim_eval:n { \l_tmpa_dim - \l_tmpb_dim - 2\l_sdaps_choicequestion_colsep_dim}} |
| 848 |
\noindent \usekomafont{choiceitemfont} \tl_trim_spaces:n { #3 }\strut |
| 849 |
\par |
| 850 |
\dim_gset:Nn \g_tmpa_dim { \dim_max:nn { \box_dp:N \l_tmpa_box } { \prevdepth } } |
| 851 |
\unskip |
| 852 |
\end{minipage} |
| 853 |
} |
| 854 |
|
| 855 |
\_sdaps_classic_line_shipout_add:NNn \l_tmpa_coffin \g_tmpa_dim { #2 } |
| 856 |
\ignorespaces |
| 857 |
} |
| 858 |
|
| 859 |
\providecommand{\choiceitemtext}[4][]{% |
| 860 |
\tl_clear:N \l_sdaps_choicequestion_choice_var_tl |
| 861 |
\tl_clear:N \l_sdaps_choicequestion_choice_val_tl |
| 862 |
\tl_clear:N \l_sdaps_choicequestion_choice_text_tl |
| 863 |
|
| 864 |
\keys_set:nn { sdaps / choicequestion / choice } { #1 } |
| 865 |
% TODO: Warn if val has been set here |
| 866 |
|
| 867 |
% If not multichoice then warn |
| 868 |
\tl_if_eq:VnF \l_sdaps_choicquestion_type_tl { multichoice } { |
| 869 |
\msg_error:nn { sdapsclassic } { choicequestion_no_text } |
| 870 |
} |
| 871 |
|
| 872 |
\tl_if_empty:NTF \l_sdaps_choicequestion_choice_text_tl { |
| 873 |
\sdaps_answer:n { #4 } |
| 874 |
} { |
| 875 |
\sdaps_answer:V \l_sdaps_choicequestion_choice_text_tl |
| 876 |
} |
| 877 |
|
| 878 |
\dim_set:Nn \l_tmpa_dim { #3\linewidth / \l__sdaps_classic_choiceitem_cols_int - \l__sdaps_classic_choiceitem_pad_dim + #3 \l__sdaps_classic_choiceitem_pad_dim / \l__sdaps_classic_choiceitem_cols_int } |
| 879 |
|
| 880 |
\hcoffin_set:Nn \l_tmpa_coffin { |
| 881 |
\hskip \l_sdaps_choicequestion_colsep_dim |
| 882 |
\begin{minipage}[t]{\dim_eval:n { \l_tmpa_dim - 2\l_sdaps_choicequestion_colsep_dim}} |
| 883 |
\usekomafont{choiceitemfont} |
| 884 |
\dim_set:Nn \l_tmpa_dim { #2 } |
| 885 |
\dim_set:Nn \l_tmpb_dim { #2 } |
| 886 |
\dim_set:Nn \l_tmpa_dim { 0.5 \l_tmpa_dim - 0.8ex } |
| 887 |
\dim_set:Nn \l_tmpb_dim { 0.5 \l_tmpb_dim + 0.8ex } |
| 888 |
\strut\ignorespaces \tl_trim_spaces:n { #4 } ~ |
| 889 |
\sdaps_textbox_hstretch:VVVnn \l_sdaps_choicequestion_choice_var_tl \l_tmpa_dim \l_tmpb_dim { 0pt } { 1 } |
| 890 |
\par |
| 891 |
\dim_gset:Nn \g_tmpa_dim { \prevdepth } |
| 892 |
\unskip |
| 893 |
\end{minipage} |
| 894 |
} |
| 895 |
|
| 896 |
\_sdaps_classic_line_shipout_add:NNn \l_tmpa_coffin \g_tmpa_dim { #3 } |
| 897 |
\ignorespaces |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
% \end{macrocode} |
| 903 |
% |
| 904 |
% \subsection{The questionnaire environment} |
| 905 |
% |
| 906 |
% There is a bit of magic here. If (and only if) we need to render multiple |
| 907 |
% pages of the questionnaire, then we write the whole questionnaire into a |
| 908 |
% temporary file. This way we can input the file multiple times, which means |
| 909 |
% that environments changing the parser (e.g. verbatim) work properly. |
| 910 |
% |
| 911 |
% \begin{macrocode} |
| 912 |
% |
| 913 |
|
| 914 |
\iow_new:N \l__sdaps_questionnaire_iow |
| 915 |
\bool_new:N \l__sdaps_questionnaire_parse_direct_bool |
| 916 |
|
| 917 |
\bool_new:N \l__sdaps_questionnaire_info_bool |
| 918 |
|
| 919 |
\keys_define:nn { sdaps / questionnaire } |
| 920 |
{ |
| 921 |
info .bool_set:N = \l__sdaps_questionnaire_info_bool, |
| 922 |
info .default:n = true, |
| 923 |
info .initial:n = true, |
| 924 |
|
| 925 |
noinfo .meta:n = { info=false }, |
| 926 |
} |
| 927 |
|
| 928 |
\cs_new_protected_nopar:Nn \_sdaps_classic_info: |
| 929 |
{ |
| 930 |
\translate{infotext} \\[1ex] |
| 931 |
\tl_if_eq:VnTF \g_sdaps_checkmode_tl { checkcorrect } { |
| 932 |
\begin{tabularx}{\textwidth}{lXllll} |
| 933 |
\checkbox & \strut \translate{info-multi} & \hspace{2em} \checkedbox {} & \translate{info-cross} & \hspace{1em} \correctedbox {} & \translate{info-corrected} \\ |
| 934 |
\checkbox* & \strut \translate{info-single} & \hspace{2em} \checkedbox* {} & \translate{info-cross} & \hspace{1em} \correctedbox* {} & \translate{info-corrected} \\ |
| 935 |
\end{tabularx} |
| 936 |
} { |
| 937 |
\tl_if_eq:VnTF \g_sdaps_checkmode_tl { check } { |
| 938 |
\begin{tabularx}{\textwidth}{lXll} |
| 939 |
\checkbox & \strut \translate{info-multi} & \hspace{2em} \checkedbox {} & \translate{info-cross} \\ |
| 940 |
\checkbox* & \strut \translate{info-single} & \hspace{2em} \checkedbox* {} & \translate{info-cross} \\ |
| 941 |
\end{tabularx} |
| 942 |
} { |
| 943 |
\tl_if_eq:VnTF \g_sdaps_checkmode_tl { fill } { |
| 944 |
\begin{tabularx}{\textwidth}{lXll} |
| 945 |
\checkbox & \strut \translate{info-multi} & \hspace{2em} \filledbox {} & \translate{info-fill} \\ |
| 946 |
\checkbox* & \strut \translate{info-single} & \hspace{2em} \filledbox* {} & \translate{info-fill} \\ |
| 947 |
\end{tabularx} |
| 948 |
} { |
| 949 |
\PackageError{sdaps}{Sorry, there is no help text for the checkmode you have choosen right now! Please pass the noinfo optional argument to the questionnaire environment!}\@ehb % |
| 950 |
} |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
\cs_new_protected_nopar:Nn \_sdaps_classic_show_info: |
| 956 |
{ |
| 957 |
\bool_if:NT \l__sdaps_questionnaire_info_bool { |
| 958 |
\begin{info} |
| 959 |
\_sdaps_classic_info: |
| 960 |
\end{info} |
| 961 |
} |
| 962 |
\ignorespaces |
| 963 |
} |
| 964 |
|
| 965 |
\newenvironment { questionnaire } [ 1 ] [] |
| 966 |
{ |
| 967 |
\keys_set:nn { sdaps / questionnaire } { #1 } |
| 968 |
|
| 969 |
\hypersetup{ |
| 970 |
pdfauthor = \@author, |
| 971 |
pdftitle = \@title, |
| 972 |
pdfsubject = sdaps questionnaire \@title, |
| 973 |
pdfkeywords = sdaps questionnaire \@title |
| 974 |
} |
| 975 |
|
| 976 |
% If we only have one questionnaire ID, then parse the environment directly, |
| 977 |
% otherwise write it into a temporary file and input it multiple times. |
| 978 |
\group_begin: |
| 979 |
|
| 980 |
\if@twoside |
| 981 |
\bool_gset_true:N \g_sdaps_twoside_bool |
| 982 |
\else |
| 983 |
\bool_gset_false:N \g_sdaps_twoside_bool |
| 984 |
\fi |
| 985 |
|
| 986 |
% Enable all metadata writing by default |
| 987 |
\sdaps_context_enable_writing: |
| 988 |
|
| 989 |
\sdaps_info_write:x{Author=\exp_not:o{\@author}} |
| 990 |
\sdaps_info_write:x{Title=\exp_not:o{\@title}} |
| 991 |
|
| 992 |
\int_compare:nTF { \seq_count:N \g_sdaps_questionnaire_ids_seq <= 1 } { |
| 993 |
\bool_set_true:N \l__sdaps_questionnaire_parse_direct_bool |
| 994 |
|
| 995 |
% Set the questionnaire ID |
| 996 |
\seq_gpop_left:NN \g_sdaps_questionnaire_ids_seq \l_tmpa_tl |
| 997 |
\sdaps_set_questionnaire_id:V \l_tmpa_tl |
| 998 |
|
| 999 |
% And, begin the questionnaire |
| 1000 |
\sdaps_begin: |
| 1001 |
\_sdaps_classic_show_info: |
| 1002 |
} { |
| 1003 |
\bool_set_false:N \l__sdaps_questionnaire_parse_direct_bool |
| 1004 |
|
| 1005 |
% Write content into a file, see "verbatim" documentation for more information. |
| 1006 |
% TODO: Allow multiple temporary files by postfixing with integer? |
| 1007 |
\iow_open:Nn \l__sdaps_questionnaire_iow { \c_sys_jobname_str . questionnaire } |
| 1008 |
\cs_set_eq:NN\do\@makeother\dospecials |
| 1009 |
\catcode`\^^M\active |
| 1010 |
\def\verbatim@processline{ |
| 1011 |
\iow_now:Nx \l__sdaps_questionnaire_iow {\the\verbatim@line} |
| 1012 |
} |
| 1013 |
\verbatim@ |
| 1014 |
} |
| 1015 |
} { |
| 1016 |
\bool_if:NTF \l__sdaps_questionnaire_parse_direct_bool { |
| 1017 |
% Just end everything, nothing else to do. |
| 1018 |
% Make sure we always end the current paragraph. |
| 1019 |
\par |
| 1020 |
\sdaps_end: |
| 1021 |
|
| 1022 |
\group_end: |
| 1023 |
} { |
| 1024 |
% We are done inputting the questionnaire |
| 1025 |
\iow_close:N \l__sdaps_questionnaire_iow |
| 1026 |
\group_end: |
| 1027 |
|
| 1028 |
% Now cycle through all IDS and output it again. |
| 1029 |
\group_begin: |
| 1030 |
\seq_map_inline:Nn \g_sdaps_questionnaire_ids_seq { |
| 1031 |
\sdaps_set_questionnaire_id:n { ##1 } |
| 1032 |
|
| 1033 |
% Reset a lot of global LaTeX counters |
| 1034 |
\@ifundefined{c@page}{}{\setcounter{page}{1}} |
| 1035 |
\@ifundefined{c@part}{}{\setcounter{part}{0}} |
| 1036 |
\@ifundefined{c@chapter}{}{\setcounter{chapter}{0}} |
| 1037 |
\@ifundefined{c@paragraph}{}{\setcounter{paragraph}{0}} |
| 1038 |
\@ifundefined{c@subparagraph}{}{\setcounter{subparagraph}{0}} |
| 1039 |
\@ifundefined{c@section}{}{\setcounter{section}{0}} |
| 1040 |
\@ifundefined{c@subsection}{}{\setcounter{subsection}{0}} |
| 1041 |
\@ifundefined{c@subsubsection}{}{\setcounter{subsubsection}{0}} |
| 1042 |
\@ifundefined{c@equation}{}{\setcounter{equation}{0}} |
| 1043 |
\@ifundefined{c@figure}{}{\setcounter{figure}{0}} |
| 1044 |
\@ifundefined{c@table}{}{\setcounter{table}{0}} |
| 1045 |
|
| 1046 |
\sdaps_begin: |
| 1047 |
\_sdaps_classic_show_info: |
| 1048 |
\input{ \c_sys_jobname_str . questionnaire } |
| 1049 |
% Make sure we always end the current paragraph. |
| 1050 |
\par |
| 1051 |
\sdaps_end: |
| 1052 |
\newpage |
| 1053 |
|
| 1054 |
% Close the output file now (after the page has been shipped out) |
| 1055 |
% XXX: This is a bit of a hack, as disabling metadata writing has side effects |
| 1056 |
\iow_close:N \g_sdaps_infofile_iow |
| 1057 |
|
| 1058 |
} |
| 1059 |
\group_end: |
| 1060 |
} |
| 1061 |
} |
| 1062 |
|
| 1063 |
\def\sdapspagemark{ |
| 1064 |
\sdaps_page_end: |
| 1065 |
} |
| 1066 |
|
| 1067 |
\def\sdapsinfo{ |
| 1068 |
\_sdaps_classic_info: |
| 1069 |
} |
| 1070 |
|
| 1071 |
% \end{macrocode} |
| 1072 |
% |
| 1073 |
% \subsection{The group environments} |
| 1074 |
% |
| 1075 |
% Alias for the group environments. |
| 1076 |
% |
| 1077 |
% \begin{macrocode} |
| 1078 |
% |
| 1079 |
|
| 1080 |
\tl_new:N \l__sdaps_classic_group_var_tl |
| 1081 |
\tl_new:N \l__sdaps_classic_group_text_tl |
| 1082 |
\tl_new:N \l__sdaps_classic_group_extra_tl |
| 1083 |
\keys_define:nn { sdapsclassic / group } |
| 1084 |
{ |
| 1085 |
var .tl_set:N = \l__sdaps_classic_group_var_tl, |
| 1086 |
text .tl_set:N = \l__sdaps_classic_group_text_tl, |
| 1087 |
} |
| 1088 |
|
| 1089 |
\newenvironment { choicegroup } [ 2 ] [] |
| 1090 |
{ |
| 1091 |
\group_begin: |
| 1092 |
\keys_set_known:nnN { sdapsclassic / group } { #1 } \l__sdaps_classic_group_extra_tl |
| 1093 |
|
| 1094 |
\_sdaps_classic_question{#2} |
| 1095 |
\tl_if_empty:NTF \l__sdaps_classic_group_text_tl { |
| 1096 |
\sdaps_qobject_begin:nnn { choicegroup } { Head } { #2 } |
| 1097 |
} { |
| 1098 |
\sdaps_qobject_begin:nnV { choicegroup } { Head } \l__sdaps_classic_group_text_tl |
| 1099 |
} |
| 1100 |
|
| 1101 |
\tl_if_empty:NF \l__sdaps_classic_group_var_tl { |
| 1102 |
\sdaps_qobject_append_var:V \l__sdaps_classic_group_var_tl |
| 1103 |
} |
| 1104 |
|
| 1105 |
% Undefine the question (and choice) commands in local scope so that they |
| 1106 |
% can be redefined by choicearray without any issues. |
| 1107 |
% Note that \cs_undefine:N works in global scope, so we cannot use it here. |
| 1108 |
\cs_set_eq:NN\question\tex_undefined:D |
| 1109 |
\cs_set_eq:NN\choice\tex_undefined:D |
| 1110 |
|
| 1111 |
\expandafter\choicearray\expandafter[\l__sdaps_classic_group_extra_tl] |
| 1112 |
% XXX: This is a bit of a hack, set in global scope because the choicearray |
| 1113 |
% environment does evil things with scopes. |
| 1114 |
\cs_gset_eq:NN\groupaddchoice\choice |
| 1115 |
\cs_gset_eq:NN\choiceline\question |
| 1116 |
} |
| 1117 |
{ |
| 1118 |
\cs_gset_eq:NN\groupaddchoice\undefined |
| 1119 |
\cs_gset_eq:NN\choiceline\undefined |
| 1120 |
|
| 1121 |
\endchoicearray |
| 1122 |
|
| 1123 |
\sdaps_qobject_end:n { choicegroup } |
| 1124 |
\group_end: |
| 1125 |
} |
| 1126 |
|
| 1127 |
\newenvironment { optiongroup } [ 2 ] [] |
| 1128 |
{ |
| 1129 |
\group_begin: |
| 1130 |
\keys_set_known:nnN { sdapsclassic / group } { #1 } \l__sdaps_classic_group_extra_tl |
| 1131 |
|
| 1132 |
\_sdaps_classic_question{#2} |
| 1133 |
\tl_if_empty:NTF \l__sdaps_classic_group_text_tl { |
| 1134 |
\sdaps_qobject_begin:nnn { optiongroup } { Head } { #2 } |
| 1135 |
} { |
| 1136 |
\sdaps_qobject_begin:nnV { optiongroup } { Head } \l__sdaps_classic_group_text_tl |
| 1137 |
} |
| 1138 |
|
| 1139 |
\tl_if_empty:NF \l__sdaps_classic_group_var_tl { |
| 1140 |
\sdaps_qobject_append_var:V \l__sdaps_classic_group_var_tl |
| 1141 |
} |
| 1142 |
|
| 1143 |
% Undefine the question (and choice) commands in local scope so that they |
| 1144 |
% can be redefined by optionarray without any issues. |
| 1145 |
% Note that \cs_undefine:N works in global scope, so we cannot use it here. |
| 1146 |
\cs_set_eq:NN\question\tex_undefined:D |
| 1147 |
\cs_set_eq:NN\choice\tex_undefined:D |
| 1148 |
|
| 1149 |
\expandafter\optionarray\expandafter[\l__sdaps_classic_group_extra_tl] |
| 1150 |
% XXX: This is a bit of a hack, set in global scope because the optionarray |
| 1151 |
% environment does evil things with scopes. |
| 1152 |
\cs_gset_eq:NN\groupaddchoice\choice |
| 1153 |
\cs_gset_eq:NN\optionline\question |
| 1154 |
} |
| 1155 |
{ |
| 1156 |
\cs_gset_eq:NN\groupaddoption\undefined |
| 1157 |
\cs_gset_eq:NN\optionline\undefined |
| 1158 |
|
| 1159 |
\endoptionarray |
| 1160 |
\sdaps_qobject_end:n { optiongroup } |
| 1161 |
\group_end: |
| 1162 |
} |
| 1163 |
|
| 1164 |
\newenvironment { markgroup } [ 2 ] [] |
| 1165 |
{ |
| 1166 |
\group_begin: |
| 1167 |
\keys_set_known:nnN { sdapsclassic / group } { #1 } \l__sdaps_classic_group_extra_tl |
| 1168 |
|
| 1169 |
\_sdaps_classic_question{#2} |
| 1170 |
\tl_if_empty:NTF \l__sdaps_classic_group_text_tl { |
| 1171 |
\sdaps_qobject_begin:nnn { markgroup } { Head } { #2 } |
| 1172 |
} { |
| 1173 |
\sdaps_qobject_begin:nnV { markgroup } { Head } \l__sdaps_classic_group_text_tl |
| 1174 |
} |
| 1175 |
|
| 1176 |
\tl_if_empty:NF \l__sdaps_classic_group_var_tl { |
| 1177 |
\sdaps_qobject_append_var:V \l__sdaps_classic_group_var_tl |
| 1178 |
} |
| 1179 |
|
| 1180 |
% Undefine the range command in local scope so that it can be redefined |
| 1181 |
% by rangearray without any issues. |
| 1182 |
% Note that \cs_undefine:N works in global scope, so we cannot use it here. |
| 1183 |
\cs_set_eq:NN\range\tex_undefined:D |
| 1184 |
|
| 1185 |
\expandafter\rangearray\expandafter[\l__sdaps_classic_group_extra_tl] |
| 1186 |
% XXX: This is a bit of a hack, set in global scope because the choicearray |
| 1187 |
% environment does evil things with scopes. |
| 1188 |
\cs_gset_eq:NN\markline\range |
| 1189 |
} |
| 1190 |
{ |
| 1191 |
\cs_gset_eq:NN\markline\undefined |
| 1192 |
|
| 1193 |
\endrangearray |
| 1194 |
\sdaps_qobject_end:n { markgroup } |
| 1195 |
\group_end: |
| 1196 |
} |
| 1197 |
|
| 1198 |
\ExplSyntaxOff |
| 1199 |
|
| 1200 |
% \end{macrocode} |
| 1201 |
|
| 1202 |
% \Finale |
| 1203 |
\endinput |