I am totaly inexperienced in LuaLaTeX and I don't know why but it was somehow very difficult to find working LuaLaTeX example so I can start playing around.
I finaly found the example in a document Numerical methods using LuaLaTeX (p.3):
\documentclass{article}
\usepackage{luacode}
\begin{luacode*}
function trigtable ()
for t=0, 45, 3 do
x=math.rad(t)
tex.print(string.format(
’%2d$^{\\circ}$ & %1.9f & %1.9f & %1.9f & %1.9f \\\\’, t, x, math.sin(x), math.cos(x), math.tan(x)))
end
end
\end{luacode*}
\newcommand{\trigtable}{\luadirect{trigtable()}}
\begin{document}
\begin{tabular}{rcccc}
\hline
& $x$ & $\sin(x)$ & $\cos(x)$ & $\tan(x)$ \\
\hline
\trigtable
\hline
\end{tabular}
\end{document}
What I found out from this example is, how to implement Lua code in LaTeX document and it is all great, but how come that this example fails to compile with LuaLaTeX if I save it as text.tex and process it using lualatex test.tex?
I get this command line output:
This is LuaTeX, Version 1.0.4 (TeX Live 2017/Arch Linux)
restricted system commands enabled.
(./test.tex
LaTeX2e <2017-04-15>
(using write cache: /home/ziga/.texlive/texmf-var/luatex-cache/generic)(using r
ead cache: /var/lib/texmf/luatex-cache/generic /home/ziga/.texlive/texmf-var/lu
atex-cache/generic)
luaotfload | main : initialization completed in 0.128 seconds
Babel <3.12> and hyphenation patterns for 1 language(s) loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo(load luc: /home/ziga/.texlive/
texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc)))
(/usr/share/texmf-dist/tex/lualatex/luacode/luacode.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/share/texmf-dist/tex/luatex/luatexbase/luatexbase.sty
(/usr/share/texmf-dist/tex/luatex/ctablestack/ctablestack.sty)))[\directlua]:5:
malformed number near '2d'.
\luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }
l.12 \end{luacode*}


’%2din your code (the ’ there is U+2019 RIGHT SINGLE QUOTATION MARK). If that's what you have in your real code as well, then that is probably the bug. How did it get there? Edit: Yes, changing the two occurrences of ’ to ' each allowslualatexto successfully process the file and produce a trig table as you probably intended. Is that it? – ShreevatsaR Aug 17 '17 at 18:04[[<your raw string>]]? – marsupilam Aug 17 '17 at 18:12