LaTeX forum ⇒ GeneralDTLinitials Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
Posts: 19
Joined: Thu Jul 19, 2018 4:47 pm


Postby Pangur » Thu Aug 08, 2019 9:25 pm

Today I embarked on learning how to read a CSV file into LaTeX using datatool package. For each row, I am able to obtain the data using
to give me surname and forenames. By using

{\fnames\ \surname\\

I can print out the list of names. All good so far

However, sometimes, I want to be able to show initials instead of forenames. As the manual says, \DTLinitial{Mary} gives M.

However, it appears that while \DTLinitials can read a straight forward string (e.g., Mary), it cannot read the variable that \fnames contains at each row.

How can I pass the value of \fnames to \DTLinitials, please?

Have tried the following varieties:





without success.

Thanks for any advice or help.

Cross-posted from Stack Exchange.

User avatar
Stefan Kottwitz
Site Admin
Posts: 9415
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Aug 11, 2019 9:16 am

Hi Pangur!

Expand \fnames before applying \DTLinitials to it. This can be done by using \expandafter, that temporarily skips the next control sequence:



  1. \documentclass{scrbook}
  2. \usepackage[english]{babel}
  3. \usepackage{datatool}
  4. \DTLloaddb{members}{folks.csv}
  6. \begin{document}
  7. \mainmatter
  8. \pagestyle{headings}
  10. \DTLforeach{members}
  11. {\fnames=fnames, \surname=surname}
  12. {
  13. \expandafter\DTLinitials\expandafter{\fnames}\
  14. \surname\
  16. }
  17. \end{document}

Site admin

Posts: 19
Joined: Thu Jul 19, 2018 4:47 pm

Postby Pangur » Sun Aug 11, 2019 2:19 pm

Hi Stefan,
Thanks very much for this. I have now tested it, and it worked beautifully.
Much appreciated.

Return to “General”

Who is online

Users browsing this forum: No registered users and 5 guests