1

I'm new to latex and I'm trying to work on some tables for my thesis.

After some tryouts I've been able to import some CSV tables with the desired format but I'm struggling now with the content.

Let me give you an over view of how the code works. I've created my solution based on this thread.

This produces a result with which I'm quite happy:

enter image description here

The problem I'm facing is that whenever the cells contain some specific spanish characters, as for example: í, á, ó, ... latex triggers an error when compiling, and when I recompile again, it accepts the order but it produces a table with incomplete data.

Look at what happens when I change the 'a' in the random word from the first image into 'á'.

enter image description here

The tables that I will be importing (I need to importe a lot of them :P) will definetely include these characters and I don't know what to do. I've forced the CSV files to be coded as Unicode (UTF-8), so I don't understand why I'm having problem with these characters.

Any suggestion on how to fix this or simplify my code for generating tables will be much appreciated.

Thanks a lot for your time and patience!

EDITING TO ADD WORKING EXAMPLE

On this example, if we create only the first table, everything works ok. If we try to create the second one, it throws a compilation error, and if you try to compile it again it produces a table with missing rows and characters on the changed fields. The changed fields are on cells [1, 0] & [2, 1] & [3, 2] of exampleTable3.csv

\documentclass[11pt,twoside,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{
     a4paper,
     total={140mm,217mm},
     left=35mm,
     top=40mm,
 }
 \usepackage{longtable, array, booktabs}
 \usepackage{csvsimple}

 \begin{filecontents*}{exampleTable2.csv}
     Name;Description;Format;Restrictions
     Private;textext;boolean;optional
     Gender;some more field;string;optional
     Names;field;[array of String];restriction
     Facts;field;[array of Facts];optional
 \end{filecontents*}

 \begin{filecontents*}{exampleTable3.csv}
     Name;Description;Format;Restrictions
     Prívate;textext;boolean;optional
     Gender;some mòore field;string;optional
     Names;field;[arrày of String];restriction
     Facts;field;[array of Facts];optional
 \end{filecontents*}

\begin{document}

    %printing table 2, NO SPANISH SPECIAL characters
    \csvautobooklongtable[
       separator=semicolon
    ]
    {exampleTable2.csv}

    %printing table 3, YES SPANISH SPECIAL characters
    \csvautobooklongtable[
       separator=semicolon
    ]
    {exampleTable3.csv}

\end{document}

Adding an image of the result of the above code

enter image description here

NEW EDIT: Adding example only on local

I've been experimenting with my own example and I still can't make it work. On the next picture I show the source file used, the encoding of the source file at the bottom of the image and the outcome of each one of the tables.

It seems that this should be working, so I'm not really sure why it's not. Not playing with encodings of inputs files here, just all in the same source.

enter image description here

Thanks again for your help and input!

  • What are you using the create the CSV files? Excel for the Mac, for example, does not create utf8 CSV (even though it pretends to.) – Alan Munn Aug 12 '16 at 22:55
  • I'm using microsoft excel (for windows) and forcing the format as displayed in this link – Sergi Porras Pagès Aug 12 '16 at 22:58
  • 2
    Ok. Can you turn your code into a compilable document rather than just some fragments. And also add a few sample rows of a CSV file that doesn't work. – Alan Munn Aug 12 '16 at 23:00
  • Yeah, I guess that I could change the whole code encoding from \usepackage[utf8]{inputenc} to something else, but I'm not really sure of what I should be using. Sorry, I'm not really used to encodings and I'm probably not explaining myself too well. The problem with the csv appears with any cell that has contents like: condició, col·lecció, pàgina. The cells with special characters get their contents trimmed. The rest of the latex document has no problem handling the characters. – Sergi Porras Pagès Aug 12 '16 at 23:09
  • Sorry, what I mean is change the code you've put in this question so that it makes a complete compilable document that shows the error, and add a few lines of a sample CSV file that can be used with that code. This is about the question, not about your actual document. If we can replicate your problem, then we can probably solve it too. But at the moment that's impossible. – Alan Munn Aug 12 '16 at 23:12
1

The problem you are seeing comes from different encodings of your CSV files and your source file. There are various ways that these encoding problems can arise, and it's very difficult for software to reliably detect the encoding of a file.

I was able to recreate the problem in the following way: I saved the minimal document with the latin1 encoding (but left the inputenc option as utf8). Then the file produces errors like the following:

./csvsimple-latin1.tex:42: Package inputenc Error: Unicode char íva (U+E4)
(inputenc) not set up for use with LaTeX.

Unfortunately a lot of editors push through the errors, and produce an output file anyway, which makes diagnosing the problem harder.

So the main issue is to make sure that the CSV file and your source document are the same encoding, and that the encoding is in fact the correct one. My experience with Excel for the Mac is that it doesn't actually produce UTF8 CSV files properly. Whether this is a problem with Windows versions of Excel I don't know. It's not surprising, though that you report that using CSV files from Google docs works, as they do seem to be valid UTF8.

  • This was exactly the problem. In the end, generating CSV files through a program different that microsoft excel (which let you control the encoding of the file to UTF-8 w/o BOM) worked fine. Thanks again for the help all along @Alan Munn! Hopefully I won't bother you guys anymore =) – Sergi Porras Pagès Aug 13 '16 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.