Am 14.02.2010 um 13:11 schrieb Peter Münster: > On Sun, Feb 14 2010, Andreas Harder wrote: > >> 1) Is it possible to have a comma as decimal separator? >> >> 2) If you look at the above definition, it works fine with +, –, /, but >> not with *. Is it possible to expand my macro that it will also work with >> a multiplication or even with the last two examples? > > Hello Andreas, > > Just a quick hack: > > \usemodule[calcmath] > \startluacode > sqrt = math.sqrt > pi = math.pi > function my_equation(s, r) > r = tostring(r) > tex.print(s:gsub("*", "×") .. "=" .. r:gsub("%.", ",")) > end > \stopluacode > \def\calculate#1{\calcmath{\ctxlua{my_equation("#1", #1)}}} > \starttext > \startlines > \calculate{1+2} > \calculate{3/2-1} > \calculate{3*2} > \calculate{sqrt(2)} > \calculate{2*pi} > \stoplines > \stoptext
That’s nice! Thank you very much! I've found an posting on the LuaTeX-mailing-list and incorporated it, so one have rounded results (I didn't find a way to use "\%.2f"). So, if someone is interested: \usemodule[calcmath] \startluacode local floor = math.floor local round = function(n) return floor(1000*n+0.5)/1000 end sqrt = math.sqrt pi = math.pi function my_equation(s, r) r = round(r) r = tostring(r) tex.print(s:gsub("*", "$·$") .. "=" .. r:gsub("%.", ",")) end \stopluacode \def\calculate#1{\calcmath{\ctxlua{my_equation("#1", #1)}}} \starttext \startlines \calculate{1+2} \calculate{3/2-1} \calculate{3*2} \calculate{sqrt(2)} \calculate{2*pi} \stoplines \stoptext Greetings Andreas ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________