4

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

Let's start with something that does compile:

\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}

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

\begin{document}

\glsaddall
\printglossaries

\end{document}

Which renders to this:

enter image description here

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 
3
  • 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
3
+100

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}

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

\begin{document}

\glsaddall
\printglossaries

\end{document}

enter image description here

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}

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

\begin{document}

\glsaddall
\printglossaries

\end{document}
4
  • Thanks Ulrike. At least I have something that works now. However, I'm still not quite satisfied with the solution for two reasons: 1) This still doesn't work with longnewglossaryentry (again the can't break out of anything error), which causes issues in the display (I have a different style in the full document) 2) I'd really like the data in the csv to be just descriptive of the result. I'd don't want people that edit this to have to think about these quirks and and "latex magic" to make things work. – SeeDoubleYou Jun 12 '20 at 18:44
  • 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
  • I added an edit. – Ulrike Fischer Jun 12 '20 at 19:42
  • Thanks for that Ulrike, bounty is yours! – SeeDoubleYou Jun 15 '20 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.