Debian Codegraph @

texmf-dist/doc/latex/dataref/dataref-doc.tex

raw
1 % Copyright (c) 2013-2017 Christian Dietrich
2 %
3 % This work may be distributed and/or modified under the
4 % conditions of the LaTeX Project Public License, either version 1.3
5 % of this license or (at your option) any later version.
6 % The latest version of this license is in
7 % http://www.latex-project.org/lppl.txt
8 % and version 1.3 or later is part of all distributions of LaTeX
9 % version 2005/12/01 or later.
10 %
11 % This work has the LPPL maintenance status `maintained'.
12 %
13 % The Current Maintainer of this work is Christian Dietrich
14 %
15 % This work consists of the files dataref.tex and dataref.sty
16
17 \documentclass{ltxdoc}
18 \usepackage[usagereport]{dataref}[2019/02/01]
19
20 \EnableCrossrefs
21 \CodelineIndex
22 \RecordChanges
23
24 \usepackage{verbatim}
25 \usepackage{listings}
26 \usepackage{pdfcomment}
27 \usepackage{siunitx}
28 \usepackage{xspace}
29 \usepackage{pgffor}
30 \usepackage{filecontents}
31 \usepackage{tikz}
32 \usetikzlibrary{positioning, arrows}
33
34 \begin{filecontents}{datapoints.tex}
35 \drefset{/control group/mice race}{Black Six}
36 \drefset{/control group/mice count}{32}
37 \drefset{/control group/dead after 24h}{4}
38 \drefset{/control group/dead after 48h}{7}
39 \drefset{/control group/recovered}{21}
40
41 \drefset{/med A/mice race}{Black Six}
42 \drefset{/med A/mice count}{32}
43 \drefset{/med A/dead after 24h}{6}
44 \drefset{/med A/dead after 48h}{12}
45 \drefset{/med A/recovered}{20}
46
47 \drefsethelp{.*/mice race}{The mice race used for experiments heavily
48 influences the outcome of the results}
49
50 \drefsethelp{.*/(dead after|recovered)}{Of all infected mice, a
51 certain number died within a specified period of time. A certain
52 recovered from the infection. The dead categories are cumulative and
53 include all dead mice before.}
54 \end{filecontents}
55 \input{datapoints}
56 % \OnlyDescription
57 \drefkeys{prefix=/foo,value=123,save=/foo}
58 \drefset{/override test}{2}
59 \begin{document}
60 \drefsave{/override test}{4}
61 \drefkeys{prefix=}
62
63 \parskip=1ex
64 \parindent=0pt
65
66 \CheckSum{0}
67
68
69 \CharacterTable
70 {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
71 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
72 Digits \0\1\2\3\4\5\6\7\8\9
73 Exclamation \! Double quote \" Hash (number) \#
74 Dollar \$ Percent \% Ampersand \&
75 Acute accent \' Left paren \( Right paren \)
76 Asterisk \* Plus \+ Comma \,
77 Minus \- Point \. Solidus \/
78 Colon \: Semicolon \; Less than \<
79 Equals \= Greater than \> Question mark \?
80 Commercial at \@ Left bracket \[ Backslash \\
81 Right bracket \] Circumflex \^ Underscore \_
82 Grave accent \` Left brace \{ Vertical bar \|
83 Right brace \} Tilde \~}
84
85
86 \changes{v0.7}{2019/02/15}{Fix math backends, \cmd{\drefinput}}
87 \changes{v0.6}{2016/11/15}{Units, Unit Scaling, general overhaul}
88 \changes{v0.4}{2015/04/21}{Remove Spurious Whitespaces}
89 \changes{v0.1}{2013/12/06}{Initial version}
90
91 \DoNotIndex{\newcommand,\newenvironment}
92
93 \makeatletter
94 \def\colorfirsttoken#1#2{\bgroup\expandafter\color{#1}\cmd{#2}\egroup}
95 \def\Macro@Name#1#2\@nnil{\string#1}
96
97 \renewcommand{\meta}[1]{\bgroup\color{green!40!black}$\langle$\textit{#1}$\rangle$\egroup}
98 \newcommand{\Macro}[2][]{%
99 \noindent\hspace{-\marginparwidth}%
100 \hypertarget{\Macro@Name#2\@nnil}{%
101 \mbox{\colorfirsttoken{blue!50!black}#2}} \hfill\mbox{#1}\par}
102 \newcommand{\Option}[2][]{%
103 \noindent\hspace{-\marginparwidth}%
104 \mbox{\color{red!50!black}#2} \hfill\mbox{#1}\par}
105
106 \newcommand{\option}[1]{%
107 \bgroup\color{red!50!black}#1\egroup\xspace
108 }
109
110 \renewcommand{\macro}[1]{%
111 \hyperlink{\Macro@Name#1\@nnil}{\bgroup\color{blue!50!black}\cmd#1\egroup}\xspace
112 }
113 \makeatother
114
115 \colorlet{examplefill}{yellow!80!black}
116 \definecolor{codebackground}{rgb}{0.9,0.9,1}
117 \newdimen\examplewidth
118 \newsavebox{\codebox}
119 \newenvironment{example}[1][\marginparwidth-12pt]
120 {\begin{lrbox}{\codebox}\begin{minipage}{#1-2\fboxsep}}
121 {\end{minipage}\end{lrbox}%
122 \examplewidth=\wd\codebox%
123 \addtolength{\examplewidth}{-\marginparwidth+15pt}%
124 \global\examplewidth=\examplewidth%
125 \noindent\hspace{-\marginparwidth}\colorbox{examplefill}{\usebox{\codebox}}\hspace{12pt}}
126
127 \newenvironment{codeexample}
128 {\begin{lrbox}{\codebox}\begin{minipage}{\textwidth-\examplewidth-2\fboxsep}}
129 {\end{minipage}\end{lrbox}\noindent\colorbox{codebackground}{\usebox{\codebox}}\global\examplewidth=0pt%
130 \par\vspace{1em}}%
131
132
133 \newcommand{\dataref}{\textsc{dataref}\xspace}
134 \providecommand*{\url}{\texttt}
135 \GetFileInfo{dataref.sty}
136 \title{The \textsf{dataref} package}
137 \author{Christian Dietrich 2013-2016\\ \url{[email protected]}\\
138 \url{https://github.com/stettberger/dataref}}
139 \date{\filedate~\fileversion}
140
141 \maketitle
142
143 \section{Introduction}
144
145 Writing scientific texts is a craft. It is the craft of communicating your results to your
146 colleagues and to the curious world public. Often your conclusions are based upon facts and
147 numbers that you gathered during your research for the specific topic. You might have done many
148 experiments and produced lot of data. The craft of writing is to guide your reader through a
149 narrative that is based upon that data. But there may be many versions of that data. Perhaps you
150 found a problem in your experiment, while already writing, that forces you back into the
151 laboratory. After a while, the moon has done its circle many times, you return from that dark
152 place and your methodology has improved as significantly as your data has. But now you have to
153 rewrite that parts of the data that reference the old data points.
154
155 The \textsf{dataref} is here to help you with managing your data points. It provides you with
156 macro style keys that represent symbolic names for your data points. You can reference those
157 symbolic names with \macro{\dref}, use them in calculations to have always up-to-date percentage
158 values, define projections between sets of data points and document them. \textsf{dataref} also
159 introduces the notion of assertions (\macro{\drefassert}) for your results to ensure that your prosa
160 text references fit the underlying data.
161
162 \section{Usage (or \dref*{/control group/mice count} mice)}
163
164 \begin{example}
165 From the \dref{/med A/mice count} mice in the experiment, \drefcalc[prefix=/med A]{d(/mice
166 count)-d(/recovered)} died.
167 \end{example}
168 \begin{codeexample}
169 \verb|\drefset{/med A/mice count}{32}|\\
170 \verb|\drefset{/med A/recovered}{20}|\\
171 \verb|From the \dref{/med A/mice count} mice in the experiment, |\\
172 \verb|\drefcalc[prefix=/med A]{d(/mice count)-d(/recovered)} died.|
173 \end{codeexample}
174
175 \subsection{Design Principles}
176
177 Before we jump into the description of \dataref, let us look a little bit into the design principles of \dataref. By
178 understanding the principles, you will be more productive and embedding data into your document will become easier.
179
180 First of all, \dataref is built on top of \textsf{pgfkeys} and \textsf{pgfmath} from the PGF/TiKZ macro packages. While
181 the former provides a usable user interface to provide options to \dataref, the later is used to perform computation on
182 your datapoints. If you are interested into these two excellent \TeX{} packages, please look at \texttt{texdoc
183 pgfmanual} for further information.
184
185 There are two aspects of \dataref: setting datapoints and referencing datapoints. While setting datapoints is kind of
186 boring, we have a wide variety of options when it comes to referencing. The expansion of datapoints is done in
187 multiples phases (see Figure~\ref{fig:pipeline}).
188
189
190 \begin{figure}[t]
191 \begin{tikzpicture}[node distance=0.5cm]
192 \tikzstyle{phase}=[draw,minimum width=1.5cm, fill=green!20!white];
193 \tikzstyle{desc}=[align=left, text width=3cm,anchor=#1,draw];
194
195
196 \node[phase](@init){@init};
197 \node[phase,right=of @init](@options){@options};
198 \node[phase,right=of @options](@get){@get};
199 \node[phase,right=of @get](@calc){@calc};
200 \node[phase,right=of @calc](@print){@print};
201 \node[phase,right=of @print](@set){@set};
202
203 \draw[>=latex']
204 (@init) edge[->] (@options)
205 (@options) edge[->] (@get)
206 (@get) edge[->] (@calc)
207 (@calc) edge[->] (@print)
208 (@print) edge[->] (@set);
209
210 \draw[ultra thin,shorten <=2pt] (@init) -- ++(75:1cm)
211 node[desc=south] {Set up a clean working environment.};
212
213 \draw[ultra thin,shorten <=2pt] (@options) -- ++(-140:1.5cm)
214 node[desc=north] {Parse the user-defined options and fill up all subsequent phases.};
215
216 \draw[ultra thin,shorten <=2pt] (@get) -- ++(95:1cm)
217 node[desc=south] {Load the main datapoint into \macro{\drefresult} and reference it.};
218
219 \draw[ultra thin,shorten <=2pt] (@calc) -- ++(-140:1.5cm)
220 node[desc=north] {Perform calculations on the main datapoint, including unit scaling.};
221
222 \draw[ultra thin,shorten <=2pt] (@print) -- ++(95:1.5cm)
223 node[desc=south] {Format and insert the result into the document body.};
224
225 \draw[ultra thin,shorten <=2pt] (@set) -- ++(-140:1.5cm)
226 node[desc=north] {Save the result as a datapoint or macro.};
227
228 \end{tikzpicture}
229 \caption{The \dataref Pipeline}\label{fig:pipeline}
230 \end{figure}
231
232 The \dataref macros are different regarding the phases they include or omit and in their default settings. In the
233 following, we will discuss all options and macros you can use to reference your datapoints. By default, the
234 \macro{\drefresult} is always set to the result of the pipeline.
235
236 \subsection{Setting Datapoints}
237
238
239
240 \Macro[(@set)]{\drefset\oarg{options}\{\meta{name}\}\{\meta{value}\}}
241
242
243 \begin{codeexample}
244 \begin{verbatim}
245 \drefset{/med A/mice race}{Black Six}
246 \drefset{/med A/mice count}{32}
247 \drefset{/med A/dead after 24h}{6}
248 \drefset{/med A/dead after 48h}{1}
249 \end{verbatim}
250 \end{codeexample}
251
252
253 The \macro{\drefset} command is used to define the symbolic datapoints. The name of a datapoint may contain virtually all
254 characters, including spaces and slashes. It is good practice to use a hierarchy to structure your data point names.
255 The value might be any string, while the focus of \dataref is on numerical datapoints. The \macro{\drefset} command works
256 outside the pipeline model (Figure \ref{fig:pipeline}) for performance reasons. It virtually consists only of the
257 @options and @set stage.
258
259 \Macro[(@set)]{\drefsave[\meta{options}]\{\meta{name}\}\{\meta{value}\}}
260
261 Besides setting the datapoint, \macro{\drefsave} writes it to the \textsc{aux} file and, therefore, makes it available in
262 the next \LaTeX{} run from the very beginning. The \option{ignoremissing} option is useful to reference the saved keys
263 at an earlier place in the document.
264
265 \Option[(no default)]{/dref/set=\meta{key}}
266
267 Inserts a \macro{\drefset} to the @set that captures the current result and saves it to the given datapoint.
268
269 \Option[(no default)]{/dref/save=\meta{key}}
270
271 Inserts a \macro{\drefsave} to the @set that captures the current result and saves it to the given datapoint. Since
272 \macro{\drefsave} is used the result is available from the beginning of the document.
273
274 \Option[(no default)]{/dref/to macro=\meta{macro}}
275
276 The current result is saved to the given macro.
277
278 \begin{example}[2cm]
279 \dref[set=/foo]{/med A/mice count} \dref{/foo}\\
280 \dref[ignoremissing]{/bar} \dref[save=/bar]{/med A/mice count}\\
281 \drefcalc*[to macro=\myresult]{3+2} \myresult
282 \end{example}
283 \begin{codeexample}
284 \begin{verbatim}
285 \dref[set=/foo]{/med A/mice count} \dref{/foo}\\
286 \dref[ignoremissing]{/bar} \dref[save=/bar]{/med A/mice count}\\
287 \drefcalc*[to macro=\myresult]{3+2} \myresult
288 \end{verbatim}
289 \end{codeexample}
290
291
292 \Option[(no default, initially "")]{/dref/prefix=\meta{key prefix}}
293
294 On every key retrieval or setting of a datapoint this prefix is added.
295 It is a value-typed PGF key, so operations like
296 \texttt{prefix/.append} are possible.
297
298 \Macro{\drefinput[\meta{prefix}]\{\meta{filename}\}}
299
300 Reads in the given \TeX/dataref file with the given key prefix. Therefore, all included \cmd{\drefset} commands are define their keys with the given prefix.
301 This is useful to include several files that resulted from different experiments but include equal datapoint keys.
302
303 This command uses \cmd{\subimport} from the \texttt{import} package to read the file.
304 Hence, if there is an \cmd{\drefinput} in an included file, it search its filename relative to its own directory.\footnote{In former versions, \cmd{\drefinput} relied directly on \cmd{\input} and, therefore, the filename was interpreted relative to the root file.}.
305
306
307 \subsection{Referencing Datapoints}
308
309
310 \Macro[(@options=\{print=default\}, @get, @calc, @print, @set)]{\dref*[\meta{options}]\{\meta{name}\}}
311 \Macro[(@options=\{print=raw\}, @get, @calc, @print, @set)]{\dref[\meta{options}]\{\meta{name}\}}
312
313 This macro is used to reference a single symbolic data point. The value stored in that datapoint is inserted into the
314 text. \macro{\dref} additionally marks the data point as used; it will appear in the datagraphy (see
315 Section~\ref{sec:datagraphy}). The starred variant does not attempt to parse the datapoint as a numerical value, but
316 outputs the saved string.
317
318 \begin{example}
319 \dref*{/control group/mice race}\\
320 \dref*{/control group/mice count}\\
321 \dref[sci,precision=2,zerofill=true]{/med A/recovered}
322 \end{example}
323 \begin{codeexample}
324 \begin{verbatim}
325 \dref*{/control group/mice race}\\
326 \dref*{/control group/mice count}\\
327 \dref[sci,precision=2,zerofill=true]{/med A/recovered}
328 \end{verbatim}
329 \end{codeexample}
330
331 \Macro[(@get, @print)]{\drefvalueof\{\meta{name}\}}
332 \Macro[(@get)]{\drefref\{\meta{name}\}}
333 \vspace{1em}
334
335 \begin{example}
336 \drefvalueof{/med A/mice race}
337 \end{example}\begin{codeexample}
338 \begin{verbatim}
339 \drefvalueof{/med A/mice race}
340 \end{verbatim}
341 \end{codeexample}
342
343 Since \macro{\dref} is not expandable, it cannot be used in all circumstances. Therefore, \macro{\drefvalueof} bypasses
344 all internal bookkeeping and provides access to the raw datapoint value. \macro{\drefref} can be used to mark the
345 datapoint as used to let it appear in the datagraphy.
346
347 \Option[(default \textbf{true}, initially \textbf{false})]{/dref/ignoremissing=\meta{true-or-false}}
348 \Option[(no default, initially \textbf{1.0})]{/dref/defaultvalue=\meta{value}}
349
350 By default, \dataref produces an error if the referenced datapoint is undefined. If ignoremissing is given, the
351 defaultvalue is used. This key is useful in combination with \macro{\drefsave}. Furthermore, it is possible to extract the
352 missing keys from the \textsc{aux} file and to retrieve it from a secondary source (e.g. database, wikidata, etc).
353
354 \begin{example}
355 \dref*[ignoremissing,defaultvalue=undefined]{blah}
356 \end{example}\begin{codeexample}
357 \begin{verbatim}
358 \dref*[ignoremissing,defaultvalue=undefined]{blah}
359 \end{verbatim}
360 \end{codeexample}
361
362 \Macro{\drefsethelp\{\meta{pattern}\}\{\meta{text}\}}
363 \Macro{\drefhelp\{\meta{name}\}}
364
365 \textsf{dataref} comes with a simple method for defining documentation for data points. This help can for example be used to communicate what is the concrete semantics of the data point. This is of special interest when writter and data gatherer are not the same person. \macro{\drefsethelp} takes two arguments: first a regular expression that matches the symbolic data point, second the help text.
366
367 \begin{codeexample}
368 \begin{verbatim}
369 \drefsethelp{.*/mice race}{The mice race used for experiments
370 heavily influences the outcome of the results}
371 \end{verbatim}
372 \end{codeexample}
373
374 The documentation for a datapoint is obtained by using the \macro{\drefhelp} macro. It checks all defined documentation
375 strings (in linear order, first defined, first matched), and prints the first matching help text. With \textbf{LuaTeX}:
376 only Lua (string.find) regular expressions are supported as patterns.
377
378 \begin{example}
379 \drefhelp{/med A/mice race}
380 \end{example}\begin{codeexample}
381 \begin{verbatim}
382 \drefhelp{/med A/mice race}
383 \end{verbatim}
384 \end{codeexample}
385
386
387 \Macro{\drefresult}
388
389 Is set in the @set phase to the result of the currently executed pipeline.
390
391
392 \subsection{Calculations and Math Tools}
393
394 \Macro[(@calc, @print, @set)]{\drefcalc[\meta{options}]\{\meta{expression}\}}
395 \Macro[(@calc, @set)]{\drefcalc*[\meta{options}]\{\meta{expression}\}}
396 \Macro[(@print)]{\drefformat*[\meta{options}]\{\meta{number}\}}
397
398 The \macro{\drefcalc} is the core function of calculating with data points. It is based on the pgfmath engine, but allows
399 also the usage of symbolic datapoints within mathematical expressions. Datapoints can either are inserted into the
400 calculations with the \cmd{d(\meta{path})} or the \cmd{data("\meta{path}")} notation. The starred variant of
401 \macro{\drefcalc} does not print the result, but only sets the result macros.
402
403 It is important to note, that \macro{\drefcalc} always uses the \textbf{/pgf/fpu} environment. The FPU feature of pgfmath
404 is used to handle large numbers, which may occur often when handling experiment data points.
405
406 \begin{example}
407 \drefcalc{(4+7)/12 * 100}\\
408 \drefcalc{d(/med A/mice count) * 100}\\
409 \drefcalc{data("/med A/mice count") * 100}\\
410 \drefcalc*{1+3}\\
411 \drefresult
412 \end{example}\begin{codeexample}
413 \begin{verbatim}
414 \drefcalc{(4+7)/12 * 100}\\
415 \drefcalc{d(/med A/mice count) * 100}\\
416 \drefcalc{data("/med A/mice count") * 100}\\
417 \drefcalc*{1+3}\\
418 \drefresult
419 \end{verbatim}
420 \end{codeexample}
421
422 Since the default printing mechanism of \dataref utilizes PGF, all options from \texttt{/pgf/number format} can be
423 directly used in the options. \macro{\drefformat} does only the printing. For documentation on the available options,
424 please consult the PGF manual.
425
426 \begin{example}
427 \drefcalc[precision=4]{1/3}\\
428 \drefcalc[sci]{123456789}\\
429 \drefcalc[prefix=/med A/,frac]{d(recovered)/d(mice count)}\\
430 \drefformat[fixed zerofill, precision=2]{\drefresult}
431 \end{example}\begin{codeexample}
432 \begin{verbatim}
433 \drefcalc[precision=4]{1/3}\\
434 \drefcalc[sci]{123456789}\\
435 \drefcalc[prefix=/med A/,frac]{d(recovered)/d(mice count)}\\
436 \drefformat[fixed zerofill, precision=2]{\drefresult}
437 \end{verbatim}
438 \end{codeexample}
439
440 \subsection{Units and Unit Scaling}
441
442 \dataref allows to give the unit of a datapoint and enforces the correct combination of units when using them in
443 calculations. \dataref units can be arbitrary combinations of macros and strings, which allows the combination with the
444 \textsc{SIUnitX} package.
445
446 \Option[(no default)]{/dref/unit=\meta{unit}}
447
448 The unit of a datapoint is loaded in the @get phase, and stored in the @set phase of the \dataref pipeline.
449
450 \drefset[unit=\joule]{/power}{1234}
451 \drefset[unit=ms]{/duration}{5555}
452 \begin{codeexample}
453 \begin{verbatim}
454 \drefset[unit=ms]{/duration}{5555}
455 \drefset[unit=\joule]{/power}{1234}
456 \end{verbatim}
457 \end{codeexample}
458
459 \Option[(no default, choice)]{/dref/unit/format=\meta{formatting style}}
460 \Option[(initially \textbf{plain})]{/dref/unit/format default=\meta{formatting style}}
461
462
463 If a datapoint with unit is referenced, the unit is printed after the value. The formatting mechanism can be exchanged,
464 in order to omit the unit, or to use \textsc{SIUnitX} for properly print it. By default, the \texttt{unit/format
465 default} is set in the @init phase. If you are using \textsc{SIUnitX} in your document, it is safe to set the default
466 value accordingly. Currently, the values \texttt{false}, \texttt{plain}, and \texttt{siunitx} are valid formatting
467 styles.
468
469 \drefkeys{unit/format default=siunitx}
470 \begin{example}
471 \dref[unit/format=false]{/duration}; \dref{/duration};
472 \typeout{\pgfkeysvalueof{/dref/unit/format default}}
473 \dref{/power}
474 \end{example}\begin{codeexample}
475 \begin{verbatim}
476 \drefkeys{unit/format default=siunitx}
477 \dref[unit/format=false]{/duration}; \dref{/duration};
478 \dref{/power}
479 \end{verbatim}
480 \end{codeexample}
481
482 \Option[(no default)]{/dref/unit/new scala=\meta{scala}}
483
484 \dataref allows to define scaled units and conversion between the members of the scala. A scala definition is a list of
485 units with scaling factors between them.
486
487
488 \drefkeys{
489 unit/new scala={
490 1/y, 365/d, 24/h, 60/m, 60/s, 1000/ms, 1000/us, 1000/ns
491 },
492 unit/new scala={
493 1/\kilo\joule, 1000/\joule, 1000/\milli\joule,
494 1000/\micro\joule, 1000/\nano\joule
495 }
496 }
497
498 \begin{codeexample}
499 \begin{verbatim}
500 \drefkeys{
501 unit/new scala={
502 1/y, 365/d, 24/h, 60/m, 60/s, 1000/ms, 1000/us, 1000/ns
503 },
504 unit/new scala={
505 1/\kilo\joule, 1000/\joule, 1000/\milli\joule,
506 1000/\micro\joule, 1000/\nano\joule
507 }
508 }
509 \end{verbatim}
510 \end{codeexample}
511
512 \Option[(no default)]{/dref/unit/scale to=\meta{unit}}
513
514 With a defined scala, you can scale to any unit on that scala automatically. In the example, we use unit to set the unit
515 of plain value to nano joule, and scale everything to milli joule.
516
517 \begin{example}
518 \foreach \a in {1234, 4135413, 213516513245, 24} {%
519 \drefformat[unit=\nano\joule, unit/scale to=\milli\joule]{\a}\\
520 }
521 \end{example}\begin{codeexample}
522 \begin{verbatim}
523 \foreach \x in {1234, 4135413, 213516513245, 24} {%
524 \drefformat[
525 unit=\nano\joule,
526 unit/scale to=\milli\joule]{\x}\\
527 }
528 \end{verbatim}
529 \end{codeexample}
530
531 \Option[(default \textbf 50)]{/dref/unit/scale to auto=\meta{optimum number}}
532
533 With \texttt{scale to auto}, the appropriate unit is chosen automatically. The algorithm tries every unit on the scala
534 and chooses the unit, where the numerical value after scaling is nearest to the \meta{optimum number}. So with a optimum
535 number of 50, 5000 seconds are scaled to \drefformat[unit=s, unit/scale to auto]{5000} instead of \drefformat[unit=s,
536 unit/scale to=h]{5000}.
537
538
539 \begin{example}
540 \foreach \a in {1234, 4135413, 213516513245, 24} {%
541 \drefformat[unit=ms, unit/scale to auto]{\a}\\
542 }
543 \end{example}\begin{codeexample}
544 \begin{verbatim}
545 \foreach \x in {1234, 4135413, 213516513245, 24} {%
546 \drefformat[unit=ms, unit/scale to auto]{\x}\\
547 }
548 \end{verbatim}
549 \end{codeexample}
550
551
552 \subsection{Relating Datapoints}
553
554 \Macro[(@calc, @set)]{\drefrel*[\meta{options}]\{\meta{key or value}\}}
555 \Macro[(@calc, @print, @set)]{\drefrel[\meta{options}]\{\meta{key or value}\}}
556
557 Often, datapoints are set in relation to each other. This can either be done with \macro{\drefcalc} or, more explictily,
558 with \macro{\drefrel}. The different options that come along \macro{\drefrel}, add steps to the @calc phase and can,
559 therefore, be combinated with any other dref macro that includes the @calc phase.
560
561 All operations operate on the current result, which is initially the given key or value from the mandatory argument.
562
563 \begin{example}
564 \drefrel[percent of=123]{40}
565 \end{example}\begin{codeexample}
566 \begin{verbatim}
567 \drefrel[percent of=123]{40}
568 \end{verbatim}
569 \end{codeexample}
570
571 The different relation operations try to have a speaking name, such that the \TeX{} code is easily understandable by the
572 writer. This explicit notation aims to prevent common mistakes, like confusing denominator and numerator.
573
574 The starred version of \macro\drefrel does not print any number, but only saves the result in \macro\drefresult. Instead of
575 only taking datapoint keys, \macro\drefrel, as well as the relating operations, take either a key or a bare number as you can
576 see from the example.
577
578 \Option[(no default)]{/dref/scale by=\meta{key or value}}
579
580 Scales the current value by the given factor, which must be unit less. The resulting unit is untouched.
581
582 \Option[(no default)]{/dref/percent}
583
584 Scales the current value by 100. The unit is not changed.
585
586 \Option[(no default)]{/dref/negate}
587
588 Scales the current value by -1. The resulting unit is untouched.
589
590 \Option[(no default)]{/dref/divide by=\meta{key or value}}
591
592 Divides the current value by the given factor, which must be unit less. The resulting unit is untouched.
593
594
595 \Option[(no default)]{/dref/abs}
596
597 Calculate the absolute value.
598
599 \Option[(no default)]{/dref/factor of=\meta{key or value}}
600 \Option[(no default)]{/dref/percent of=\meta{key or value}}
601
602 The \textbf{factor of} operation gives the portion the current value in relation to the given base value. In easy words:
603 a division. This macro ensures, that base and current vale have the same unit or are unit less. The result of this
604 operation is unit less. The \textbf{percent of} operation, furthermore, scales the result with 100 to get a percentage.
605
606 \Option[(no default)]{/dref/increase from=\meta{key or value}}
607 \Option[(no default)]{/dref/decrease from=\meta{key or value}}
608 \Option[(no default)]{/dref/increase factor from=\meta{key or value}}
609 \Option[(no default)]{/dref/decrease factor from=\meta{key or value}}
610 \Option[(no default)]{/dref/increase percent from=\meta{key or value}}
611 \Option[(no default)]{/dref/decrease percent from=\meta{key or value}}
612
613 In a situation, where a datapoint is the result of a changed experiment setup, the value normally shows an increased or decrease
614 numerical value. This family of operations calculates this delta, assuming it is an increase or decrease. The factor
615 operations scale the result to the base value, and the percent operations give this scaled value as a percentage.
616
617 \begin{example}
618 \drefrel[increase from=500]{525}\\
619 \drefrel[increase factor from=500,fixed]{525}\\
620 \drefrel[increase percent from=500]{525}\,\%
621 \end{example}
622 \begin{codeexample}
623 \begin{verbatim}
624 \drefrel[increase from=500]{525}\\
625 \drefrel[increase factor from=500,fixed]{525}\\
626 \drefrel[increase percent from=500]{525}\,\%
627 \end{verbatim}
628 \end{codeexample}
629
630 \subsection{Helper Utilities}
631
632 \Macro{\drefrow[\meta{options}]\{\meta{comma-separated list}\}\{\meta{key template}\}}
633 \Macro{\drefrow*\{\meta{comma-separated list}\}\{\meta{template}\}}
634
635 Often different columns in a table have to be obtained from your data
636 points. Often those rows and columns are similar. Generating parts of
637 tables within \LaTeX is very tricky, so \dataref provides you
638 with \macro{\drefrow}. This macro iterates over a comma-separated list
639 of values and fills out a macro which is interpreted as a symbolic
640 data point. The entries are seperated with \& and printed. In the
641 starred variant the resulting text is not interpreted as symbolic
642 name, but as a macro.
643
644 Both, unstarred and starred variant take a template (a macro body) that is expanded once for every item in the given
645 list. The first replacement \verb|#1| is list item and the second \verb|#2| is the current index starting from 0. The
646 unstarred variant interprets the expanded result as a datapoint key and uses \macro\dref to expand it; the optional
647 parameter is passed through to every invocation of \macro\dref.
648 The starred variant does not wrap the result into \macro\dref, and, therefore, is more flexible.
649
650 \begin{example}
651 \begin{tabular}{|c|c|c|}\hline
652 \drefrow{dead after 24h,dead after 48h,recovered}%
653 {/control group/#1}\\\hline
654 \drefrow{dead after 24h,dead after 48h,recovered}%
655 {/med A/#1}\\\hline
656 \end{tabular}
657 \end{example}
658 \begin{codeexample}
659 \begin{verbatim}
660 \begin{tabular}{|c|c|c|}\hline
661 \drefrow{dead after 24h,dead after 48h,recovered}
662 {/control group/#1}\\\hline
663 \drefrow{dead after 24h,dead after 48h,recovered}%
664 {/med A/#1}\\\hline
665 \end{tabular}
666 \end{verbatim}
667 \end{codeexample}
668
669
670 \Macro[(@calc)]{\drefassert\{\meta{expr}\}}
671
672 Sometimes the underlying data changes while you are writing. But what
673 if your prose text relies on certain characteristics of the data. \macro{\drefassert} uses a pgfmath
674 expression that evaluates to \verb|true| or \verb|false|. When the
675 assertion holds (\verb|true|) nothing happens, only a terminal message
676 is printed. When it does not hold (\verb|false|) the compilation is aborted.
677
678 \begin{example}
679 \drefassert{data("/control group/mice count") > 30}
680 Of the more than thirty infected mice...
681 \end{example}\begin{codeexample}
682 \begin{verbatim}
683 \drefassert{data("/control group/mice count") > 30}
684 Of the more than thirty infected mice...
685 \end{verbatim}
686 \end{codeexample}
687
688 \Option[(default \textbf{true})]{/dref/noassert=\meta{true or false}}
689
690 The \textbf{noassert} deescalates all assertion errors to mere warnings. This option can also be given at the
691 \cmd{\usepackage} invication.
692
693 \Option[(no default, initially \textbf{none}, choice)]{/dref/annotate=\meta{annotation type}}
694 \Option[(choice item)]{/dref/annotate=none}
695 \Option[(choice item)]{/dref/annotate=footnote}
696 \Option[(choice item)]{/dref/annotate=pdfcomment}
697 \Option[(choice item)]{/dref/annotate=typeout}
698
699 While writing a document it is desirable to know, what key is used, while writing the text and generating the document.
700 Therefore \dataref provides the possibility to annotate values. The default option \textbf{none} disables this kind of
701 annotation. The \textbf{pdfcomment} option uses pdf annotations. Be aware that those annotations work properlyy only on
702 a few selected PDF readers\footnote{In doubt use Acrobat}.
703
704 \begin{example}[6cm]
705 \drefkeys{annotate=footnote}
706 \dref*{/control group/mice race}
707 \dref{/control group/mice count}
708 \drefcalc[annotate=pdfcomment]{100/3}
709 \end{example}\begin{codeexample}
710 \begin{verbatim}
711 \drefkeys{annotate=footnote}
712 \dref*{/control group/mice race}
713 \dref{/control group/mice count}
714 \drefcalc[annotate=pdfcomment]{100/3}
715 \end{verbatim}
716 \end{codeexample}
717
718
719 \subsection{Datagraphy}\label{sec:datagraphy}
720
721 \Macro{\drefusagereport}
722 \Option{[usagereport]}
723 \Option{[refall]}
724
725 With the \textbf{usagereport} package option enabled, \macro{\drefusagereport} generates a usagereport of all referenced
726 keys. The usage report groups the keys by the help texts. If the refall package option is given, all keys are marked as
727 referenced.
728
729 \section*{Datagraphy}
730 \drefusagereport
731
732 \end{document}
733
734 %%% Local Variables:
735 %%% mode: latex
736 %%% TeX-master: t
737 %%% End: