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}
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)
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
\def\readDataFile{\directlua{readDataFile()}}
\def\printTable{\directlua{printTable()}}
\begin{document}
\readDataFile
\printTable
\end{document}
datatool
solution to the linked question.