2

I am trying to import a UTF-8 encoded csv file into a tabularx environment to sort the table in ascending order with respect to the first column. When compiling I get the error: Package inputenc Error: Unicode char (U+FEFF)(inputenc) not set up for use with LaTeX. \end{tabularx}.

Here is my code

\documentclass[12pt,a4paper]{report}
\usepackage{graphicx}
\usepackage{tabularx,booktabs}
\usepackage[norsk]{babel}
\usepackage{datatool}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{booktabs}
\usepackage{float}
\usepackage{textcomp}
\begin{document}
    \DTLloaddb[noheader,keys={sangnr,engelsk,norsk}]{test}{test.csv}
    \DTLsort{sangnr=ascending}{test}
\begin{table}[H]
    \scriptsize
    \begin{tabularx}{\linewidth}{>{\bfseries}l X X }
        \toprule
        \textnumero & 
        Engelsk tittel & 
        Norsk tittel \\
        \midrule
        \DTLforeach{test}{%
            \sangnr=sangnr,\eng=engelsk,\nor=norsk}{%
            \sangnr & \eng & \nor \\
        }
        \\[-\normalbaselineskip] \bottomrule
    \end{tabularx}
\end{table}
\end{document}


test.csv


%sangnr, engelsk, norsk
45, Have Thine Own Way{,} Lord, Dann meg{,} Herre
55, Jesus rose from the dead, Jesus stod opp fra døden
454, How Great Thou Art, Å{,} Store Gud

I know I can save the csv file in ANSI and write \o for ø, but this will be rather tedious in the long run. Can anyone see what I am doing wrong?

Eirik B
  • 85
  • U+FEFF is a zero-width no-break space in some versions of Unicode, and a byte order mark in others. If I make my own UTF-8 .csv with your second line (number 55), I can't reproduce the error. I've typed my own lines, and also copied and pasted your lines. Same effect: no error. There might be something weird in how your .csv was made. – Mike Renfro Mar 26 '17 at 00:43
  • The error was indeed caused by a BOM when saving from notepad. By adding \DeclareUnicodeCharacter{FEFF}{} to the preamble I got another error File ended while scanning use of \@dtl@trim.. Upon removing the % from my first line, the document compiled with no errrors! However it does not seem to sort my table anymore. The order in my csv file is 45, 55, 454. After compiling the order is 45, 454, 55. It is neither ascending or following the order in the csv file. It also prints my keys sangnr, engelsk, norsk at the buttom of the table. Any suggestions why this is happening? – Eirik B Mar 26 '17 at 10:28
  • That's got to be something in your .csv file in both cases. I wrote one by copying and pasting your included data, and it sorts numerically (45, 55, 454), regardless of their actual order in the file. – Mike Renfro Mar 26 '17 at 22:03
  • Problem resolved by saving making new file with the same content in Notepad++. Thank you so much for your input and help! – Eirik B Mar 27 '17 at 12:38

0 Answers0