I'd like to use datatool to populate a longtblr table (defined by tabularray) with data.
I expected this:
\documentclass{article}
\begin{filecontents}[overwrite]{data.csv}
Key,Value
a1,a2
b1,b2
\end{filecontents}
\usepackage{datatool}
\DTLloaddb{data}{data.csv}
\usepackage{tabularray}
\UseTblrLibrary{functional}
\begin{document}
\begin{longtblr}[evaluate=\DTLforeach]{colspec = {cc}}
\DTLforeach*{data}{
\key=Key,
\value=Value%
}{
\key &
\value\\
}
\end{longtblr}
\end{document}
to yield a table like:
but I receive the error:
27: Misplaced alignment tab character &.
Line 27 refers to: \end{longtblr}.
I added [evaluate=\DTLforeach] on a hunch based on the comments on this question. Deleting all the whitespace within longtblr has no effect.
MWE Using tabular
This yields the expected result:
\documentclass{article}
\begin{filecontents}[overwrite]{data.csv}
Key,Value
a1,a2
b1,b2
\end{filecontents}
\usepackage{datatool}
\DTLloaddb{data}{data.csv}
\begin{document}
\begin{tabular}{cc}
\DTLforeach*{data}{
\key=Key,
\value=Value%
}{
\key &
\value\\
}
\end{tabular}
\end{document}
MWE Using xltabular
As does this:
\documentclass{article}
\begin{filecontents}[overwrite]{data.csv}
Key,Value
a1,a2
b1,b2
\end{filecontents}
\usepackage{datatool}
\DTLloaddb{data}{data.csv}
\usepackage{xltabular}
\begin{document}
\begin{xltabular}{\textwidth}{cc}
\DTLforeach*{data}{
\key=Key,
\value=Value%
}{
\key &
\value\\
}
\end{xltabular}
\end{document}
But I'd like to make use of tabularray's rich feature set.

&s in the table content directly. You can use expl3 to construct the code to be executed, then execute all of it in one go. – user202729 Nov 23 '22 at 15:03\edef\tblrbody{\tblrbody ... current row ...}within\DTLforeach. That question does not use a csv but I am fairly sure it is applicable. – Marijn Nov 23 '22 at 21:52expl3because it's wholly unfamiliar, but maybe it's time to learn. It will take me some time to fully understand that answer @Marjin, but it certainly looks applicable. – seanakabry Nov 23 '22 at 22:01