Generaldatatool package help

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
proxima
Posts: 2
Joined: Fri Nov 11, 2011 1:03 am

datatool package help

Post by proxima »

I have a problem with datatool package while trying to get only the first row.
I want to get \foo with the value of the first row outside the cycle.

Code: Select all

\documentclass[a4paper,11pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[italian]{babel}
\usepackage{datatool}
\begin{document}
\DTLloaddb{elenconote2}{note.txt}
\DTLforeach*[\value{DTLrowi}<1]{elenconote2}{\1=name}{%
\gdef\foo{\1}
this is the first row: \foo
\\
}
this should be the first row: \foo
\end{document}
this is the external file (note.txt):

Code: Select all

name
01
02
03
and this is the result (PDF file):

Code: Select all

this is the rst row: 01
this should be the rst row: 03
Why 03 and not 01 ?
Someone please help me to find the error. Thank you.
Last edited by proxima on Fri Nov 11, 2011 2:27 pm, edited 1 time in total.

Recommended reading 2024:

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

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

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Re: datatool package help

Post by nlct »

Use \xdef instead of \gdef so that \foo gets set to the expanded value of \1 rather than \1.

Regards
Nicola Talbot
proxima
Posts: 2
Joined: Fri Nov 11, 2011 1:03 am

Re: datatool package help

Post by proxima »

It works perfectly. Many thanks again for your quick response and for this wonderful package, your work is fully aprreciated.
Post Reply