From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/32416 Path: news.gmane.org!not-for-mail From: Hans Hagen Newsgroups: gmane.comp.tex.context Subject: Re: store counter or variable and reread again Date: Mon, 01 Jan 2007 23:28:47 +0100 Message-ID: <45998B1F.8060000@wxs.nl> References: <45941026$0$4168$ba624c82@nntp02.dk.telia.net> <459670F8.5020106@elvenkind.com> <45968AED.7040904@gmx.net> <4596E9B0.8070705@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1167690544 9203 80.91.229.12 (1 Jan 2007 22:29:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 1 Jan 2007 22:29:04 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Mon Jan 01 23:29:03 2007 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1H1VeK-0005Re-FH for gctc-ntg-context-518@m.gmane.org; Mon, 01 Jan 2007 23:28:56 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id AFF8C20033; Mon, 1 Jan 2007 23:26:26 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 18075-01; Mon, 1 Jan 2007 23:26:24 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 57F0A1FEFB; Mon, 1 Jan 2007 23:26:18 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id EDF251FEFE for ; Mon, 1 Jan 2007 23:26:14 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 17390-09-4 for ; Mon, 1 Jan 2007 23:26:11 +0100 (CET) Original-Received: from mail.pragma-ade.net (dsl-083-247-100-017.solcon.nl [83.247.100.17]) by ronja.ntg.nl (Postfix) with SMTP id 07D7B1FEDF for ; Mon, 1 Jan 2007 23:26:11 +0100 (CET) Original-Received: from [10.100.1.102] (unverified [10.100.1.102]) by controller-1 (SurgeMail 3.7b8) with ESMTP id 114 for ; Mon, 01 Jan 2007 23:28:40 +0100 User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) Original-To: mailing list for ConTeXt users In-Reply-To: X-Server: High Performance Mail Server - http://surgemail.com r=-274017400 X-Authenticated-User: hagen@controller-1 X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.7 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 X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:32416 Archived-At: Aditya Mahajan wrote: > > Ahh, \lastpage uses \savecurrentvalue. I was pretty sure that I copied > the twopass some time back from \lastpage. Maybe I was dreaming, maybe > you are changing the internals too fast for me to keep up. Anyways, to > make ammends, here is the solution using \savecurrentvalue > you probably have subpage numbers in the back of your mind since they use two pass lists > % It may be better to use \setcounter series of macros. > % First let us define a general macro for adding arbitrary number to a counter > > \unprotect > \def\addtocounter#1#2% #1 name #2 value > {\@EA\xdef\csname#1\endcsname{\the\numexpr\csname#1\endcsname+#2\relax}} > \protect > > % To Hans and Taco: Should the above macro be added to syst-ext? > i've added: \def\incrementcounter#1#2% #1 name #2 value {\setxvalue{#1}{\the\numexpr\csname#1\endcsname+#2\relax}} \def\decrementcounter#1#2% #1 name #2 value {\setxvalue{#1}{\the\numexpr\csname#1\endcsname-#2\relax}} (increment is used elsewere too) > % Now lets define everything in terms of ConTeXt's counter macros > > \makecounter{Points} > > % % show the points on the right side > \def\showP[#1]{\inright{\hskip 10mm \framed{#1} }} > > \def\pkt[#1]% > {\showP[#1]% > \addtocounter{Points}{#1}} > % > > \def\nofPoints{0} % Number of points from previous run > > \def\savenofPoints > {\savecurrentvalue\nofPoints{\countervalue{Points}}} > > % It is a bit boring to type \savenofPoints everytime > > \appendtoks \savenofPoints \to \everystoptext > > % An example usage > > \starttext > > \title{This exam is of \nofPoints\ Points} > > % Lets set 10 problems with different points > \dorecurse{10} > {\pkt[\recurselevel] \input tufte \endgraf} > > \stoptext > > The whole things is much shorter :) > > Hans, I just noticed that \everystarttext is executed at the start of > components and products, while \everystoptext is not. Does it make > sense to define \stopcomponet and \stopproduct so that \everystoptext > is executed? > everystoptext is more tricky and cannot be handled in the nested case; starttext is less tricky ; both are only expanded once Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------