0

I have set up a database structure for projects and people. The aim is to have the IDs of the people as a value stored in a column of the project database. Now I would like to refer to the people, whose information is stored in a different database.

UPDATE

I was able to get the desired information using \DTLgetvalue. This works now fine for one entry in pi. But how can I loop through all of the entries stored in pi? My attempt with clist_map_inline fails.

MWE:

\documentclass{scrbook}

\usepackage{datatool}
% ===== people database setup =======
\makeatletter
\define@key{person}{name}{\DTLnewdbentry{\crcDB}{name}{#1}}
\define@key{person}{nameFirst}{\DTLnewdbentry{\crcDB}{nameFirst}{#1}}
\makeatother
\NewDocumentCommand{\crcPersonEntry}{ m m }{
  \def\crcDB{#1}
  \DTLifdbexists{\crcDB}{}{\DTLnewdb{\crcDB}}
  \DTLnewrow{\crcDB}
  \setkeys{person}{#2}
}

% ===== project database setup
\makeatletter
\define@key{project}{name}[\DTLnewdbentry{\crcDB}{name}{}]{\DTLnewdbentry{\crcDB}{name}{#1}}
\define@key{project}{pi}[\DTLnewdbentry{\crcDB}{pi}{}]{\DTLnewdbentry{\crcDB}{pi}{#1}}
\makeatother
\NewDocumentCommand{\crcProjectEntry}{ m m }{
  \def\crcDB{#1}
  \DTLifdbexists{\crcDB}{}{\DTLnewdb{\crcDB}}
  \DTLnewrow{\crcDB}
  \setkeys{project}{#2}
}

\ExplSyntaxOn
% Use: \getProject{<id>}

\NewDocumentCommand{\getPIs}{m}{%
\clist_map_inline:Nn {#1}{%
  \DTLgetvalue{\thePI}{##1}{1}{\dtlcolumnindex{##1}{nameFirst}}\thePI\space
  \DTLgetvalue{\thePI}{##1}{1}{\dtlcolumnindex{##1}{name}}\thePI
}}

\NewDocumentCommand{\getProject}{m}{%
  \DTLgetvalue{\theProjectName}{#1}{1}{\dtlcolumnindex{#1}{name}}\theProjectName-\space
  \DTLgetvalue{\thePIlist}{#1}{1}{\dtlcolumnindex{#1}{pi}}(\thePIlist)\space
\getPIs{\thePIlist}
}

 \ExplSyntaxOff


\begin{document}
\crcProjectEntry{project1}{
  name={My Project},
  pi={person1, person2}
}
\crcProjectEntry{project2}{
  name={My other Project},
  pi={person3}
}

\crcPersonEntry{person1}{
  name={Perssonos},
  nameFirst={Peter}
}

\crcPersonEntry{person2}{
  name={Holgersson},
  nameFirst={Agnes}
}

\crcPersonEntry{person3}{
  name={Ickstein},
  nameFirst={Paula}
}



%\getProject{project1} % --> My Project, Peter Perssonos, Agnes Holgersson

\getProject{project2} % -> My other Project, Paula Ickstein

\end{document}

That is the current result.

enter image description here

10
  • Try printing out thePIList just before the clist_map_inline command to see what are the content/catcode.
    – user202729
    Mar 23, 2022 at 16:48
  • I get the content of the key "pi", e.g. 'person1, person2' or 'person3'. So it seems the content is passed correctly to the macro "\getPIs". Any suggestions how to solve it? Mar 23, 2022 at 19:00
  • So if you already have the value person3 how would you manually "loop through the values"? (I'm not familiar with datatool)
    – user202729
    Mar 23, 2022 at 19:15
  • Using \tl_analysis_show:n for the argument of \getPIs I get: The token list contains the tokens: > \thePIlist (control sequence=macro:->person1, person2).. Looping through the values is only necessary when I have more than one value (e.g. person1, person2 in the database project1. In that case the names of the people behind person1 and person2 should be printed. Mar 23, 2022 at 19:19
  • Try printing out the ##1 (don't run datatool to get the name yet, just print out ##1) to see whether the clist is parsed correctly.
    – user202729
    Mar 23, 2022 at 19:22

0

You must log in to answer this question.

Browse other questions tagged .