| 1 |
% This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04 |
| 2 |
% Example 70 Creating a New Database with a Label |
| 3 |
% Label: "ex:newdb" |
| 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 data |
| 12 |
\DTLnewdb{mydata} |
| 13 |
\DTLnewrow{mydata}% create a new row |
| 14 |
% Add entries to the first row: |
| 15 |
\DTLnewdbentry |
| 16 |
{mydata}% database label |
| 17 |
{Product}% column key |
| 18 |
{The Adventures of Duck and Goose}% value |
| 19 |
\DTLnewdbentry |
| 20 |
{mydata}% database label |
| 21 |
{Quantity}% column key |
| 22 |
{1,452}% value |
| 23 |
\DTLnewdbentry |
| 24 |
{mydata}% database label |
| 25 |
{Price}% column key |
| 26 |
{\$1.99}% value |
| 27 |
\DTLnewrow{mydata}% create a new row |
| 28 |
% Add entries to the second row: |
| 29 |
\DTLnewdbentry |
| 30 |
{mydata}% database label |
| 31 |
{Product}% column key |
| 32 |
{Duck and Goose on Holiday}% value |
| 33 |
\DTLnewdbentry |
| 34 |
{mydata}% database label |
| 35 |
{Quantity}% column key |
| 36 |
{94}% value |
| 37 |
\DTLnewdbentry |
| 38 |
{mydata}% database label |
| 39 |
{Price}% column key |
| 40 |
{\$2.99}% value |
| 41 |
% the next value needs to be expanded: |
| 42 |
\DTLsetup{new-value-expand} |
| 43 |
\DTLnewdbentry |
| 44 |
{mydata}% database label |
| 45 |
{Notes}% column key |
| 46 |
{\limiteded}% value |
| 47 |
% switch off expansion: |
| 48 |
\DTLsetup{new-value-expand=false} |
| 49 |
\DTLnewrow{mydata}% create a new row |
| 50 |
% Add entries to the third row: |
| 51 |
\DTLnewdbentry |
| 52 |
{mydata}% database label |
| 53 |
{Product}% column key |
| 54 |
{The Return of Sir Quackalot}% value |
| 55 |
\DTLnewdbentry |
| 56 |
{mydata}% database label |
| 57 |
{Quantity}% column key |
| 58 |
{3}% value |
| 59 |
\DTLnewdbentry |
| 60 |
{mydata}% database label |
| 61 |
{Price}% column key |
| 62 |
{\$4.99}% value |
| 63 |
|
| 64 |
\begin{document} |
| 65 |
\DTLdisplaydb{mydata} |
| 66 |
\end{document} |