1

This is a follow up question regarding: How to use DTLforeach (datatool) within a tabularray table?.

Consider this MWE:

\documentclass{scrbook}
\usepackage{datatool,tabularray,xcolor}

\NewDocumentCommand{\crcEntry}{ o m m }{% \def\crcDB{#2}% \DTLifdbexists{\crcDB}{}{\DTLnewdb{\crcDB}}% \DTLnewrow{\crcDB}% \IfNoValueTF{#1}{\setkeys{#2}{#3}}{\setkeys{#1}{#3}}% }

\makeatletter \define@key{OtherFundingSource}{nameID}{% \DTLnewdbentry{\crcDB}{nameID}{#1} } \define@key{OtherFundingSource}{periodStart}{\DTLnewdbentry{\crcDB}{periodStart}{#1}} \define@key{OtherFundingSource}{periodEnd}{\DTLnewdbentry{\crcDB}{periodEnd}{#1}} \define@key{OtherFundingSource}{projectTitle}{\DTLnewdbentry{\crcDB}{projectTitle}{#1}} \define@key{OtherFundingSource}{fundingAgency}{\DTLnewdbentry{\crcDB}{fundingAgency}{#1}} \makeatother

\NewDocumentCommand{\crcOtherFundingSourceTable}{ }{% \def\tblrbody{}% \DTLforeach*{OtherFundingSource}{% \nameID=nameID,% \fundingAgency=fundingAgency,% \projectTitle=projectTitle,% \periodStart=periodStart,% \periodEnd=periodEnd% }{% \edef\tblrbody{\tblrbody {\nameID} & {x} & \projectTitle & \periodStart --\periodEnd & \fundingAgency\ }}% \begin{tblr}[% expand=\tblrbody, label={none}, entry={none}, long ]{ colspec = {m{2.6cm}m{.8cm}X[m]m{1.3cm}m{2cm}}, rowhead = 1, row{1} = { font={\bfseries}, halign={c} }, } PI % & Project % & Project title % & Funding period % & Funding agency\ \tblrbody \end{tblr}}

\begin{document} \crcEntry{OtherFundingSource}{ nameID = {NAME}, projectTitle = {This is my \emph{title}.}, periodStart = {2020}, periodEnd = {2023}, fundingAgency = {LaTeX-funding} } \crcOtherFundingSourceTable \end{document}

It will give me the error:

! Use of \@sDTLforeach doesn't match its definition. \text@command #1->\edef \reserved@a { \unexpanded {#1}}\ifx \reserved@a @emp...

l.77 \crcOtherFundingSourceTable

But I can compile when I delete \emph from the content.

lukascbossert
  • 3,015
  • 1
  • 16
  • 37

1 Answers1

3

never use \edef on arbitrary text content.

Use \protected@edef\tblrbody.

Ulrike Fischer
  • 327,261