The macro runs except when the real b is negative. Why ?
\documentclass[a4paper,12pt]{article}
\usepackage[upright]{fourier}
\usepackage[no-math]{fontspec}
\usepackage{luacode,luatextra,luaotfload}
\begin{document}
\newcommand\racine[3]{%
\luaexec{
local d=math.pow(#2,2)-4*#1*#3
local r_1
local r_2
local r
if d>0 then
r_1=(-#2-math.sqrt(d))/2*#1
r_2=(-#2+math.sqrt(d))/2*#1
tex.print("The discriminant is\\ " .. d .. ".\\par")
tex.print("The first root is\\ " .. r_1 .. ".\\par")
tex.print("The second root is\\ " .. r_2 .. ".\\par")
elseif d==0 then
r=-#2/2*#1
tex.print("The discriminant is\\ " .. d .. ".\\par")
tex.print("The double root is\\ " .. r .. ".\\par")
elseif d < 0 then
tex.print("The discriminant is\\ " .. d .. ".\\par")
tex.print("There are no real solutions.")
end
}}
\racine{10}{-3}{5}
\end{document}
The error message is :
! LuaTeX error [string "\directlua "]:1: unexpected symbol near <eof>.
\luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }
l.28 \racine{10}{-3}{5}
?
I would like the solutions, when possible, be written as a fraction.