GeneralDTLinitials

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

DTLinitials

Post by Pangur »

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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10344
Joined: Mon Mar 10, 2008 9:44 pm

DTLinitials

Post by Stefan Kottwitz »

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:

Code: Select all

\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
LaTeX.org admin
Pangur
Posts: 29
Joined: Thu Jul 19, 2018 4:47 pm

DTLinitials

Post by Pangur »

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