# Build glossaries from csv with datatool using with longnewglossaryentry

I'm trying to build a glossary from a csv using datatool and \longnewglossaryentry. I haven't been able to get this to work.

\documentclass[10pt, a4paper]{article}
\usepackage[verbose]{datatool}
\usepackage{filecontents}
\usepackage{hyperref}
\usepackage[nopostdot]{glossaries}

\begin{filecontents*}[overwrite]{test.csv}
Name,Term,Description
"html","Hypertext Markup Language (HTML)","is a markup language"
"css","Cascading Style Sheets (CSS)","is a style sheet language"
\end{filecontents*}

\makeglossaries

\glssetexpandfield{name}
\glssetexpandfield{desc}

\DTLforeach*{data}
{%
\Name=Name,%
\Term=Term,%
\Desc=Description%
}
{%
\newglossaryentry{\Name}{
name={\Term},
description={\Desc}
}%
}

\begin{document}

\printglossaries

\end{document}


Which renders to this:

Now comes the fun part. I have certain descriptions that have an enumeration in them. If I add the following row to the csv:

"enum","","Enumeration","is a numbered list like \begin{enumerate} \item first \item second \end{enumerate}"


and recompile, I get an error:

[...]
! Incomplete \iffalse; all text was ignored after line 31.
<inserted text>
\fi
[...]


This makes sense since I'm using \newglossaryentry which doesn't support lists [See update 2, this not be the main issue]. \longnewglossaryentry does support this, but when I change \newglossaryentry to \longnewglossaryentry in my script, I get an error from datatool:

! Package datatool Error: Can't break out of anything.


And that's where I'm stuck.

## Update 1

I have seen this format being used for \longnewglossaryentry as well, where the description is given as the second argument:

\longnewglossaryentry{\Name}{
name={\Term}
}{\Desc}%


In that case, lists do work, but all descriptions will become equal to the last one set.

## Update 2

Weirdly enough, when I add the option 'verbose' to datatool (\usepackage[verbose]datatool), the error has more info, but is also different and actually equal to the error with \newglossaryentry:

New row added to database data'
Added Name -> enum to database data'
Added Term -> Enumeration to database data'
! Incomplete \iffalse; all text was ignored after line 19.
<inserted text>
\fi

• Interesting. This might be issue for the package author, Mrs. Talbot. – Tomáš Kruliš Jun 11 '20 at 8:05
• @Tomáš You think it's a bug in datatool? – SeeDoubleYou Jun 11 '20 at 8:35
• There were some issues around conditionals in glossaries (an maybe also in datatool) recently. I would guess that this error comes from expansion or grouping trouble. Anyhow, I am just a newbie and my skills are by no means sufficient to solve this. – Tomáš Kruliš Jun 11 '20 at 9:06

It breaks already when the data base is loaded. You could protect the entry in the csv:

\documentclass[10pt, a4paper]{article}
\usepackage[verbose]{datatool}
\usepackage{filecontents}
\usepackage{hyperref}
\usepackage[nopostdot]{glossaries}

\begin{filecontents*}[overwrite]{test.csv}
Name,Term,Description
"html","Hypertext Markup Language (HTML)","is a markup language"
"css","Cascading Style Sheets (CSS)","is a style sheet language"
"enum","Enumeration","is a numbered list like \unexpanded{\begin{enumerate} \item first \item second \end{enumerate}}"
\end{filecontents*}

\makeglossaries

\glssetexpandfield{name}
\glssetexpandfield{desc}

\DTLforeach*{data}
{%
\Name=Name,%
\Term=Term,%
\Desc=Description%
}
{%
\newglossaryentry{\Name}{
name={\Term},
description={\Desc}
}%
}

\begin{document}

\printglossaries

\end{document}


## Edit

Actually it fails when loading the database because of the verbose option. If one remove it remains the problem that with \glssetexpandfield{desc} \newglossaryentry tries to fully expand the description content which breaks again. This can be avoid by adding the \unexpanded there:

\documentclass[10pt, a4paper]{article}
\usepackage{datatool}
\usepackage{hyperref}
\usepackage[nopostdot]{glossaries}

\begin{filecontents*}[overwrite]{test.csv}
Name,Term,Description
"html","Hypertext Markup Language (HTML)","is a markup language"
"css","Cascading Style Sheets (CSS)","is a style sheet language"
"enum","Enumeration","is a numbered list like \begin{enumerate} \item first \item second \end{enumerate}"
\end{filecontents*}

\makeglossaries

\glssetexpandfield{name}
\glssetexpandfield{desc}

\DTLforeach*{data}
{%
\Name=Name,%
\Term=Term,%
\Desc=Description%
}
{%
\newglossaryentry{\Name}{
name={\Term},
description={\unexpanded\expandafter{\Desc}}
}%
}

\begin{document}


• Actually, longnewglossaryitem does not seem necessary after all. It turns out the problems I mentioned in the display are caused by the use inside a tabularx or something. Anyway, only point two remains. I'm actually quite happy with what I have right now, but not having to put the \unexpanded` in the csv would be the icing on the cake – SeeDoubleYou Jun 12 '20 at 19:29