| 1 |
Creating custom layouts using base commands |
| 2 |
=========================================== |
| 3 |
|
| 4 |
Usually the pre-defined layouts that SDAPS provides are sufficent. However, |
| 5 |
there may be special cases that need more customization. Such customization is |
| 6 |
possible, but it does require a more in depth understanding of LaTeX and |
| 7 |
the SDAPS packages. |
| 8 |
|
| 9 |
If you do this, please make sure to properly test the output. The easiest way |
| 10 |
of such testing is to use the ``annotate`` command that SDAPS provides, as it |
| 11 |
visualises the view that SDAPS has of the questionnaire. Doing this testing is |
| 12 |
essential as small errors and even side effects of how LaTeX executes code may |
| 13 |
render the information about the questionnaire useless! |
| 14 |
|
| 15 |
Even seemingly "simple" environments like ``tabularx`` may not be usable |
| 16 |
together with SDAPS! |
| 17 |
|
| 18 |
|
| 19 |
General question structure |
| 20 |
-------------------------- |
| 21 |
|
| 22 |
To define a question, you need to define |
| 23 |
1. the start of the question and its type, |
| 24 |
2. the possible answers to the question |
| 25 |
3. the checkboxes and textboxes, and finally |
| 26 |
4. the end of the question. |
| 27 |
|
| 28 |
A very simple example might look like the following. |
| 29 |
|
| 30 |
.. sdaps:: Question with one checkbox |
| 31 |
:sdapsclassic: |
| 32 |
:metadata: |
| 33 |
|
| 34 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 35 |
\ExplSyntaxOn |
| 36 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 37 |
\let\mycheckbox\sdaps_checkbox:nn |
| 38 |
\let\myanswer\sdaps_answer:n |
| 39 |
\let\myquestionend\sdaps_qobject_end:n |
| 40 |
\ExplSyntaxOff |
| 41 |
|
| 42 |
\myquestionbegin{name}{Choice}{Exported question text} |
| 43 |
Please check after reading this text: \mycheckbox{}{} |
| 44 |
\myanswer{check} |
| 45 |
\myquestionend{name} |
| 46 |
|
| 47 |
Please have a look at the resulting document and the generated metadata. In particular, |
| 48 |
please note: |
| 49 |
|
| 50 |
* The export shows "``QObject-Choice``" this is from the ``Choice`` specified and denotes the question type |
| 51 |
* The ``name`` argument does not show up. It only needs to match the one at the end and primarily serves error detection purposes. |
| 52 |
* SDAPS will see the question as "Exported question text" with one answer "check" |
| 53 |
* The checkbox is automatically exported including its coordinates |
| 54 |
|
| 55 |
.. warning:: |
| 56 |
Be careful! The below example shows the effect that ``tabularx`` has. This environment |
| 57 |
expands its content multiple times, and the result is that the automatic numbering |
| 58 |
breaks; making this the 3rd question rather than the first! Other subtle errors like |
| 59 |
this can occur with certain environments, so make sure to double check everything is OK! |
| 60 |
|
| 61 |
.. sdaps:: Question inside tabularx |
| 62 |
:preamble: \usepackage{tabularx} |
| 63 |
:sdapsclassic: |
| 64 |
:metadata: |
| 65 |
|
| 66 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 67 |
\ExplSyntaxOn |
| 68 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 69 |
\let\mycheckbox\sdaps_checkbox:nn |
| 70 |
\let\myanswer\sdaps_answer:n |
| 71 |
\let\myquestionend\sdaps_qobject_end:n |
| 72 |
\ExplSyntaxOff |
| 73 |
|
| 74 |
\begin{tabularx}{\textwidth}{|X|} |
| 75 |
\myquestionbegin{name}{Choice}{The tabularx environment breaks everything ...} |
| 76 |
Please check after reading this text: \mycheckbox{}{} |
| 77 |
\myanswer{check} |
| 78 |
\myquestionend{name} |
| 79 |
\end{tabularx} |
| 80 |
|
| 81 |
|
| 82 |
The different question types |
| 83 |
============================ |
| 84 |
|
| 85 |
Headings |
| 86 |
-------- |
| 87 |
|
| 88 |
This is the easiest case, and it can be used for structuring the document. |
| 89 |
|
| 90 |
For example, the ``\section`` command simply calls |
| 91 |
``\sdaps_qobject_begin:nnn { section }{ Head }{ #1 }`` |
| 92 |
and ``\sdaps_qobject_end:n { section }`` for you. Something similar happens for |
| 93 |
the ``choicegroup`` and other grouping environments where a heading is defined |
| 94 |
for all questions. |
| 95 |
|
| 96 |
.. sdaps:: Grouping questions |
| 97 |
:sdapsclassic: |
| 98 |
:metadata: |
| 99 |
|
| 100 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 101 |
\ExplSyntaxOn |
| 102 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 103 |
\let\myquestionend\sdaps_qobject_end:n |
| 104 |
\ExplSyntaxOff |
| 105 |
|
| 106 |
\myquestionbegin{heading}{Head}{Heading} |
| 107 |
Something inside the section. |
| 108 |
\myquestionend{heading} |
| 109 |
|
| 110 |
|
| 111 |
Multiple choice |
| 112 |
--------------- |
| 113 |
|
| 114 |
The simple multiple choice question is of type ``Choice``. We already saw the |
| 115 |
first example earlier. Simply add more checkboxes and answers as needed. SDAPS |
| 116 |
will match each checkbox to one answer in the order that it finds the defintions. |
| 117 |
|
| 118 |
.. sdaps:: Multiple choice question using itemize |
| 119 |
:sdapsclassic: |
| 120 |
:metadata: |
| 121 |
|
| 122 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 123 |
\ExplSyntaxOn |
| 124 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 125 |
\let\mycheckbox\sdaps_checkbox:nn |
| 126 |
\let\myanswer\sdaps_answer:n |
| 127 |
\let\myquestionend\sdaps_qobject_end:n |
| 128 |
\ExplSyntaxOff |
| 129 |
|
| 130 |
\myquestionbegin{name}{Choice}{Attended events} |
| 131 |
Which of the following events did you attend? |
| 132 |
\begin{itemize} |
| 133 |
\item[\mycheckbox{}{}] \myanswer{Keynote} The Keynote |
| 134 |
\item[\mycheckbox{}{}] \myanswer{Workshop} A workshop |
| 135 |
\item[\mycheckbox{}{}] \myanswer{Party} Our glorious party |
| 136 |
\item Something else entirely \myanswer{other} |
| 137 |
\ExplSyntaxOn |
| 138 |
\sdaps_textbox_hstretch:nnnnn{}{2mm}{5mm}{40mm}{1} |
| 139 |
\ExplSyntaxOff |
| 140 |
\end{itemize} |
| 141 |
\myquestionend{name} |
| 142 |
|
| 143 |
Note that we placed a textbox rather than a checkbox as one of the possible |
| 144 |
answers. |
| 145 |
|
| 146 |
|
| 147 |
Single choice |
| 148 |
------------- |
| 149 |
|
| 150 |
We can also define a single choice question. For this, we need to make two |
| 151 |
small adjustments. The first is to use the ``Option`` question type. The second |
| 152 |
is to tell SDAPS that we would like to use the ``singlechoice`` style for |
| 153 |
checkboxes. |
| 154 |
|
| 155 |
The checkbox style change will be in effect for the scope of the question. |
| 156 |
|
| 157 |
.. sdaps:: Single choice question using itemize |
| 158 |
:sdapsclassic: |
| 159 |
:metadata: |
| 160 |
|
| 161 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 162 |
\ExplSyntaxOn |
| 163 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 164 |
\let\mycheckbox\sdaps_checkbox:nn |
| 165 |
\let\myanswer\sdaps_answer:n |
| 166 |
\let\myquestionend\sdaps_qobject_end:n |
| 167 |
\let\mysetcheckboxtype\sdaps_checkbox_set_type:n |
| 168 |
\ExplSyntaxOff |
| 169 |
|
| 170 |
\myquestionbegin{name}{Option}{Attended events} |
| 171 |
\mysetcheckboxtype{singlechoice} |
| 172 |
Which one of the following events did you attend? |
| 173 |
\begin{itemize} |
| 174 |
\item[\mycheckbox{}{}] \myanswer{Talk room A} Talk in room A |
| 175 |
\item[\mycheckbox{}{}] \myanswer{Talk room B} Talk in room B |
| 176 |
\item Something else entirely \myanswer{other} |
| 177 |
\ExplSyntaxOn |
| 178 |
\sdaps_textbox_hstretch:nnnnn{}{2mm}{5mm}{40mm}{1} |
| 179 |
\ExplSyntaxOff |
| 180 |
\end{itemize} |
| 181 |
\myquestionend{name} |
| 182 |
|
| 183 |
Note that we placed a textbox rather than a checkbox as one of the possible |
| 184 |
answers. |
| 185 |
|
| 186 |
|
| 187 |
Ranges |
| 188 |
------ |
| 189 |
|
| 190 |
Quite often one has single choice question which represent a value on a range. |
| 191 |
One could create these using the ``Option`` type question, but with ``Range`` |
| 192 |
it becomes more convenient. |
| 193 |
|
| 194 |
Range questions can contain a single range and further answers like |
| 195 |
"Not applicable". |
| 196 |
|
| 197 |
The range is specified with a separate command. For the purpose of this command, |
| 198 |
the first and last box that is part of the range needs to be specified. This is |
| 199 |
done with a zero based index (i.e. the first checkbox is 0, the second 1, …). |
| 200 |
|
| 201 |
.. sdaps:: Range question |
| 202 |
:sdapsclassic: |
| 203 |
:metadata: |
| 204 |
|
| 205 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 206 |
\ExplSyntaxOn |
| 207 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 208 |
\let\mycheckbox\sdaps_checkbox:nn |
| 209 |
\let\myanswer\sdaps_answer:n |
| 210 |
\let\myrange\sdaps_range:nnn |
| 211 |
\let\myquestionend\sdaps_qobject_end:n |
| 212 |
\let\mysetcheckboxtype\sdaps_checkbox_set_type:n |
| 213 |
\ExplSyntaxOff |
| 214 |
|
| 215 |
\myquestionbegin{name}{Option}{Attended events} |
| 216 |
\mysetcheckboxtype{singlechoice} |
| 217 |
Did you like the keynote? |
| 218 |
\begin{itemize} |
| 219 |
\item |
| 220 |
it was bad |
| 221 |
\mycheckbox{}{} ~ |
| 222 |
\mycheckbox{}{} ~ |
| 223 |
\mycheckbox{}{} ~ |
| 224 |
\mycheckbox{}{} ~ |
| 225 |
\mycheckbox{}{} ~ |
| 226 |
it was great |
| 227 |
\item[\mycheckbox{}{}] I did not attend the keynote |
| 228 |
\end{itemize} |
| 229 |
\myrange{lower}{0}{bad} |
| 230 |
\myrange{upper}{4}{great} |
| 231 |
\myanswer{did not attend} |
| 232 |
\myquestionend{name} |
| 233 |
|
| 234 |
Note that ``lower`` must always be the earlier checkbox. You can however assign |
| 235 |
different values to each checkbox using the second parameter to the checkbox |
| 236 |
command, thereby redefining the numeric value. The main different to the |
| 237 |
``Option`` question is simply how the question will be represented in the |
| 238 |
report. |
| 239 |
|
| 240 |
.. _codeboxes: |
| 241 |
|
| 242 |
Codeboxes |
| 243 |
--------- |
| 244 |
|
| 245 |
There is experimental support for code boxes, that is not yet available using a |
| 246 |
nice wrapper. This can be used to create QR code read fields. |
| 247 |
|
| 248 |
.. sdaps:: Codebox question and field |
| 249 |
:sdapsclassic: |
| 250 |
:metadata: |
| 251 |
:preamble: |
| 252 |
% Prepare some stuff so that we can access the specialized commands more easily. |
| 253 |
\ExplSyntaxOn |
| 254 |
\let\myquestionbegin\sdaps_qobject_begin:nnn |
| 255 |
\let\mytexthbox\sdaps_textbox_hbox:nnn |
| 256 |
\let\myquestionend\sdaps_qobject_end:n |
| 257 |
\let\mysettextboxtype\sdaps_textbox_set_type:n |
| 258 |
% Set a global overlay with a nice icon (quite likely, you will just want |
| 259 |
% to place text into the hbox below rather than just placing spacing). |
| 260 |
\sdaps_context_set:n { |
| 261 |
codebox = { |
| 262 |
centered_text = { |
| 263 |
\begin{tikzpicture}[yscale=-0.1, xscale=0.1] |
| 264 |
\path[draw=black,fill=black,stroke=] (-1,0) |
| 265 |
-- (-1,5) -- (4,5) -- (4,0) -- cycle(7,0) -- (7,5) -- (12,5) -- (12,0) -- cycle(0,1) -- (3,1) -- (3,4) |
| 266 |
-- (0,4) -- cycle(8,1) -- (11,1) -- (11,4) -- (8,4) -- cycle(1,2) -- (1,3) -- (2,3) -- (2,2) -- cycle(5,2) -- |
| 267 |
(5,3) -- (6,3) -- (6,2) -- cycle(9,2) -- (9,3) -- (10,3) -- (10,2) -- cycle(5,4) -- (5,6) -- (2,6) -- (2,7) |
| 268 |
-- (6,7) -- (6,4) -- cycle(0,6) -- (0,7) -- (1,7) -- (1,6) -- cycle(7,6) -- (7,7) -- (8,7) -- (8,6) -- |
| 269 |
cycle(-1,8) -- (-1,13) -- (4,13) -- (4,8) -- cycle(5,8) -- (5,13) -- (6,13) -- (6,8) -- cycle(7,8) -- (7,9) |
| 270 |
-- (8,9) -- (8,10) -- (7,10) -- (7,13) -- (8,13) -- (8,11) -- (9,11) -- (9,10) -- (10,10) -- (10,9) -- (9,9) |
| 271 |
-- (9,8) -- cycle(10,9) -- (12,9) -- (12,8) -- (10,8) -- cycle(0,9) -- (3,9) -- (3,12) -- (0,12) -- |
| 272 |
cycle(1,10) -- (1,11) -- (2,11) -- (2,10) -- cycle(11,10) -- (11,11) -- (12,11) -- (12,10) -- cycle(11,11) -- |
| 273 |
(10,11) -- (10,12) -- (9,12) -- (9,13) -- (12,13) -- (12,12) -- (11,12) -- cycle; |
| 274 |
\end{tikzpicture} |
| 275 |
}, |
| 276 |
} |
| 277 |
} |
| 278 |
\ExplSyntaxOff |
| 279 |
|
| 280 |
\myquestionbegin{name}{Text}{This is a QR code question} |
| 281 |
\mysettextboxtype{codebox} |
| 282 |
|
| 283 |
Place barcode sticker into the box: |
| 284 |
% Note that we use hspace + vrule for sizing here, that is a bit weird but |
| 285 |
% a reasonable method of setting a size |
| 286 |
\mytexthbox{}{3bp}{ \hspace{8cm} \vrule width 0pt height 3cm depth 2cm } |
| 287 |
\myquestionend{name} |
| 288 |
|