Update:
With csvsimple v2.1.0 (2021/07/06), csvsimple-l3 gets compatible with tabularray.
You should use \usepackage[l3]{csvsimple} or \usepackage{csvsimple-l3} to load csvsimple-l3, rather than the superseded csvsimple-legacy.
\begin{filecontents*}{data.csv}
frA,frB,deA
un cogne,arg.,ein Bulle
morfler,arg.,eins abkriegen
\end{filecontents*}
\documentclass{article}
\usepackage[ngerman,french]{babel}
\usepackage{fontspec}
\usepackage{tabularray} %needs package ninecolors.sty
\usepackage{booktabs}
\usepackage[l3]{csvsimple} % or "\usepackage{csvsimple-l3}"
\begin{document}
\subsection*{Desired output}
This is what I'd like to obtain, with environment \verb|tblr|:
\begin{tblr}{
colspec={X[2,l]X[4,l]},
width=0.5\linewidth,
hlines,
}
\textit{un cogne} (arg.) & \textit{un policier ou un gendarme}\
\textit{morfler} (arg.) & {\selectlanguage{ngerman}\textit{eins abkriegen}}\
\end{tblr}
\subsection*{With \texttt{tabular} env}
A normal tabular seems to work (but I'd miss the functions of tabularray...)
(not only the X column type, also the alignment facilities):
\begin{tabular}{p{4cm}p{8cm}}\toprule
\csvreader[
late after line=\\midrule,
late after last line=\\bottomrule,
head to column names,
]{data.csv}{}{%
\textit{\frA} (\frB) & \textit{\deA}
}
\end{tabular}
\subsection*{With \texttt{tblr} env}
% required by tabularray
\NewTableCommand\toprule{\hline[0.08em]}
\NewTableCommand\midrule{\hline[0.05em]}
\NewTableCommand\bottomrule{\hline[0.08em]}
\csvreader[
tabularray={
colspec={X[2,l]X[4,l]},
width=0.5\linewidth,
% hlines
},
table head=\toprule,
late after line=\\midrule,
late after last line=\\bottomrule,
head to column names,
]{data.csv}{}{%
\noexpand\textit{\frA} (\frB) & \noexpand\textit{\deA}
}
\end{document}
Output is the same as below.
Original:
Here is a first try on the csvsimple side. The idea is to make \csvloop (in the taste of csvsimple-legacy) firstly store the whole tabular staff in a macro (here \csv@output), instead of directly printing them. Then user can use \csvoutput to print the table.
Restricted by how tabularray is implemented, every \hline-like staff, \\, and & should be directly seen in \csv@output.
\begin{filecontents*}{data.csv}
frA,frB,deA
un cogne,arg.,ein Bulle
morfler,arg.,eins abkriegen
\end{filecontents*}
\documentclass{article}
\usepackage[ngerman,french]{babel}
\usepackage{fontspec}
\usepackage{tabularray} %needs package ninecolors.sty
\usepackage{booktabs}
\usepackage{csvsimple}
%%%
%%% patch for csvsimple-lagency
%%%
\usepackage{xpatch}
\makeatletter
\newif\ifcsv@storeonly
\csvset{
% new keys
table env/.store in=\csv@tableenv,
store only/.is if=csv@storeonly,
% redefinition
tabular/.style={
@table={\csv@pretable\begin{\csv@tableenv}{#1}\csv@tablehead}{\csv@tablefoot\end{\csv@tableenv}\csv@posttable},
late after line=\
},
% init new keys
table env=tabular,
store only=false
}
% store-or-print patch for \csvloop
\long\def\csvloop#1{%
% reset
\global\let\csv@output@empty
\global\let@endloophook\csv@empty%
\global\let\csvlinetotablerow\csv@assemble@csvlinetotablerow%
% options
\csvset{default,every csv,#1}%
\csv@preprocss%
\csv@set@catcodes%
\csv@print@or@ostore\csv@prereading%
\csv@print@or@ostore\csv@table@begin%
\setcounter{csvinputline}{0}%
% start reading
\openin\csv@file=\csv@input@filename\relax%
\ifeof\csv@file%
\csv@error{File '\csv@input@filename' not existent, not readable, or empty!}{}%
\else%
% the head line
\csv@opt@processheadline%
\fi%
%
\setcounter{csvrow}{0}%
\gdef\csv@do@preline{%
\csv@print@or@ostore\csv@prefirstline%
\gdef\csv@do@preline{\csv@print@or@ostore\csv@preline}%
}%
\gdef\csv@do@postline{%
\csv@print@or@ostore\csv@postfirstline%
\gdef\csv@do@postline{\csv@print@or@ostore\csv@postline}%
}%
\gdef\csv@do@@latepostline{%
\csv@print@or@ostore\csv@latepostfirstline%
\gdef\csv@do@latepostline{\csv@print@or@ostore\csv@latepostline}%
}%
\gdef\csv@do@latepostline{%
\csv@print@or@ostore\csv@lateposthead%
\global\let\csv@do@latepostline=\csv@do@@latepostline%
}%
% command for the reading loop
\gdef\csv@iterate{%
\let\csv@usage=\csv@empty%
\csvreadnext%
\ifeof\csv@file%
\global\let\csv@next=\csv@empty%
\else%
\global\let\csv@next=\csv@iterate%
\ifx\csv@par\csvline\relax%
\else%
\csv@escanline{\csvline}%
% check and decide
\csv@opt@checkcolumncount%
\fi%
\fi%
% do or do not
\csv@usage%
\csv@next}%
\ifeof\csv@file%
\global\let\csv@next=\csv@empty%
\else%
\global\let\csv@next=\csv@iterate%
\fi%
\csv@next%
\closein\csv@file%
@endloophook%
\csv@print@or@ostore\csv@latepostlastline%
\csv@print@or@ostore\csv@table@end%
\csv@print@or@ostore\csv@postreading%
\csv@reset@catcodes%
}
\newcommand\csvoutput{%
% expose tabular-like env name
\xpatchcmd@self\csv@output\csv@tableenv
\xpatchcmd@self\csv@output\csv@tableenv
% expose hrule-like commands
\xpatchcmd@self\csv@output\csv@tablehead
\xpatchcmd@self\csv@output\csv@tablefoot
% output
\csv@output
}
% helper, \xpatchcmd#1{#2}{<one-step expansion of #2>}{}{\fail}
\newcommand\xpatchcmd@self[2]{%
\expanded{\unexpanded{\xpatchcmd#1{#2}}{\unexpanded\expandafter{#2}}}{}{\fail}%
}
% store-or-print patch for \csv@do@linecommand
\xpatchcmd\csv@do@linecommand
{\csv@body}
{\csv@print@or@estore\csv@body}
{}{\fail}
% expand once
\def\csv@print@or@ostore#1{\csv@print@or@store@meta
{\expandafter\g@addto@macro\expandafter\csv@output\expandafter{#1}}
{#1}}
% fully expansion
\def\csv@print@or@estore#1{\csv@print@or@store@meta
{\expanded{\noexpand\g@addto@macro\noexpand\csv@output{#1}}}
{#1}}
\def\csv@print@or@store@meta{%
\ifcsv@storeonly
\expandafter@firstoftwo
\else
\expandafter@secondoftwo
\fi
}
\makeatother
%%%
%%% end of patch
%%%
\begin{document}
\subsection*{Desired output}
This is what I'd like to obtain, with environment \verb|tblr|:
\begin{tblr}{
colspec={X[2,l]X[4,l]},
width=0.5\linewidth,
hlines,
}
\textit{un cogne} (arg.) & \textit{un policier ou un gendarme}\
\textit{morfler} (arg.) & {\selectlanguage{ngerman}\textit{eins abkriegen}}\
\end{tblr}
\subsection*{With \texttt{tabular} env}
A normal tabular seems to work (but I'd miss the functions of tabularray...)
(not only the X column type, also the alignment facilities):
\begin{tabular}{p{4cm}p{8cm}}\toprule
\csvreader[
late after line=\\midrule,
late after last line=\\bottomrule,
head to column names,
]{data.csv}{}{%
\textit{\frA} (\frB) & \textit{\deA}
}
\end{tabular}
\subsection*{With \texttt{tblr} env}
\csvreader[
table env=tblr,
tabular={
colspec={X[2,l]X[4,l]},
width=0.5\linewidth,
% hlines
},
store only,
table head=\toprule,
late after line=\\midrule,
late after last line=\\bottomrule,
head to column names,
]{data.csv}{}{%
\noexpand\textit{\frA} (\frB) & \noexpand\textit{\deA}
}
\NewTableCommand\toprule{\hline[0.08em]}
\NewTableCommand\midrule{\hline[0.05em]}
\NewTableCommand\bottomrule{\hline[0.08em]}
\csvoutput
\end{document}

tabularray, see https://github.com/lvjr/tabularray/issues/23. – muzimuzhi Z Jul 02 '21 at 20:41