I have the below document that I try to compile with LuaLaTex (using the MiKTeX package).
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\expandafter\pgfplotstableread\directlua {
global json = utilities.json.load("test.json")
tex.sprint("{\string\r")
tex.sprint("x y\string\r")
for n, row in ipairs(json.data) do
tex.sprint(row[1] .. " " .. row[2] .. "\string\r")
end
tex.sprint("}")
}\loadedtable
\begin{tikzpicture}
\begin{axis}
\addplot table {\loadedtable};
\end{axis}
\end{tikzpicture}
\end{document}
but I get a compilation error due to a Syntax error in the Lua part:
[\directlua]:1: syntax error near 'json'.
l.17 }
\loadedtable
I'm a noob at LaTeX and unfortunately I have no clue of Lua either, but from what I have researched I can't figure out where there is a syntax error.
The respective test.json
is located in the same folder like the .tex script and has this form:
{
"name":"list_of_xy_values",
"data":[[1,2],[2,4],[3,6],[4,3],[5,0]]
}
This question refers to this other question
global
if you want to reusejson
in further Lua calls. Just removeglobal