2

The databib package from the datatool bundle allows one to import BibTeX databases and work with them from within LaTeX. The author field can be accessed as \DTLbibfield{Author}, which returns data from the bbl file, where it is stored in the format

\DTLnewbibitem {Author}{{von1}{Last1}{jr1}{First1},%
{von2}{Last2}{jr2}{First2}}%

What I see in my pdf output is von1Last1jr1First1,von2Last2jr2First2.

What I would like to do is loop over the comma-separated list.

My first problem is that I do not know exactly what \DTLbibfield{Author} returns. First, I assumed {von1}{Last1}{jr1}{First1},{von2}{Last2}{jr2}{First2}, but then when trying to loop over this list using \foreach from the pgffor package, it sees it as just a single value.

A minimal example illustrating the problem:

\begin{filecontents}{data.bib}
@inproceedings{test,
  Author = {Author One and Auteur Twee},
  Title = {An loopy approach to author list iteration},
}
\end{filecontents}
\documentclass{article}
\usepackage{databib,pgffor}
  \newcommand{\Authors}{\DTLbibfield{Author}}
\begin{document}
  % GET DATA OUT OF BIBFILE INTO DB
  \nocite{*}
  \DTLloadbbl{data}{data.bib}

  % LOOP OVER ENTRIES
  \DTLforeachbibentry*{data}{
    \Authors\\
    % LOOP OVER AUTHORS IN ENTRY
    \foreach \Author in \Authors {\Author\ *** }
      % seen as one-item list instead of two-item list
  }
\end{document}
  • Note that your usage of \providecommand is wrong. Moreover \Authors will expand to \DTLbibfield{Author}, which is certainly not a comma separated list. You have to use \DTLbibfieldlet\Authors{Author}, instead of \providecommand{\Authors}{\DTLbibfield{Author}} – egreg May 23 '15 at 22:18
  • Fixed the wrong usage of \providecommand (first sentence of comment). The rest of your comment answers the question. – equaeghe May 23 '15 at 22:27
2

Your usage of \providecommand is wrong in any case. Even if it worked, \Authors would expand to \DTLbibfield{Author}, which is not a comma separated list good for \foreach, so the only item is processed as a unit.

You should use \DTLbibfieldlet instead:

\begin{filecontents}{\jobname.bib}
@inproceedings{test,
  Author = {Author One and Auteur Twee},
  Title = {An loopy approach to author list iteration},
}
\end{filecontents}

\documentclass{article}
\usepackage{databib,pgffor}

\begin{document}

% GET DATA OUT OF BIBFILE INTO DB
\nocite{*}
\DTLloadbbl{data}{\jobname.bib}

% LOOP OVER ENTRIES
\DTLforeachbibentry{data}{%
  \DTLbibfieldlet\Authors{Author}%
  % LOOP OVER AUTHORS IN ENTRY
  \foreach \Author in \Authors {\Author\ *** }%
}

\end{document}

enter image description here

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.