Debian Codegraph @

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

raw
1 % This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
2 % Example 77 Inserting a Column at the Start of Displayed Data
3 % Label: "ex:displayinsertcol"
4 % arara: pdflatex
5 % arara: pdflatex
6 % arara: pdfcrop
7 \documentclass[12pt]{article}
8 \pagestyle{empty}
9 \begin{filecontents}[noheader,overwrite]{studentmarks.csv}
10 Surname,Forename,StudentNo,Assign1,Assign2,Assign3
11 "Smith, Jr",John,102689,68,57,72
12 "Brown",Jane,102647,75,84,80
13 "Brown",Jane,102646,64,92,79
14 "Brown",Andy,103569,42,52,54
15 "Adams",Zoƫ,105987,52,48,57
16 "Brady",Roger,106872,68,60,62
17 "Verdon",Clare,104356,45,50,48
18 \end{filecontents}
19
20 \usepackage{datatool}
21 \DTLsetup{default-name=marks}
22 \DTLread{studentmarks.csv}
23 \ExplSyntaxOn
24 \RenewDocumentCommand \DTLdisplaydbAddItem
25 { m m m m m m m m }
26 {
27 \int_compare:nNnT { #7 } = { \c_one_int }
28 {
29 \DTLaction[ return={ \StudentNo = StudentNo } ]
30 { current ~ row ~ values }
31 \tl_put_right:Nn #1 { \DTLrowincr \label }
32 \tl_put_right:Nx #1 { { \StudentNo } }
33 \tl_put_right:Nn #1 { \DTLtherow & }
34 }
35 \tl_put_right:Nn #1 { #3 { #2 } }
36 }
37 \ExplSyntaxOff
38 \begin{document}
39 \DTLrowreset
40 \DTLaction[
41 options={
42 pre-col={r},
43 pre-head={\bfseries Row &}
44 }
45 ]{display}
46
47 \DTLaction[
48 assign={
49 \Surname=Surname,
50 \Forename=Forename,
51 \StudentNo=StudentNo
52 },
53 options={
54 inline={%
55 \DTLifstringeq{\Surname}{Brown}
56 {\DTLifstringeq{\Forename}{Andy}{#1}{}}{}%
57 }
58 }
59 ]{find}
60 Row \ref{\StudentNo} shows the details for Andy Brown.
61 \end{document}