I'm trying to create an author index using the databib package (datatool) bundle. I can loop over the entries in a BibTeX database and for each entry, loop over the authors using the \foreach command from the pgffor package. I then would like to add the author to the index, but this fails.

The following minimal example illustrates the issue:

  Author = {Author One and Auteur Twee},

\newcommand*{\invertfourargs}[4]{#4 #3 #2 #1}



  \foreach \fourargs in \multiplefourargs {%
  \foreach \fourargs in \multiplefourargs {%



    \foreach \Author in \Authors {%
%     \foreach \Author in \Authors {% THIS DOES NOT WORK
%       \index[test]{\expandafter\DTLformatauthor\Author}}


The error I get is:

Runaway definition?
->\write \test@idxfile {\indexentry{\let \global \advance \dtlforeachlevel \ETC
! File ended while scanning definition of \reserved@a.
<inserted text> 

What should I do to fix my code?


Your problem is not to expand the \Author (\index will do it anyway) but to prevent the expansion of \DTLformatauthor when the index is written. So use

  • What is then the essential difference between \DTLformatauthor and \invertfourargs? – equaeghe May 27 '15 at 9:57
  • 1
    The invertfourargs is expandable and can be executed while writing the .ind. Look in test.ind to see the differences. – Ulrike Fischer May 27 '15 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.