Debian Codegraph @

texmf-dist/doc/latex/datatool/datatool-user-examples/datatool-user-example069.tex

raw
1 % This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
2 % Example 69 Automatically Formatting Values Calculated by Actions
3 % Label: "ex:actiondatum"
4 % arara: pdflatex
5 % arara: pdfcrop
6 \documentclass[12pt]{article}
7 \pagestyle{empty}
8 \usepackage{datatool}
9 % custom expandable command:
10 \newcommand{\limiteded}{limited edition}
11 % define a database with the name 'pricelist':
12 \DTLsetup{store-datum,default-name=pricelist}
13 \DTLaction{new}% create the default database
14 % 1st row:
15 \DTLaction[
16 assign={
17 Product = {The Adventures of Duck and Goose},
18 Quantity = {1,452}, Price = {\$1.99}
19 }
20 ]{new row}
21 % 2nd row:
22 \DTLaction[
23 assign={
24 Product = {Duck and Goose on Holiday},
25 Quantity = {94}, Price = {\$2.99}
26 }
27 ]{new row}
28 % the next value needs to be expanded:
29 \DTLaction[
30 key={Notes}, expand-value={\limiteded} ]{new entry}
31 % 3rd row:
32 \DTLaction[
33 assign={
34 Product = {The Return of Sir Quackalot},
35 Quantity = {3}, Price = {\$4.99}
36 }
37 ]{new row}
38 \begin{document}
39 \section{Default datum=false}
40
41 \DTLaction[
42 key=Quantity,
43 key2=Price,
44 options={sd,min,max}
45 ]{aggregate}
46
47 Quantity column index: \DTLuse{column}.
48 Total quantity: \DTLuse{sum}.
49 Average quantity: \DTLuse{mean}.
50 Quantity standard deviation: \DTLuse{sd}.
51 Minimum quantity: \DTLuse{min}.
52 Maximum quantity: \DTLuse{max}.
53
54 Price column index: \DTLuse{column2}.
55 Total price: \DTLuse{sum2}.
56 Average price: \DTLuse{mean2}.
57 Price standard deviation: \DTLuse{sd2}.
58 Minimum price: \DTLuse{min2}.
59 Maximum price: \DTLuse{max2}.
60
61 \section{datum=\{round=2\}}
62
63 \DTLaction[
64 datum={round=2},
65 key=Quantity,
66 key2=Price,
67 options={sd,min,max}
68 ]{aggregate}
69
70 Quantity column index: \DTLuse{column}.
71 Total quantity: \DTLuse{sum}
72 (\DTLget[sum]{\theTotal}\DTLdatumvalue{\theTotal}).
73 Average quantity: \DTLuse{mean}.
74 Quantity standard deviation: \DTLuse{sd}.
75 Minimum quantity: \DTLuse{min}
76 (\DTLget[min]{\theMin}\DTLdatumvalue{\theMin}).
77 Maximum quantity: \DTLuse{max}
78 (\DTLget[max]{\theMax}\DTLdatumvalue{\theMax}).
79
80 Price column index: \DTLuse{column2}.
81 Total price: \DTLuse{sum2}.
82 Average price: \DTLuse{mean2}.
83 Price standard deviation: \DTLuse{sd2}.
84 Minimum price: \DTLuse{min2}.
85 Maximum price: \DTLuse{max2}.
86
87 \section{datum=\{round=2,currency\}} (All aggregate values become currency!)
88
89 \DTLaction[
90 datum={round=2,currency},
91 key=Quantity,
92 key2=Price,
93 options={sd,min,max}
94 ]{aggregate}
95
96 Quantity column index: \DTLuse{column}.
97 Total quantity: \DTLuse{sum}
98 (\DTLget[sum]{\theTotal}\DTLdatumvalue{\theTotal}).
99 Average quantity: \DTLuse{mean}.
100 Quantity standard deviation: \DTLuse{sd}.
101 Minimum quantity: \DTLuse{min}
102 (\DTLget[min]{\theMin}\DTLdatumvalue{\theMin}).
103 Maximum quantity: \DTLuse{max}
104 (\DTLget[max]{\theMax}\DTLdatumvalue{\theMax}).
105
106 Price column index: \DTLuse{column2}.
107 Total price: \DTLuse{sum2}.
108 Average price: \DTLuse{mean2}.
109 Price standard deviation: \DTLuse{sd2}.
110 Minimum price: \DTLuse{min2}.
111 Maximum price: \DTLuse{max2}.
112 \end{document}