5

I can't get lua and LuaLaTeX to produce a table, I am missing something in the tex.sprint line. I need LuaLaTeX to print the value and I need a new row in the table starting from the new line.

MWE

\documentclass[a4paper]{article}
\usepackage{luacode}

\begin{document}

\begin{luacode}
local a, b, c, d
a = 1
b = 1
c = 1
d = 1
tex.sprint("\\begin{tabular}{lllll}")
    
for i = 1,10
do
a = a + 1 
b = b + 1
c = c + 1
d = d + 1

if ((a + b + c + d) <= 100)
then
tex.sprint("i & a & b & c & d\\")
end
end

tex.sprint("\\end{tabular}")
\end{luacode}

\end{document}

1 Answer 1

4

You need to change the line:

tex.sprint("i & a & b & c & d\\")

into

tex.sprint("i & a & b & c & d\\\\")

since Lua changes \\ in a string into a single backslash, but you need two backslashes for a line end.

2
  • 2
    I think he want values of variables, so what he needs is tex.sprint(i.."&"..a.."&"..b.."&"..c.."&"..d.."\\\\")
    – Salim Bou
    Commented Apr 4, 2023 at 21:05
  • 1
    You could also use [[double bracket quotes]]. Then you wouldn't need to double the backslashes Commented Apr 4, 2023 at 21:11

You must log in to answer this question.

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