假设我有一个.csv
文件,里面有国际音标协会 (IPA)、它们的注释,以及我想要合并到文档中的翻译。
但是,使用datatool
循环.csv
不能与gb4e
间距宏一起使用\gll
。
比较:
到:
我认为问题可能是将\IPA
命令放在单个\textipa{}
命令中,但即使是第二个版本,\textipa{}
命令出现在.csv
文件内部而不是\DTLforeach
循环中,也会导致同样的问题。
平均能量损失
\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}
答案1
从理论上来说这应该可行:
\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}
}
然而,似乎存在一个错误,导致加载 csv 文件时丢失datatool
第一组括号。因此,第一个条目加载为\textipa{sonj2n-i}
\textipa sonj2n-i \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta}
代替
\textipa{sonj2n-i} \textipa{motun} \textipa{kuki-lul} \textipa{an-m2k-ess-ta}
可以通过更改列顺序或插入空括号来解决此问题:
\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*}
或者插入一个空列:
\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*}
我会看看是否能找出导致该错误的原因。以下是完整的 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}
得出的结果为: