From: Hans Hagen <pragma@wxs.nl>
Cc: <ntg-context@ntg.nl>
Subject: Re: Calculating in TeX
Date: Mon, 10 Dec 2001 09:46:19 +0100 [thread overview]
Message-ID: <5.1.0.14.1.20011210093439.0315a0f0@server-1> (raw)
In-Reply-To: <Pine.BSF.4.30.0112052223001.3513-100000@chip.physik.fu-ber lin.de>
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
-------------------------------------------------------------------------
next parent reply other threads:[~2001-12-10 8:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.BSF.4.30.0112052223001.3513-100000@chip.physik.fu-ber lin.de>
2001-12-10 8:46 ` Hans Hagen [this message]
2001-12-06 14:06 e_w_g
-- strict thread matches above, loose matches on Subject: below --
2001-12-05 21:31 Tobias Burnus
2001-12-06 9:50 ` Giuseppe Bilotta
2001-12-06 11:27 ` Taco Hoekwater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5.1.0.14.1.20011210093439.0315a0f0@server-1 \
--to=pragma@wxs.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).