What are differences, which to use for including .csv, .tsv files ? Datatool ? pgfplotstable ?

I've seen at question : How typeset a numeric table from a CSV file

how person asked about fixing datatool issue, and answer was to use pgfplotstable

Are there other options for including tabular data into documents ?

What are advantages and disadvantages of possible choices ?

  • I've added a datatool solution to the linked question.
    – Alan Munn
    Feb 13, 2012 at 14:08

2 Answers 2


Maybe you want to give LuaLaTeX a try. It's very easy to write a script to read external files and format LaTeX commands. It is good practice to write the lua functions in a separate file with the extension .lua. For this MWE I use the filecontents environment instead to provide an extra file for the lua script and the datafile.

Here is an other example for reading csv files with LuaLaTeX: https://tex.stackexchange.com/a/41499/10570.


%create a datafile
30.0,   0.0,    0.0
60.0,   1.9098, 5.8779
90.0,   6.9098, 9.5106
120.0,  13.09,  9.5106
150.0,  18.09,  5.8779
180.0,  20.0,   0.0

%create a lua script file
 function readDataFile()

    local input = io.open('datafile.csv', 'r')
    dataTable = {} --global table for storing the read values

    for line in input:lines() do

        --split the line with the comma delimiter 
        local split = string.explode(line, ",")

        --save the arguments in variables
        tableItem = {}
        tableItem.arg1 = split[1]
        tableItem.arg2 = split[2]
        tableItem.arg3 = split[3]

        --insert the arguments of one line in the table
        table.insert(dataTable, tableItem)


function printTable()
    tex.print(string.format("Column 1 & Column 2 & Column 3\\\\\\hline"))

    --create a latex string for every table entry
    for i,p in ipairs(dataTable) do
        tex.print(string.format(" {%s} & {%s} & {%s} \\\\",p.arg1, p.arg2, p.arg3))


% read the external lua file to declare the defined functions,
% but without execute the Lua commands and functions

% latex commands to execute the lua functions

  • In future I am planning to try LuaLaTeX as I've programmed in past in Lua and liked this scripting language a lot ! Currently I am working with book, with many custom typesettings tailored for pdflatex. So not now, but in future - I'd love to. Your example will be one of my starting points :). Feb 12, 2012 at 15:16

Both datatool and pgfplotstable can do similar things, but datatool is designed as a more general tool and therefore can in principle do more things (e.g. form letters and the like). So if your requirements are simply pretty printing tables directly from CSV files I might prefer pgfplotstables since it is especially designed for that, and if you are independently used to using TiKZ, has a nice key-value syntax that is very easy to use. If you have more complicated things you might need to do with your CSV data, then datatool might be a better choice.

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.