| 1 |
% This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04 |
| 2 |
% Example 76 Referencing Rows from Displayed Data |
| 3 |
% Label: "ex:displayrowref" |
| 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 |
} |
| 34 |
\tl_put_right:Nn #1 { #3 { #2 } } |
| 35 |
} |
| 36 |
\ExplSyntaxOff |
| 37 |
\begin{document} |
| 38 |
\DTLrowreset |
| 39 |
\DTLaction{display} |
| 40 |
|
| 41 |
\DTLaction[ |
| 42 |
assign={ |
| 43 |
\Surname=Surname, |
| 44 |
\Forename=Forename, |
| 45 |
\StudentNo=StudentNo |
| 46 |
}, |
| 47 |
options={ |
| 48 |
inline={% |
| 49 |
\DTLifstringeq{\Surname}{Brown} |
| 50 |
{\DTLifstringeq{\Forename}{Andy}{#1}{}}{}% |
| 51 |
} |
| 52 |
} |
| 53 |
]{find} |
| 54 |
Row \ref{\StudentNo} shows the details for Andy Brown. |
| 55 |
\end{document} |