我是 Latex 的新手
我有一个文件,仅用于测试,ListeEleves.csv
nom,prénom
Avogadro,Amédéo
Bohr,Niels
Copernic,Nicolas
Einstein,Albert
我想得到
nom,prénom,ID,IDInitials
Avogadro,Amédéo,Avogadro-Amedeo,Avogadro-A
Bohr,Niels,Bohr-Niels,Bohr-N
Copernic,Nicolas,Copernic-Nicolas,Copernic-N
Einstein,Albert,Einstein-Albert,Einstein-A
我的代码
\documentclass[10pt,a4paper,french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array,multirow,tabularx}
\usepackage{datatool}
%\DTLsetseparator{;}
\usepackage{fp,pgf,tikz}
\usepackage{ifthen,multido}
\usepackage{babel}
\begin{document}
\DTLloaddb{ListeEleves}{ListeEleves.csv}
\DTLforeach{ListeEleves}{\nom=nom,\prenom=prénom}{%début for each
\DTLforeachkeyinrow{\ItemLu}{%début de for each key in row
%\ifthenelse{\dtlcol >2}{\dtlbreak}{%on limite la lecture aux deux premières colonnes
%suppression des lettres accentuées
\DTLsubstituteall{\ItemLu}{À}{A}
\DTLsubstituteall{\ItemLu}{à}{a}
\DTLsubstituteall{\ItemLu}{Â}{a}
\DTLsubstituteall{\ItemLu}{â}{a}
\DTLsubstituteall{\ItemLu}{È}{E}
\DTLsubstituteall{\ItemLu}{è}{e}
\DTLsubstituteall{\ItemLu}{É}{E}
\DTLsubstituteall{\ItemLu}{é}{e}
\DTLsubstituteall{\ItemLu}{Ê}{E}
\DTLsubstituteall{\ItemLu}{ê}{e}
\DTLsubstituteall{\ItemLu}{Î}{I}
\DTLsubstituteall{\ItemLu}{î}{i}
\DTLsubstituteall{\ItemLu}{Ï}{I}
\DTLsubstituteall{\ItemLu}{ï}{i}
\DTLsubstituteall{\ItemLu}{Ü}{U}
\DTLsubstituteall{\ItemLu}{ü}{u}
\DTLsubstituteall{\ItemLu}{Û}{U}
\DTLsubstituteall{\ItemLu}{û}{u}
\DTLsubstituteall{\ItemLu}{Ù}{u}
\DTLsubstituteall{\ItemLu}{ù}{u}
\DTLsubstituteall{\ItemLu}{Ô}{o}
\DTLsubstituteall{\ItemLu}{ô}{o}
\DTLsubstituteall{\ItemLu}{'}{}
\DTLsubstituteall{\ItemLu}{ }{}
%fin suppression des lettres accentuées
%}%
\DTLifeq{\dtlcol}{1}{\FPset\NOM{\ItemLu}}{\relax}
\DTLifeq{\dtlcol}{2}{\FPset\PRENOM{\ItemLu}}{\relax}
}%fin de for each key in row
\NOM \PRENOM
}%fin for each
\DTLdisplaydb{ListeEleves}
\end{document}
1)这是不是更简单的方法来编码线条\DTLifeq{\dtlcol}{1}{\FPset\NOM{\ItemLu}}{\relax}
和\DTLifeq{\dtlcol}{2}{\FPset\PRENOM{\ItemLu}}{\relax}
2)我无法自动添加带有
\DTLnewdbentry{ListeEleves}{ID}{\NOM-Prenom}
偶数\dtlgetentryfromcurrentrow
或\dtlreplaceentryincurrentrow
3)\DTLstoreinitials{\Ini}{\PRENOM}
不适用于命令名
你有什么想法吗?
谢谢
答案1
1)这是不是更简单的方法来编码线条
\DTLifeq{\dtlcol}{1}{\FPset\NOM{\ItemLu}}{\relax}
和\DTLifeq{\dtlcol}{2}{\FPset\PRENOM{\ItemLu}}{\relax}
是的,有一种更简单的方法。我不明白为什么在已经在赋值中访问过所有键的情况下还要迭代它们{\nom=nom,\prenom=prénom}
。据我所知,您正在尝试从这两个值中去除重音符号。这可以按如下方式完成(因为您正在使用\usepackage[utf8]{inputenc}
):
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{datatool}
\DTLloaddb{ListeEleves}{ListeEleves.csv}
\makeatletter
\newcommand*{\stripaccents}[2]{%
\begingroup
\def\IeC##1{\@thirdofthree##1}%
\protected@edef\x{\endgroup\noexpand\def\noexpand#1{#2}}%
\x
}
\makeatother
\begin{document}
\DTLforeach{ListeEleves}{\nom=nom,\prenom=prénom}{%
\stripaccents{\NOM}{\nom}%
\stripaccents{\PRENOM}{\prenom}%
\NOM \PRENOM
}
\DTLdisplaydb{ListeEleves}
\end{document}
2)我无法自动添加带有
\DTLnewdbentry{ListeEleves}{ID}{\NOM-Prenom}
偶数\dtlgetentryfromcurrentrow
或\dtlreplaceentryincurrentrow
你已经解决了这个问题在 LC 上交叉发布当添加包含需要扩展的命令的值时,需要打开扩展:
\dtlexpandnewvalue
\DTLforeach{ListeEleves}{\nom=nom,\prenom=prénom}{%
\stripaccents{\NOM}{\nom}%
\stripaccents{\PRENOM}{\prenom}%
\DTLappendtorow{ID}{\NOM-\PRENOM}%
}
3)
\DTLstoreinitials{\Ini}{\PRENOM}
不适用于命令名
的第一个参数\DTLstoreinitials
必须是字符串而不是命令,因为不执行任何扩展。由于您的代码中没有\Ini
,我猜您在这里把参数弄反了,并且您希望将首字母存储在中\Ini
。因此您需要执行以下操作:
\expandafter\DTLstoreinitials\expandafter{\PRENOM}{\Ini}
完整文档如下:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{datatool}
\DTLloaddb{ListeEleves}{ListeEleves.csv}
\makeatletter
\newcommand*{\stripaccents}[2]{%
\begingroup
\def\IeC##1{\@thirdofthree##1}%
\protected@edef\x{\endgroup\noexpand\def\noexpand#1{#2}}%
\x
}
\makeatother
\begin{document}
\dtlexpandnewvalue
\renewcommand*{\DTLafterinitials}{}
\DTLforeach{ListeEleves}{\nom=nom,\prenom=prénom}{%
\stripaccents{\NOM}{\nom}%
\stripaccents{\PRENOM}{\prenom}%
\DTLappendtorow{ID}{\NOM-\PRENOM}%
\expandafter\DTLstoreinitials\expandafter{\PRENOM}{\Ini}%
\DTLappendtorow{IDInitials}{\NOM-\Ini}%
}
\DTLdisplaydb{ListeEleves}
\end{document}
得出的结果为:
复制您请求的数据:
nom,prénom,ID,IDInitials
Avogadro,Amédéo,Avogadro-Amedeo,Avogadro-A
Bohr,Niels,Bohr-Niels,Bohr-N
Copernic,Nicolas,Copernic-Nicolas,Copernic-N
Einstein,Albert,Einstein-Albert,Einstein-A
答案2
\DTLforeach{ListeCompetencesEleves}{\nom=nom,\prenom=prénom}{%
\def\IdQuestion{}
\DTLforeachkeyinrow{\ItemLu}{%
\ifthenelse{\dtlcol >2}{\dtlbreak}{%
\StrSubstitute{\ItemLu}{ }{}[\ItemLu]
\StrSubstitute{\ItemLu}{'}{}[\ItemLu]
\StrSubstitute{\ItemLu}{.}{}[\ItemLu]
\StrSubstitute{\ItemLu}{-}{}[\ItemLu]
\StrSubstitute{\ItemLu}{À}{A}[\ItemLu]
\StrSubstitute{\ItemLu}{à}{a}[\ItemLu]
\StrSubstitute{\ItemLu}{Â}{A}[\ItemLu]
\StrSubstitute{\ItemLu}{â}{a}[\ItemLu]
\StrSubstitute{\ItemLu}{È}{E}[\ItemLu]
\StrSubstitute{\ItemLu}{è}{e}[\ItemLu]
\StrSubstitute{\ItemLu}{É}{E}[\ItemLu]
\StrSubstitute{\ItemLu}{é}{e}[\ItemLu]
\StrSubstitute{\ItemLu}{Ê}{E}[\ItemLu]
\StrSubstitute{\ItemLu}{ê}{e}[\ItemLu]
\StrSubstitute{\ItemLu}{Î}{I}[\ItemLu]
\StrSubstitute{\ItemLu}{î}{i}[\ItemLu]
\StrSubstitute{\ItemLu}{Ï}{I}[\ItemLu]
\StrSubstitute{\ItemLu}{ï}{i}[\ItemLu]
\StrSubstitute{\ItemLu}{Ü}{U}[\ItemLu]
\StrSubstitute{\ItemLu}{ü}{u}[\ItemLu]
\StrSubstitute{\ItemLu}{Û}{U}[\ItemLu]
\StrSubstitute{\ItemLu}{û}{u}[\ItemLu]
\StrSubstitute{\ItemLu}{Ù}{u}[\ItemLu]
\StrSubstitute{\ItemLu}{ù}{u}[\ItemLu]
\StrSubstitute{\ItemLu}{Ô}{O}[\ItemLu]
\StrSubstitute{\ItemLu}{ô}{o}[\ItemLu]
\StrSubstitute{\ItemLu}{Ö}{O}[\ItemLu]
\StrSubstitute{\ItemLu}{ö}{o}[\ItemLu]
}%
\xdef\IdQuestion{\IdQuestion\ItemLu-}
}%
\DTLgetvalue{\NOM}{ListeCompetencesEleves}{\DTLcurrentindex}{\dtlcolumnindex{ListeCompetencesEleves}{nom}}%
\DTLgetvalue{\PRENOM}{ListeCompetencesEleves}{\DTLcurrentindex}{\dtlcolumnindex{ListeCompetencesEleves}{prénom}}%
\StrChar{\PRENOM}{1}[\Initiale]%
\def\Patronyme{\NOM~\Initiale}%
\StrGobbleRight{\IdQuestion}{2}[\IdQuestion]%
\DTLappendtorow{IdQuestion}{\IdQuestion}%
\DTLappendtorow{Patronyme}{\Patronyme}%
}%