Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-15 Thread Peter Münster
On Sun, Feb 14 2010, Hans Hagen wrote: sqrt = math.sqrt pi = math.pi function my_equation(s, r) beware, this creates (and possibly overloads) sqrt, pi and my_equation as gobals Indeed... The following hack was *not* so quick, but there is a bug somewhere (a digit is added at the

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-15 Thread Hans Hagen
On 15-2-2010 20:35, Peter Münster wrote: tex.write(r:gsub(%., ,)) tex.write((r:gsub(%., ,))) gsub returns two values - Hans Hagen | PRAGMA ADE Ridderstraat 27 |

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-15 Thread Andreas Harder
Am 15.02.2010 um 20:35 schrieb Peter Münster: On Sun, Feb 14 2010, Hans Hagen wrote: sqrt = math.sqrt pi = math.pi function my_equation(s, r) beware, this creates (and possibly overloads) sqrt, pi and my_equation as gobals Indeed... The following hack was *not* so quick,

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-15 Thread Peter Münster
On Mon, Feb 15 2010, Andreas Harder wrote: But the $·$-construct is problematic. It do not work in display style (\let\calcmath\displaycalcmath) and without the dollar-signs the placement and the spacing are wrong. I don't know, why · doesn't work, but you can try this: local

[NTG-context] Formatting numbers in LuaTeX

2010-02-14 Thread Andreas Harder
Hi all! I played a little bit with LuaTeX in ConTeXt and two questions have arisen. \usemodule[calcmath] \starttext \def\calculate#1{\calcmath{#1=\ctxlua{tex.print(#1)}}} \calculate{1+2} \par \calculate{3/2-1}\par % the output should be 0,5 \calculate{3*2}\par % \calculate{sqrt(2)}

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-14 Thread luigi scarso
On Sun, Feb 14, 2010 at 11:42 AM, Andreas Harder andreas.har...@rz-online.de wrote: Hi all! I played a little bit with LuaTeX in ConTeXt and two questions have arisen. \usemodule[calcmath] \starttext \def\calculate#1{\calcmath{#1=\ctxlua{tex.print(#1)}}} \calculate{1+2} \par

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-14 Thread 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

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-14 Thread Andreas Harder
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

Re: [NTG-context] Formatting numbers in LuaTeX

2010-02-14 Thread Hans Hagen
On 14-2-2010 14:10, Andreas Harder wrote: \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(*, $·$) .. = ..