# pgfplotstable or datatool?

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

Are there other options for including tabular data into documents ?

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

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.

\documentclass{book}
\usepackage{filecontents}

%create a datafile
\begin{filecontents*}{datafile.csv}
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
\end{filecontents*}

%create a lua script file
\begin{filecontents*}{luaFunctions.lua}

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)
end

input:close()
end

function printTable()
tex.print(string.format("\\begin{tabular}{c|c|c}"))
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))
end

tex.print(string.format("\\end{tabular}"))
end
\end{filecontents*}

% read the external lua file to declare the defined functions,
% but without execute the Lua commands and functions
\directlua{dofile("luaFunctions.lua")}

% latex commands to execute the lua functions