# csvsimple command csvreader changes national letter å to a

I have just began to use the csvsimple package, where I noticed a problem with national letters. The problems occurs with the danish letter å (\aa) and Å (\AA). Before the table these letters are written normally, but after the \csvreader command. Where it actually changes both the letter and the macroes into a and A instead. Does anyone know a solution to this problem?

I have the following csv file,

Navn,c,h,r,s
4.2 A,775,693,1.12,1.42
4.2 B,883,756,1.17,1.49
4.3 B,415,768,0.541,0.688
4.3 C,479,656,0.730,0.929
4.3 D,615,712,0.864,1.10
4.3 E,594,781,0.760,0.967
5.1 A,589,763,0.772,0.982
5.1 B,610,762,0.800,1.02
5.3 A,641,762,0.841,1.07
5.3 B,593,751,0.789,1.00
Navn,4.2,4.3,5.1,5.3
s,1.45,0.921,1.00,1.04


I use the following code,

\documentclass[danish,12pt,a4paper,twoside,openright]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}
\usepackage{float}
\usepackage{csvsimple,booktabs}

\begin{document}
æøå ÆØÅ \aa\AA
\begin{table}[H]
\centering
table head=\hline Navn & c & h & r & s\\\hline]%
{Forsoeg/Tabel/ResultatTabel.csv}{}%
{\csvcoli&\csvcolii&\csvcoliii&\csvcoliv&\csvcolv}
\caption{æøå ÆØÅ \aa\AA}
\label{tab:results}
\end{table}
æøå ÆØÅ \aa\AA
\end{document}


Which generate the following

Any help is appreciated :)

• Welcome to TeX.SX! A short extract from the csv file is needed to play with. – egreg May 19 '17 at 10:25
• I can't reproduce the issue. – egreg May 19 '17 at 10:33
• I completely forgot about adding the csv file. I have added it now – Simon May 19 '17 at 11:06
• I can confirm the problem. It seems to be related to head to column names, the problem goes away if the first line in the CSV is written differently. No idea what that option is suppose to do. – daleif May 19 '17 at 11:21
• @daleif this seems to have solved the problem – Simon May 19 '17 at 12:50

What happens with head to column names is that csvsimple defines control sequences based on the contents of the first line in the .csv file. In particular, it defines \r (besides \Navn, \c, \h and \s) and does a global definition. :-(

Thus \r gets redefined multiple times and at the end it expands to nothing. Thus \aa and \AA, whose definition is \r{a} and \r{A} respectively, turn out to give just ‘a’ and ‘A’ respectively.

The idea behind this is to being able to refer to the current contents of the line as \Navn, \c, \h, \r and \s, for example with

\Navn & \c & \h & \r & \s


\csvcoli&\csvcolii&\csvcoliii&\csvcoliv&\csvcolv


However, this must apparently be avoided unless one ensures the column names don't conflict with existing macros.

Removing head to column names avoids the issue.

The problem is here:

\def\set@csv@autohead{%
\toks0=\expandafter{\csname\csv@current@col\endcsname}%
\toks1=\expandafter{\csname csvcol\romannumeral\c@csvcol\endcsname}%
\edef\csv@temp{\noexpand\gdef\the\toks0{\the\toks1}\noexpand\csv@AtEndLoop{\noexpand\gdef\the\toks0{}}}%
\csv@temp%
}


(lines 184–189 in csvsimple.sty); the \gdef is the problem.

The package should at least warn that a column name could conflict with an existing macro; better, it should keep a list of the redefined macros and restore their definitions after the action of \csvreader ends.

• Even then you'd still get into trouble if the second line of the CSV contained \aa. An interface like \Header{Navn}, \Header{c}` would probably have been better. – daleif May 19 '17 at 14:40
• @daleif Definitely better. – egreg May 19 '17 at 15:02