From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/55220 Path: news.gmane.org!not-for-mail From: Curiouslearn Newsgroups: gmane.comp.tex.context Subject: Re: Metapost label - Truncating digits after decimal point Date: Tue, 15 Dec 2009 22:38:30 -0500 Message-ID: <3b4b12310912151938g3dcec3p1b8d3f752f7eb2e0@mail.gmail.com> References: <3b4b12310911280656x6c4b5023g112ba92b278d5df4@mail.gmail.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1260934739 27104 80.91.229.12 (16 Dec 2009 03:38:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Dec 2009 03:38:59 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Dec 16 04:38:51 2009 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.50) id 1NKkix-0003CP-O7 for gctc-ntg-context-518@m.gmane.org; Wed, 16 Dec 2009 04:38:51 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 7554BC9C85; Wed, 16 Dec 2009 04:38:47 +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 ywP36DTQWYp7; Wed, 16 Dec 2009 04:38:42 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id ED740C9AC7; Wed, 16 Dec 2009 04:38:41 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 61044C9AC7 for ; Wed, 16 Dec 2009 04:38:37 +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 7PtHT93tRLRq for ; Wed, 16 Dec 2009 04:38:32 +0100 (CET) Original-Received: from mail-pz0-f179.google.com (mail-pz0-f179.google.com [209.85.222.179]) by balder.ntg.nl (Postfix) with ESMTP id 37761C9A8A for ; Wed, 16 Dec 2009 04:38:32 +0100 (CET) Original-Received: by pzk9 with SMTP id 9so382136pzk.16 for ; Tue, 15 Dec 2009 19:38:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=fto4O3GQcUN6rF1ibJRimIB7tpReKdkw8LUSWK2OBso=; b=kL4CsM7YxaI9mgR9wKpN+Tvr2ipwIUhiVOoAOsGJFtvu/tUqtmWwWIR3EUtq+k7FTf GN8POpgkQnApGImP9YS8E+EKkcWzMxw1yVO/x1zeJdVY50vRcU0oVtgwvud5Wuz7sgim 7TmCIxOPh8SwpyV/ShtS429CF9yMEUrcGctuA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Qb5S4avU+1O1DMQqwzQkYi6tdpaDlr/L56z5AqNjKcqMw/imLasiiWw9jvamO+7/7Q jWgS3lkS23W5FcOKV+IBo/F6ysh+kdfdJj9OI24lFRaUzYlC/ZZD3MVeOBEDvG+xBl1P ieBS6fVtNo0v9DZ+Arw8GWDEeeD9/k2Unt+4k= Original-Received: by 10.142.151.13 with SMTP id y13mr295236wfd.253.1260934710917; Tue, 15 Dec 2009 19:38:30 -0800 (PST) In-Reply-To: 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:55220 Archived-At: Thanks for this solution. Sounds small and clean. I need to learn Lua I gue= ss. On Tue, Dec 15, 2009 at 5:34 AM, Aditya Mahajan wrote: > On Sat, 28 Nov 2009, Curiouslearn wrote: > >> Hi, >> >> Is it possible to truncate the digits after decimal point in Metapost >> when using textext()? Please see the minimal example below which >> produces 1.84375. Can I just keep the first digit and have it produce >> 1.8 ? >> >> Thanks. > > If you are using mkiv, you can use lua to truncate a number. > > \unexpanded\def\truncate#1{\ctxlua{context("\%.1f", #1)}} > > \startMPdefinitions > =A0def truncatedtext(expr s) =3D > =A0 =A0textext("\truncate{" & s & "}") > =A0enddef ; > \stopMPdefinitions > > \starttext > \startuseMPgraphic{Figure} > =A0u :=3D 1cm; > =A0pickup pencircle scaled 2pt; % default pen thickness > =A0%TheFunction > =A0vardef f(expr x) =3D > =A0 =A0 =A0 =A0 =A0(10/x)-x*((0.5)**x) > =A0enddef; > =A0%Labels > =A0%label.lft(textext("\truncate{" & decimal f(5) & "}"),(0,f(5)) scaled = u); > =A0label.lft(truncatedtext(decimal f(5)),(0,f(5)) scaled u); > \stopuseMPgraphic > \useMPgraphic{Figure} > > > \stoptext > > Aditya > _________________________________________________________________________= __________ > 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 =A0: http://www.pragma-ade.nl / http://tex.aanhet.net > archive =A0: http://foundry.supelec.fr/projects/contextrev/ > wiki =A0 =A0 : http://contextgarden.net > _________________________________________________________________________= __________ > ___________________________________________________________________________= ________ 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 ___________________________________________________________________________= ________