Debian Codegraph @

texmf-dist/doc/latex/tasks/tasks-manual.tex

raw
1 % --------------------------------------------------------------------------
2 % the TASKS package
3 %
4 % lists with columns filled horizontally
5 %
6 % --------------------------------------------------------------------------
7 % Clemens Niederberger
8 % Web: https://github.com/cgnieder/tasks/
9 % E-Mail: [email protected]
10 % --------------------------------------------------------------------------
11 % Copyright 2013--2022 Clemens Niederberger
12 %
13 % This work may be distributed and/or modified under the
14 % conditions of the LaTeX Project Public License, either version 1.3c
15 % of this license or (at your option) any later version.
16 % The latest version of this license is in
17 % http://www.latex-project.org/lppl.txt
18 % and version 1.3c or later is part of all distributions of LaTeX
19 % version 2008/05/04 or later.
20 %
21 % This work has the LPPL maintenance status `maintained'.
22 %
23 % The Current Maintainer of this work is Clemens Niederberger.
24 % --------------------------------------------------------------------------
25 % If you have any ideas, questions, suggestions or bugs to report, please
26 % feel free to contact me.
27 % --------------------------------------------------------------------------
28 \documentclass{tasks-manual}
29
30 \begin{document}
31
32 \section{Preface}
33 \subsection{Motivation \& History}
34 Originally \Tasks\ has been an integral part of the
35 \ExSheets\changedversion{0.7} package~\cite{pkg:exsheets}. However, users
36 told me that it indeed could be useful to have it as a stand-alone package not
37 having to load the whole \ExSheets\ beast just for having the \env{tasks}
38 environment available. Since I agree with this the environment has been
39 extracted into a package if its own, \Tasks. Since then \Tasks\ has been
40 distributed as a package of its own but as part of the \ExSheets\
41 bundle\changedversion{0.10}. With v0.10 I decided to make it a completely
42 independent package. So the relation to \ExSheets\ only is a historical one.
43
44 The reason for the \env{tasks} environment is an unwritten agreement in German
45 maths textbooks (exspecially in (junior) high school textbooks) to organize
46 exercises in columns counting horizontally rather than vertically. That is
47 what \code{tasks} primarily is for. If you don't need this feature you're
48 better off using traditional \LaTeX\ lists and the \pkg{enumitem} package for
49 customization.
50
51 \subsection{Changes}
52 The \sinceversion{1.0} step to version~1.0 brought some significant changes:
53 \begin{itemize}
54 \item the option \option{counter-format} is deprecated. Labels can now be
55 set quite similar to the way they are set in \pkg{enumitem}. This also
56 made the \code{enumerate} option of the list template superfluous which has
57 been removed accordingly.
58 \item The commands \cs{NewTasks} and \cs{RenewTasks} have been renamed.
59 \item The multiple choice lists have been removed.
60 \item Custom definitions can be put in a \code{tasks.cfg} file which is
61 automatically loaded if available.
62 \end{itemize}
63
64 \section{License and Requirements}\label{sec:license}
65 \license
66
67 \Tasks\ requires the \bnd{l3kernel}~\cite{bnd:l3kernel} bundle,
68 \needpackage{xparse} and \pkg{xtemplate}.
69
70 \section{How it works}
71 \subsection{Background}
72 The \env{tasks} environment is similar to a list like \env{enumerate} but not
73 the same. Here are some of the differences:
74 \begin{tasks}[style=enumerate]
75 \task there is no pagebreak possible inside an item but only between items.
76 \task the enumeration default is a), b), c) \ldots
77 \task the body of the \env{tasks} environment is split at \emph{every}
78 occurrence of the item separator. For this reason the default separator
79 is not \cs*{item} but \cs{task} so it is unique to this environment only.
80 This directly leads to\ldots
81 \task \ldots\ the fact that the \env{tasks} environment cannot be nested.
82 You can, however, use an \env*{itemize} environment or another
83 \enquote{real} list in it.
84 \task A fifth difference: verbatim material cannot be used in it. You'll
85 have to use \cs*{string}, \cs*{texttt} or \cs*{detokenize}. If this
86 won't suffice then don't use \env{tasks}.
87 \end{tasks}
88
89 \begin{bewareofthedog}
90 The environments of \Tasks\ are what I like to call
91 \enquote{pseudo-environments}. This means like environments defined by the
92 package \pkg{environ}~\cite{pkg:environ} the body of the environment is read
93 as argument before it is processed. This is why verbatim material cannot be
94 used in \Tasks' lists.
95 \end{bewareofthedog}
96
97 \subsection{The Basics}
98 \begin{environments}
99 \environment{tasks}[\oarg{options}\darg{num of columns}]
100 List like environment where the single items are introduced with
101 \cs{task}.
102 \end{environments}
103 Let's see an example:
104 \begin{example}
105 % \Sample is defined to contain some sample text:
106 % \def\sample{This is some sample text we will use to create a somewhat
107 % longer text spanning a few lines.}
108 % \def\Sample{\sample\ \sample\par\sample}
109 Some text before the list.
110 \begin{tasks}
111 \task \Sample
112 \task \Sample
113 \task \Sample
114 \end{tasks}
115 And also some text after it.
116 \end{example}
117
118 The environment takes the optional argument \darg{num of columns} with which
119 the number of columns used by the environment is specified.
120 \begin{example}
121 \begin{tasks}(2)
122 \task \Sample
123 \task \sample\ \sample
124 \task \sample
125 \task \Sample
126 \task \sample\par\sample
127 \end{tasks}
128 \end{example}
129
130 \subsection{Items Spanning More Than One Column}
131 Sometimes it may come in handy if an item is allowed to span more than one
132 column. \Tasks\sinceversion{0.10} supports items using the remaining space by
133 adding an optional\label{optional-star} star to \cs{task}:
134 \begin{example}
135 \begin{tasks}(3)
136 \task \sample
137 \task* \sample
138 \task* \sample
139 \task \sample
140 \task \sample
141 \end{tasks}
142 \end{example}
143
144 \Tasks\sinceversion{0.10} also supports items that span \emph{all} columns in
145 any case by adding an optional bang\label{optional-bang} to \cs{task}.
146 \begin{example}
147 \begin{tasks}(3)
148 \task \sample
149 \task! \sample
150 \task! \sample
151 \task \sample
152 \task \sample
153 \end{tasks}
154 \end{example}
155
156 The optional star has itself an optional argument with parentheses where you
157 can specify the number of columns the item is supposed to span:\label{debug}
158 \begin{example}
159 \settasks{debug}
160 \begin{tasks}(4)
161 \task the first
162 \task the second
163 \task the third
164 \task the fourth
165 \task*(3) the fifth item is way too long for this and needs three columns
166 \task the sixth
167 \task the seventh
168 \task*(2) the eighth item is way too long for this and needs two columns
169 \task the nineth
170 \task the tenth
171 \end{tasks}
172 \end{example}
173 If there are not enough columns left (say two columns but you said
174 \cs{task}\sarg\Darg{3}) the argument is ignored and the maximum number of
175 remaining columns is used (two in case of our example).
176
177 Both optional star and optional bang can be combined with the optional
178 argument for a custom label:
179 \begin{example}
180 \begin{tasks}(3)
181 \task \sample
182 \task* \sample
183 \task*[(x)] \sample
184 \task \sample
185 \task \sample
186 \end{tasks}
187 \end{example}
188
189 Forcing a new item line manually is also possible\sinceversion{0.9} using the
190 following command:
191 \begin{commands}
192 \command{startnewitemline}
193 Introduce a new line in a \env{tasks} environment.
194 \end{commands}
195 While this works it also needs a bit of care since the width of the items
196 doesn't change which means in order to use the full width you'd have to use
197 trickery like \cs*{rlap} which then means the danger of the item text sticking
198 into the margin.
199
200 \begin{example}
201 \begin{tasks}(4)
202 \task the first
203 \task the second
204 \task the third
205 \task the fourth
206 \task \rlap{the fifth item is way too long for this so we start a new row}
207 \startnewitemline
208 \task the sixth
209 \task the seventh
210 \task \rlap{the eighth item also is too long} \startnewitemline
211 \task the nineth
212 \task the tenth
213 \end{tasks}
214 \end{example}
215
216 \section{Available Options}\label{sec:tasks:options}
217
218 The \Tasks\ package does not have any package options\changedversion{0.10}.
219
220 The environment \env{tasks} has a number of options, though, namely the
221 following ones that can be set using a setup command:
222 \begin{commands}
223 \command{settasks}[\marg{options}]
224 Setup command for \Tasks.
225 \end{commands}
226 \begin{options}
227 \keyval{style}{instance}\Default
228 Choose the instance to be used. Read more on this in
229 section~\ref{sec:tasks}.
230 \keyval{label-format}{code}\Default
231 \changedversion{1.1a}Can be used to apply a formatting like, \eg,
232 \cs*{bfseries} to the labels. This may be code accepting the item as
233 mandatory argument.
234 \keyval{label}{code}\Default{\cs*{alph}\code{*)}}
235 \changedversion{1.0}Sets a custom label. The \code{*} is replaced by
236 \Marg{task}. This is heavily inspired by
237 \pkg{enumitem}'s~\cite{pkg:enumitem} \code{label} option.
238 \keyval{ref}{code}\Default
239 \sinceversion{1.3}Works like \option{label} but sets the output of the
240 reference by setting \cs*{the\meta{counter}} (\cs{thetask} in the default
241 setting).
242 \keyval{label-width}{dim}\Default{1em}
243 Sets the width of the item labels.
244 \keyval{label-offset}{dim}\Default{.3333em}
245 \sinceversion{0.7}Sets the offset, \ie, the distance between label and
246 item.
247 \keyval{item-format}{code}\Default
248 \sinceversion{0.11}Can be used to apply a formatting like, \eg,
249 \cs*{bfseries} to the items. This may be code accepting the item as
250 mandatory argument.
251 \keyval{item-indent}{dim}\Default{2.5em}
252 \sinceversion{0.9a}The indent of an item, \ie, the horizontal space
253 available for both label and label-offset. If
254 \[
255 \text{\code{indent}} =
256 \text{\code{label-width}} + \text{\code{label-offset}}
257 \]
258 the label will align with the textblock above (if
259 \keyis{label-align}{left} is set). Please see figure~\ref{fig:lengths}
260 for a sketch of the available lengths and how they are set.
261 \keyval{column-sep}{dim}\Default{0pt}
262 \sinceversion{0.10}A horizontal length that is inserted between columns ot
263 items.
264 \keychoice{label-align}{left,right,center}\Default{left}
265 \sinceversion{0.7}Determines how the labels are aligned within the
266 label-box whose width is set with \option{label-width}.
267 \keyval{before-skip}{skip}\Default{\cs*{topsep}}
268 \changedversion{1.4}Sets the skip before the list.
269 \keyval{after-skip}{skip}\Default{\cs*{topsep}}
270 \changedversion{1.4}Sets the skip after the list.
271 \keyval{after-item-skip}{skip}\Default{\cs*{itemsep}}
272 \changedversion{1.4}This vertical skip is inserted between rows of items.
273 \keybool{resume}\Default{false}
274 The enumeration will resume from a previous \env{tasks} environment. In
275 order to use this option properly you shouldn't mix different \env{tasks}
276 environments that both count their items.
277 \keyval{start}{integer}\Default{1}
278 \sinceversion{1.1}Set the starting value with which the list starts
279 counting.
280 \keyval{counter}{counter}\Default{task}
281 \sinceversion{1.2}The counter to be used to count the items.
282 \keybool{debug}\Default{false}
283 \sinceversion{0.10}If set to true \cs*{fboxsep} is set to \code{0pt}
284 inside the \env{tasks} environment and \cs*{fbox} is used to draw a frame
285 around the label boxes and the item boxes.
286 \end{options}
287
288 \begin{figure}
289 \centering
290 \begin{tikzpicture}[every node/.style={font=\footnotesize},scale=.5]
291 \coordinate (itemedge1) at (2,2) ;
292 \coordinate (itemedge2) at (13,2) ;
293 \draw
294 (itemedge1) -- ++(8,0) -- ++(0,-2) -- ++(-8,0) -- cycle ;
295 \draw
296 (itemedge1) ++(-.5,0) coordinate(labeledge1)
297 -- ++(-1,0) --++ (0,-1) --++(1,0) --++(0,1) ;
298 \draw (itemedge1) ++(-2,0) -- ++(0,-2) ;
299 \draw
300 (itemedge2) -- ++(8,0) -- ++(0,-2) -- ++(-8,0) -- cycle ;
301 \draw
302 (itemedge2) ++(-.3,0) coordinate(labeledge2)
303 -- ++(-1,0) --++ (0,-1) --++(1,0) --++(0,1) ;
304 \draw (itemedge2) ++(-2,0) -- ++(0,-2) ;
305 \draw[<->] (itemedge2) ++(-2,0) --node[above]{column sep} ++(-1,0) ;
306 \draw[<->] (0,-.5) --node[below]{item indent} (2,-.5) ;
307 \draw[<->] (2,-.5) --node[below]{item width} (10,-.5) ;
308 \draw[<->] (labeledge1) ++(0,1) --node[above]{label width} ++(-1,0) ;
309 \draw[<->] (labeledge1) --node[above]{label offset} ++(.5,0) ;
310 \end{tikzpicture}
311 \caption{A visual representation of the used lengths.}
312 \label{fig:lengths}
313 \end{figure}
314
315 Now the same list as above but with three columns and a different label:
316 \begin{example}
317 \begin{tasks}[label=(\roman*),label-width=4ex](2)
318 \task \Sample
319 \task \sample\ \sample
320 \task \sample
321 \task \Sample
322 \task \sample\par\sample
323 \end{tasks}
324 \end{example}
325
326 Let's use it inside a question, \ie, inside \pkg{xsim}'s \env{exercise}
327 environment~\cite{pkg:xsim}:
328 \begin{example}
329 % since settings are local the following ones will be lost
330 % outside this example;
331 \settasks{
332 label = \theexercise.\arabic* ,
333 item-indent = 2em ,
334 label-width = 2em ,
335 label-offset = 0pt
336 }
337 \begin{exercise}
338 I have these two tasks for you. Shall we begin?
339 \begin{tasks}(2)
340 \task The first task: easy!
341 \task The second task: even more so!
342 \end{tasks}
343 \end{exercise}
344 \begin{solution}[print]
345 Now, let's see\ldots\ ah, yes:
346 \begin{tasks}
347 \task This is the first solution. Told you it was easy.
348 \task This is the second solution. And of course you knew that!
349 \end{tasks}
350 \end{solution}
351 \end{example}
352
353 Finally let's see what the \option{debug} option does (you could see it
354 already on page~\pageref{debug}):
355 \begin{example}
356 \settasks{debug}
357 \begin{tasks}(2)
358 \task \Sample
359 \task \Sample
360 \end{tasks}
361 \end{example}
362
363 \section{Available Instances}\label{sec:tasks:instances}
364 There are currently three additional instances for the \code{tasks} object
365 available:
366 \begin{description}
367 \item[itemize] uses \cs*{labelitemi} as labels.
368 \item[enumerate] enumerates the items with 1., 2., \ldots
369 % \item[multiplechoice] a --~well~-- `multiple choice' list.
370 \end{description}
371 \begin{example}
372 \begin{tasks}[style=itemize](2)
373 \task that's just how\ldots
374 \task \ldots we expected
375 \end{tasks}
376 \begin{tasks}[style=enumerate](2)
377 \task that's just how\ldots
378 \task \ldots we expected
379 \end{tasks}
380 \end{example}
381 % \begin{tasks}[style=multiplechoice](2)
382 % \task that's just how\ldots
383 % \task \ldots we expected
384 % \end{tasks}
385
386 \section{Custom Labels}
387 If you want to change a single label inside a list, you can use the optional
388 argument of \cs{task}. This will temporarily overwrite the default label.
389 \begin{example}[side-by-side]
390 \begin{tasks}[style=itemize]
391 \task a standard item
392 \task another one
393 \task[+] a different one
394 \task and another one
395 \end{tasks}
396 \end{example}
397
398 You've already seen examples for the \option{label} option.
399 \begin{options}
400 \keyval{label}{code}\Default{\cs*{alph}\code{*)}}
401 It can be used to set the label for a list. A \code{*} inside is always
402 replaced by the current counter name inside braces. It can contain
403 formatting instructions like \cs*{bfseries} but it can be cleaner to use
404 \keyval{label-format}{code}\Default
405 instead. This is especially true since the \option{label} also sets
406 \cs*{the\meta{counter}} where you usually don't want to have formatting
407 instructions. Another way to deal with this issue is the option
408 \keyval{ref}{code}\Default
409 which sets \cs*{the\meta{counter}} (\cs{thetask} in the default setting).
410 \end{options}
411
412 \begin{example}[side-by-side]
413 \begin{tasks}[label=\arabic*.,ref=\arabic*]
414 \task first item
415 \task second item \label{foo}
416 \end{tasks}
417 See item~\ref{foo} without dot.
418 \end{example}
419
420 Two additional commands are defined which in some circumstances might prove
421 useful:
422 \begin{commands}
423 \command{tasksifmeasuringTF}[\marg{true}\marg{false}]
424 \sinceversion{1.2}This command used inside a label checks if the label is
425 typeset for measuring its width or if it is typeset \enquote{for
426 real}. There are also the variants \cs{tasksifmeasuringT} and
427 \cs{tasksifmeasuringF}.
428 \command{tasklabel}
429 \sinceversion{1.3}Holds the current label text.
430 \end{commands}
431
432 \section{New \code{tasks}-like Environments}
433 It is possible to add custom environments that work like the \code{tasks}
434 environment.
435 \begin{commands}
436 \command{NewTasksEnvironment}[\oarg{options}\marg{name}\oarg{separator}\darg{cols}]
437 Define environment \meta{name} that uses \meta{separator} to introduce a
438 new item. Default for \meta{separator} is \cs{task}, default for
439 \meta{cols} is \code{1}. The \meta{options} are the ones described in
440 section~\ref{sec:tasks:options}.
441 \command{RenewTasksEnvironment}[\oarg{options}\marg{name}\oarg{separator}\darg{cols}]
442 Renew environment previously defined with \cs{NewTasksEnvironment}.
443 \end{commands}
444 The \env{tasks} environment is defined as follows:
445 \begin{sourcecode}
446 \NewTasksEnvironment{tasks}
447 \end{sourcecode}
448
449 The separator does not have to be a control sequence:
450 \begin{example}
451 % preamble:
452 % \usepackage{fontawesome}
453 \NewTasksEnvironment[label=\faThumbsOUp,label-width=15pt]{done}[*]
454 \begin{done}
455 * First task
456 * Second task
457 \end{done}
458 \end{example}
459 Although this might seem handy or even nice I strongly advice against using
460 something different than a command sequence. Remember that the items will be
461 split at \emph{every} occurrence of the separator. So in order to use the
462 separator (here for example for a starred variant of a command) within an item
463 it has to be hidden in braces. This is avoided of you use a command sequence
464 which even doesn't have to be defined.
465
466 Please also keep in mind that the separator still has an optional star
467 argument (see~\pageref{optional-star}), an optional bang argument and the
468 standard optional argument. Using \code{*} will prevent the optional star
469 argument.
470
471 \begin{example}
472 % preamble:
473 % \usepackage{fontawesome}
474 \NewTasksEnvironment[label=\faThumbsOUp,label-width=15pt]{done}[*]
475 \begin{done}(3)
476 * First task
477 * Second task
478 *! Third task spanning the full width available
479 * Fourth task
480 \end{done}
481 \end{example}
482
483 \section{Styling \Tasks}
484 \Tasks\ uses \pkg{xtemplate} to declare additional instances for the lists.
485
486 \subsection{The \code{tasks} Object}\label{sec:tasks}
487 The object that's defined by \Tasks\ is the `tasks' object. This time there
488 are four instances available for the one template (again `default') that was
489 defined.
490
491 \subsubsection{Available Options}
492 This section only lists the options that can be used when defining an instance
493 of the `default' template. The following subsections will give some examples
494 of their usage.
495
496 \begin{sourcecode}
497 \DeclareTemplateInterface{tasks}{default}{3}
498 {
499 % option : type = default
500 label : tokenlist = \alph*) ,
501 indent : length = 2.5em ,
502 label-format : tokenlist ,
503 label-width : length = 1em ,
504 label-offset : length = .3333em ,
505 after-item-skip : skip = \itemsep
506 }
507 \end{sourcecode}
508
509 \subsubsection{Predefined Instances}
510 This is rather brief this time:
511 \begin{sourcecode}
512 % alphabetize: a) b) c)
513 \DeclareInstance{tasks}{alphabetize}{default}{}
514 % itemize
515 \DeclareInstance {tasks} {itemize} {default}
516 {
517 label-width = 1.125em ,
518 label = \labelitemi
519 }
520 % enumerate:
521 \DeclareInstance {tasks} {enumerate} {default}
522 { label = \arabic*. }
523 \end{sourcecode}
524
525 \printbibliography
526
527 \end{document}