5

I try to compile this code without success.

\documentclass[a4paper,12pt]{article}
\usepackage[upright]{fourier}
\usepackage[no-math]{fontspec}
\usepackage{luacode,luatextra,luaotfload}
\begin{document}
\begin{luacode*}
tex.print("\\begin{tabular}{c|c}")
tex.print("x & y \\\\\\hline")
for i=-1,5,1.0 do
  tex.print(..i "&" ..-i^2 + 5*i - 8 "\\\\\\hline")
end
tex.print("\\end{tabular}")
\end{luacode*}
\end{document}

The compilation returns the following message :

! LuaTeX error [string "\directlua "]:4: unexpected symbol near '..'.
\luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }

l.13 \end{luacode*}


? 
  • 2
    If my answer solves your problem, you might consider accepting it. This way future users see immediately that they can "trust" the accepted answer. – topskip Aug 20 '13 at 20:25
  • 1
    And the error is? – Martin Schröder Aug 21 '13 at 22:00
12

You have it almost correct:

\documentclass[a4paper,12pt]{article}
\usepackage[upright]{fourier}
\usepackage[no-math]{fontspec}
\usepackage{luacode,luatextra,luaotfload}

\begin{document}
\begin{luacode*}
tex.print("\\begin{tabular}{c|c}")
tex.print("x & y \\\\\\hline")
for i=-1,5 do
  tex.print(i .. "&" ..-i^2 + 5*i - 8 .. "\\\\\\hline")
end
tex.print("\\end{tabular}")
\end{luacode*}
\end{document}

You have the .. in the wrong place. (And a missing document environment, but that is obvious :-))

screenshot_with_table

  • @topskipI actually forgot \begin{document}, it is a blunder ! For bad positioning .., this is my first code with Lua. How to replace tex.print("x & y \\\\\\hline") by tex.print("$x$ & $f(x)$ \\\\\\hline") ? – Fabrice Aug 20 '13 at 14:05
  • 1
    @Fabrice Replacing the line works just fine. I don't see a problem in the code. – topskip Aug 20 '13 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.