Debian Codegraph @

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

raw
1 % This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
2 % Example 75 Display Data in a Table with Filtered Rows
3 % Label: "ex:displaydbcond"
4 % arara: pdflatex
5 % arara: pdfcrop
6 \documentclass[12pt]{article}
7 \pagestyle{empty}
8 \usepackage{datatool}
9 \DTLsetup{store-datum,default-name=products}
10 % define database:
11 \DTLaction{new}
12 % add columns in desired order:
13 \DTLaction[key=Title]{add column}
14 \DTLaction[key=Author]{add column}
15 \DTLaction[key=Format]{add column}
16 \DTLaction[key=Quantity]{add column}
17 \DTLaction[key=Price,value={Price (\$)}]{add column}
18 % 1st row:
19 \DTLaction[
20 assign={
21 Title = {The Adventures of Duck and Goose},
22 Author = {Sir Quackalot},
23 Format = paperback,
24 Quantity = 3, Price = {10.99}
25 }
26 ]{new row}
27 % 2nd row:
28 \DTLaction[
29 assign={
30 Title = {The Return of Duck and Goose},
31 Author = {Sir Quackalot},
32 Format = paperback,
33 Quantity = 5, Price = {19.99}
34 }
35 ]{new row}
36 % 3rd row:
37 \DTLaction[
38 assign={
39 Title = {More Fun with Duck and Goose},
40 Author = {Sir Quackalot},
41 Format = paperback,
42 Quantity = 1, Price = {12.99}
43 }
44 ]{new row}
45 % 4th row:
46 \DTLaction[
47 assign={
48 Title = {Duck and Goose on Holiday},
49 Author = {Sir Quackalot},
50 Format = paperback,
51 Quantity = 3, Price = {11.99}
52 }
53 ]{new row}
54 % 5th row:
55 \DTLaction[
56 assign={
57 Title = {The Return of Duck and Goose},
58 Author = {Sir Quackalot},
59 Format = hardback,
60 Quantity = 3, Price = {19.99}
61 }
62 ]{new row}
63 % 6th row:
64 \DTLaction[
65 assign={
66 Title = {The Adventures of Duck and Goose},
67 Author = {Sir Quackalot},
68 Format = hardback,
69 Quantity = 9, Price = {18.99}
70 }
71 ]{new row}
72 % 7th row:
73 \DTLaction[
74 assign={
75 Title = {My Friend is a Duck},
76 Author = {A. Parrot},
77 Format = paperback,
78 Quantity = 20, Price = {14.99}
79 }
80 ]{new row}
81 % 8th row:
82 \DTLaction[
83 assign={
84 Title = {Annotated Notes on the ‘Duck and Goose’ chronicles},
85 Author = {Prof Macaw},
86 Format = ebook,
87 Quantity = 10, Price = {8.99}
88 }
89 ]{new row}
90 % 9th row:
91 \DTLaction[
92 assign={
93 Title = {‘Duck and Goose’ Cheat Sheet for Students},
94 Author = {Polly Parrot},
95 Format = ebook,
96 Quantity = 50, Price = {5.99}
97 }
98 ]{new row}
99 % 10th row:
100 \DTLaction[
101 assign={
102 Title = {‘Duck and Goose’: an allegory for modern times?},
103 Author = {Bor Ing},
104 Format = hardback,
105 Quantity = 0, Price = {59.99}
106 }
107 ]{new row}
108 % 11th row:
109 \DTLaction[
110 assign={
111 Title = {Oh No! The Chickens have Escaped!},
112 Author = {Dickie Duck},
113 Format = ebook,
114 Quantity = 11, Price = {2.0}
115 }
116 ]{new row}
117
118 \newcommand{\productfilter}[3]{%
119 \dtlgetentryfromcurrentrow
120 {\theQuantity}%
121 {\dtlcolumnindex{\dtldbname}{Quantity}}%
122 \DTLifnumgt{\theQuantity}{0}{#3}{}%
123 }
124 \begin{document}
125 \DTLaction[
126 options={
127 row-condition-function=\productfilter,
128 only-keys={Title,Quantity,Price}
129 }
130 ]{display}
131 \end{document}