Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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*}


? 
share|improve this question
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
    
And the error is? –  Martin Schröder Aug 21 '13 at 22:00
add comment

1 Answer

up vote 11 down vote accepted

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

share|improve this answer
    
@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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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