From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/55191 Path: news.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: Metapost label - Truncating digits after decimal point Date: Tue, 15 Dec 2009 05:34:17 -0500 (EST) Message-ID: 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="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1260873277 17096 80.91.229.12 (15 Dec 2009 10:34:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Dec 2009 10:34:37 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Dec 15 11:34:30 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 1NKUje-0005gy-93 for gctc-ntg-context-518@m.gmane.org; Tue, 15 Dec 2009 11:34:30 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id C363BC9BA6; Tue, 15 Dec 2009 11:34:23 +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 ROneLjjDKC7C; Tue, 15 Dec 2009 11:34:12 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 0B052C9ADD; Tue, 15 Dec 2009 11:34:12 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 66E21C9ADD for ; Tue, 15 Dec 2009 11:34:11 +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 W+K2dHLoNbtP for ; Tue, 15 Dec 2009 11:34:09 +0100 (CET) Original-Received: from hellskitchen.mr.itd.umich.edu (smtp.mail.umich.edu [141.211.14.82]) by balder.ntg.nl (Postfix) with ESMTP id CD4C1C9AD9 for ; Tue, 15 Dec 2009 11:34:08 +0100 (CET) Original-Received: FROM [192.168.2.8] (c-76-28-91-31.hsd1.ct.comcast.net [76.28.91.31]) By hellskitchen.mr.itd.umich.edu ID 4B27661E.EEA2F.20117 ; Authuser adityam; 15 Dec 2009 05:34:07 EST In-Reply-To: <3b4b12310911280656x6c4b5023g112ba92b278d5df4@mail.gmail.com> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) 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:55191 Archived-At: 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 def truncatedtext(expr s) = textext("\truncate{" & s & "}") enddef ; \stopMPdefinitions \starttext \startuseMPgraphic{Figure} u := 1cm; pickup pencircle scaled 2pt; % default pen thickness %TheFunction vardef f(expr x) = (10/x)-x*((0.5)**x) enddef; %Labels %label.lft(textext("\truncate{" & decimal f(5) & "}"),(0,f(5)) scaled u); label.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 : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________