## LaTeX forum ⇒ General ⇒ DTLinitials Topic is solved

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

### DTLinitials

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
{\surname=surname,\fnames=fnames}
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:

\DTLinitials{\fnames}\DTLinitials{fnames}\DTLinitials\fnames\DTLinitials{{\fnames}}
without success.

Thanks for any advice or help.

Cross-posted from Stack Exchange.

Stefan Kottwitz
Posts: 9415
Joined: Mon Mar 10, 2008 9:44 pm
Hi Pangur!

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

\expandafter\DTLinitials\expandafter{\fnames}

MWE:

\documentclass{scrbook}\usepackage[english]{babel}\usepackage{datatool}\DTLloaddb{members}{folks.csv} \begin{document}\mainmatter\pagestyle{headings} \DTLforeach{members}{\fnames=fnames, \surname=surname}{\expandafter\DTLinitials\expandafter{\fnames}\\surname\ }\end{document}

Stefan

Pangur
Posts: 19
Joined: Thu Jul 19, 2018 4:47 pm
Hi Stefan,
Thanks very much for this. I have now tested it, and it worked beautifully.
Much appreciated.
Calum