I have the below document that I try to compile with LuaLaTex (using the MiKTeX package).




\expandafter\pgfplotstableread\directlua {
    global json = utilities.json.load("test.json")
    tex.sprint("x y\string\r")
    for n, row in ipairs(json.data) do
        tex.sprint(row[1] .. " " .. row[2] .. "\string\r")

    \addplot table {\loadedtable};

but I get a compilation error due to a Syntax error in the Lua part:

[\directlua]:1: syntax error near 'json'.
l.17 }

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:


This question refers to this other question

  • Variables are global by default in Lua. No need to add global if you want to reuse json in further Lua calls. Just remove global
    – user226564
    Dec 28, 2020 at 16:36
  • That was the problem, thank you! If you add a short answer, I'll accept it.
    – Sim Son
    Dec 28, 2020 at 16:43

1 Answer 1


Variables in Lua are global by default, so only local has to be explicitly stated. See a brief explanation on Lua Unofficial FAQ and Lua 5.3 Reference Manual for additional info. In LuaTeX's \directlua and luacode environments is usual to define variables as local, what you can see in Henri's answer to your other question, to avoid clashes and unexpected redefinitions. :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .