1

Say that I have a .csv file with sentences in IPA, their glosses, and their translations that I want to incorporate into a document.

However, using datatool to loop over the .csv doesn't work with gb4e's spacing macro, \gll.

Compare:

enter image description here

To:

enter image description here

I thought the problem might be putting the \IPA command inside a single \textipa{} command, but even the second version where the \textipa{} commands appear inside the .csv file rather than in the \DTLforeach loop leads to the same problem.

MWE

\documentclass{article}

\begin{filecontents*}{glosses1.csv}
IPA,GLOSS,TRANSLATION
sonj2n-i motun kuki-lul an-m2k-ess-ta,boy-NOM all cookie-ACC NEG-eat-PST-DEC,The boy didn't eat every cookie
\end{filecontents*}

\begin{filecontents*}{glosses2.csv}
IPA,GLOSS,TRANSLATION
\textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta},boy-NOM all cookie-ACC NEG-eat-PST-DEC,The boy didn't eat every cookie
\end{filecontents*}

\usepackage{datatool}
\DTLloaddb{glosses1}{glosses1.csv}
\DTLloaddb{glosses2}{glosses2.csv}

\usepackage[T1]{tipa}
\usepackage{gb4e}

\begin{document}

\section{How it ought to look}

\begin{exe}
    \ex[]{\gll \textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta} \\
    boy-NOM all cookie-ACC NEG-eat-PST-DEC \\
    \trans `The boy didn't eat every cookie'
    }
\end{exe}

\section{What it actually looks like}

\DTLforeach{glosses1}{%
\IPA=IPA,
\GLOSS=GLOSS,
\TRANS=TRANSLATION}{%
\begin{exe}
    \ex[]{\gll \textipa{\IPA} \\
    \GLOSS \\
    \trans `\TRANS'}
\end{exe}
}

\DTLforeach{glosses2}{%
\IPA=IPA,
\GLOSS=GLOSS,
\TRANS=TRANSLATION}{%
\begin{exe}
    \ex[]{\gll \IPA \\
    \GLOSS \\
    \trans `\TRANS'}
\end{exe}
}

\end{document}
2
  • This has nothing to do with datatool. You can't pass a macro to \gll and have it separate the words inside the macro.
    – Alan Munn
    Nov 4, 2014 at 0:51
  • @AlanMunn Ah, right. That makes sense. Is there a way to force it to expand, then, before it gets passed to \gll?
    – Adam Liter
    Nov 4, 2014 at 1:14

1 Answer 1

3

In theory this ought to work:

\DTLforeach{glosses2}{%
\IPA=IPA,
\GLOSS=GLOSS,
\TRANS=TRANSLATION}{%
\begin{exe}
\edef\doex{%
    \noexpand\ex[]{\noexpand\gll 
      \expandonce\IPA \noexpand\\
    \expandonce\GLOSS \noexpand\\
    \noexpand\trans `\expandonce\TRANS'}%
}
\doex
\end{exe}
}

However it seems there's a bug in datatool that's causing the first set of braces in \textipa{sonj2n-i} to be lost on loading the csv file. So the first entry is loaded as

\textipa sonj2n-i \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta}

Instead of

\textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta}

This can be fixed either by changing the column order or by inserting an empty brace:

\begin{filecontents*}{glosses2.csv}
IPA,GLOSS,TRANSLATION
{}\textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta},boy-NOM all cookie-ACC NEG-eat-PST-DEC,The boy didn't eat every cookie
\end{filecontents*}

Or by inserting an empty column:

\begin{filecontents*}{glosses2.csv}
,IPA,GLOSS,TRANSLATION
,\textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta},boy-NOM all cookie-ACC NEG-eat-PST-DEC,The boy didn't eat every cookie
\end{filecontents*}

I'll see if I can find out what's causing the bug. Here's the full MWE:

\documentclass{article}

\begin{filecontents*}{glosses2.csv}
,IPA,GLOSS,TRANSLATION
,\textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta},boy-NOM all cookie-ACC NEG-eat-PST-DEC,The boy didn't eat every cookie
\end{filecontents*}

\usepackage{etoolbox}
\usepackage{datatool}
\DTLloaddb{glosses2}{glosses2.csv}

\usepackage[T1]{tipa}
\usepackage{gb4e}

\begin{document}

\section{How it ought to look}

\begin{exe}
    \ex[]{\gll \textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta} \\
    boy-NOM all cookie-ACC NEG-eat-PST-DEC \\
    \trans `The boy didn't eat every cookie'
    }
\end{exe}

\section{What it actually looks like}

\DTLforeach{glosses2}{%
\IPA=IPA,
\GLOSS=GLOSS,
\TRANS=TRANSLATION}{%
\begin{exe}
\edef\doex{%
    \noexpand\ex[]{\noexpand\gll 
      \expandonce\IPA \noexpand\\
    \expandonce\GLOSS \noexpand\\
    \noexpand\trans `\expandonce\TRANS'}%
}
\doex
\end{exe}
}

\end{document}

This produces:

Image of document

1
  • Thanks, Nicola! This is perfect for my purposes, at least, as the IPA column isn't the first column in my actual .csv file.
    – Adam Liter
    Nov 4, 2014 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .