From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/6291 Path: main.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: Calculating in TeX Date: Mon, 10 Dec 2001 09:46:19 +0100 Sender: owner-ntg-context@let.uu.nl Message-ID: <5.1.0.14.1.20011210093439.0315a0f0@server-1> References: NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Trace: main.gmane.org 1035396823 9165 80.91.224.250 (23 Oct 2002 18:13:43 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 23 Oct 2002 18:13:43 +0000 (UTC) Cc: Original-To: Tobias Burnus In-Reply-To: Xref: main.gmane.org gmane.comp.tex.context:6291 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:6291 At 10:31 PM 12/5/2001 +0100, Tobias Burnus wrote: >Hi, > >I have a nice document where I need to perform small calculation (actually >only calculating the average value): > if((#1+#2+#3) != 0) > (#1*1 + #2*2 + #3*3)/(#1+#2+#3) > else > "--" > >Now I was thinking where I could do so in TeX. (I think there are some >macros in ConTeXt, but I cannot find them.) You can play a bit with etex's \dimexpr and \numexpr (docu on tex live) \def\Tobiased#1#2#3% {\ifdim\dimexpr(#1pt+#2pt+#3pt)=\zeropoint \else \expandafter\withoutpt\the\dimexpr (\dimexpr(1\dimexpr(#1pt) + 2\dimexpr(#2pt) + 3\dimexpr(#3pt))/ \dimexpr( #1pt + #2pt + #3pt)) \fi} \Tobiased{10}{150}{310.2} So, te numbers become dimens and are stripped afterwards >The output should be of the form "1{,}4" (i.e. separator is a {,} and I >get one figure after the separator). How about: \def\OneAfter#1% {\expandafter\beforesplitstring#1\at.\to\Before \expandafter\aftersplitstring#1\at.\to\After \Before.\expandafter\AfterIndeed\After0000\relax} \def\AfterIndeed#1#2#3\relax{#1} \OneAfter{1.23} \OneAfter{1} \def\Oeps{1.234} \OneAfter\Oeps You can probably figure out the rest Hans ------------------------------------------------------------------------- Hans Hagen | PRAGMA ADE | pragma@wxs.nl Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com -------------------------------------------------------------------------