I'm trying to use expl3
sequences in order to stored 0, 1 or more affiliations to 1 or more authors stored in a datatool
database. The following MWE works nicely:
\documentclass{article}
\usepackage{xparse}
\usepackage{datatool}
\ExplSyntaxOn
\DTLnewdb{_mymodule_authors}
\seq_new:N \g_mymodule_author_affiliations_seq
\keys_define:nn { mymodule/authors }
{
affiliation .code:n = \seq_gput_right:Nn \g_mymodule_author_affiliations_seq {#1}
}
\cs_new_protected:Nn \_mymodule_authors:nn
{
\DTLnewrow{_mymodule_authors}
\DTLnewdbentry{_mymodule_authors}{name}{#1}
\DTLnewdbentry{_mymodule_authors}{affiliations}{#2}
}
\cs_generate_variant:Nn \_mymodule_authors:nn { nV }
\RenewDocumentCommand \author { o m } {
\IfValueTF {#1}
{
\keys_set:nn { mymodule/authors } { #1 }
\_mymodule_authors:nV {#2}{\g_mymodule_author_affiliations_seq}
}
{
\_mymodule_authors:nV {#2}{\c_empty_tl}
}
\seq_gclear:N \g_mymodule_author_affiliations_seq
}
\NewDocumentCommand \showauthors { } {
\DTLforeach*{_mymodule_authors}{
\l_tmpa_tl=name,
\l_tmpa_seq=affiliations
}{
\mymodule_display_author:nn {\l_tmpa_tl}{\l_tmpa_seq}
\DTLiflastrow{
}{
\DTLpar
}
}
}
\cs_new_protected:Nn \mymodule_display_author:nn
{
#1
\seq_if_empty:NF {\l_tmpa_seq}
{
\space(\seq_use:Nn \l_tmpa_seq { ,~ })
}
}
\ExplSyntaxOff
\begin{document}
%\author{Foo, Bar 0}
\author[affiliation=Blah]{Foo, Bar 1}
\author[affiliation=Bleh,affiliation=Blih]{Foo, Bar 2}
\author[affiliation=Bloh,affiliation=Bluh,affiliation=Blyh]{Foo, Bar 3}
%
\showauthors
\end{document}
But, as soon as I comment out \author{Foo, Bar 0}
, the author with 0 affiliation, I'm facing the following error I don't understand:
! Missing = inserted for \ifnum.
<to be read again>
{
V
argument.\c_empty_tl
.interface3
says “TheV
type returns the value of a register, which can be one oftl
,num
,int
,skip
,dim
,toks
, or built-in TeX registers.”V
is unpredictable. I tried using\c_empty_seq
rather than\c_empty_tl
, but errors are thrown nonetheless.V
type can only be used where there is some logical 'value' concept. That simply isn't the case for a sequence.