Debian Codegraph @

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

raw
1 % This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04
2 % Example 84 Display Two Fields in One Column
3 % Label: "ex:displaydbmergefields"
4 % arara: pdflatex
5 % arara: pdfcrop
6 \documentclass[12pt]{article}
7 \pagestyle{empty}
8 \begin{filecontents}[noheader,overwrite]{studentmarks.csv}
9 Surname,Forename,StudentNo,Assign1,Assign2,Assign3
10 "Smith, Jr",John,102689,68,57,72
11 "Brown",Jane,102647,75,84,80
12 "Brown",Jane,102646,64,92,79
13 "Brown",Andy,103569,42,52,54
14 "Adams",Zoƫ,105987,52,48,57
15 "Brady",Roger,106872,68,60,62
16 "Verdon",Clare,104356,45,50,48
17 \end{filecontents}
18
19 \usepackage{datatool}
20 \DTLsetup{store-datum,default-name=marks}
21 \DTLread{studentmarks.csv}
22 \ExplSyntaxOn
23 \RenewDocumentCommand \DTLdisplaydbAddItem
24 { m m m m m m m m }
25 {
26 \int_compare:nNnTF
27 { #7 } = { \c_one_int }
28 {
29 \DTLaction[ return={\l_tmpa_tl=Forename} ]
30 { current ~ row ~ values }
31 \datatool_if_null_or_empty:NTF \l_tmpa_tl
32 {
33 \tl_put_right:Nn #1 { #3 { #2 } }
34 }
35 {
36 \tl_put_right:Nx #1
37 { \exp_not:N #3 { \exp_not:n { #2 }, ~ \exp_not:V \l_tmpa_tl } }
38 }
39 }
40 {
41 \tl_put_right:Nn #1 { #3 { #2 } }
42 }
43 }
44 \ExplSyntaxOff
45 \begin{document}
46 \DTLaction[
47 options={
48 only-keys={Surname,StudentNo,Assign1,Assign2,Assign3},
49 header-row={Name & Reg.\ No., & Mark 1 & Mark 2 & Mark 3}
50 }
51 ]{display}
52 \end{document}