From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/56263 Path: news.gmane.org!not-for-mail From: Andreas Harder Newsgroups: gmane.comp.tex.context Subject: Re: Formatting numbers in LuaTeX Date: Sun, 14 Feb 2010 14:10:17 +0100 Message-ID: References: <6B43096F-E43D-4492-BDB7-ED22DAE97ECE@rz-online.de> <20100214121138.GA13222@gaston.couberia.bzh> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1266164519 2393 80.91.229.12 (14 Feb 2010 16:21:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Feb 2010 16:21:59 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sun Feb 14 17:21:55 2010 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NghEJ-0006o9-5A for gctc-ntg-context-518@m.gmane.org; Sun, 14 Feb 2010 17:21:55 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 501A5C9D06; Sun, 14 Feb 2010 17:21:54 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Te9bC4n1PTqS; Sun, 14 Feb 2010 17:21:50 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1F02AC9C99; Sun, 14 Feb 2010 17:21:50 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 1963AC9C99 for ; Sun, 14 Feb 2010 17:21:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Zn831upvuaht for ; Sun, 14 Feb 2010 17:21:40 +0100 (CET) Original-Received: from deliver.uni-koblenz.de (deliver.uni-koblenz.de [141.26.64.15]) by balder.ntg.nl (Postfix) with ESMTP id B9B2CC9C8A for ; Sun, 14 Feb 2010 17:21:39 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 03BD178A430E for ; Sun, 14 Feb 2010 16:33:11 +0100 (CET) Original-Received: from deliver.uni-koblenz.de ([127.0.0.1]) by localhost (deliver.uni-koblenz.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05135-02 for ; Sun, 14 Feb 2010 16:33:09 +0100 (CET) X-CHKRCPT: Envelopesender noch aharder@uni-koblenz.de Original-Received: from [192.168.1.112] (77-23-29-238-dynip.superkabel.de [77.23.29.238]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTP id 3DB3778A41A8 for ; Sun, 14 Feb 2010 14:10:18 +0100 (CET) In-Reply-To: <20100214121138.GA13222@gaston.couberia.bzh> X-Mailer: Apple Mail (2.1077) X-Virus-Scanned: amavisd-new at uni-koblenz.de X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:56263 Archived-At: Am 14.02.2010 um 13:11 schrieb Peter M=FCnster: > 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 +, =96, /, 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 =3D math.sqrt > pi =3D math.pi > function my_equation(s, r) > r =3D tostring(r) > tex.print(s:gsub("*", "=D7") .. "=3D" .. 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=92s nice! Thank you very much! = I've found an posting on the LuaTeX-mailing-list and incorporated it, so on= e have rounded results (I didn't find a way to use "\%.2f"). So, if someone= is interested: \usemodule[calcmath] \startluacode local floor =3D math.floor local round =3D function(n) return floor(1000*n+0.5)/1000 end sqrt =3D math.sqrt pi =3D math.pi function my_equation(s, r) r =3D round(r) r =3D tostring(r) tex.print(s:gsub("*", "$=B7$") .. "=3D" .. 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 t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________