From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/32379 Path: news.gmane.org!not-for-mail From: Aditya Mahajan Newsgroups: gmane.comp.tex.context Subject: Re: store counter or variable and reread again Date: Sat, 30 Dec 2006 11:56:39 -0500 (EST) Message-ID: References: <45941026$0$4168$ba624c82@nntp02.dk.telia.net> <459670F8.5020106@elvenkind.com> <45968AED.7040904@gmx.net> 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 1167497823 29284 80.91.229.12 (30 Dec 2006 16:57:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 30 Dec 2006 16:57:03 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Sat Dec 30 17:57:01 2006 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 1H0hVy-0000XH-Fh for gctc-ntg-context-518@m.gmane.org; Sat, 30 Dec 2006 17:56:58 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 473042001C; Sat, 30 Dec 2006 17:54:44 +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 31466-02-4; Sat, 30 Dec 2006 17:54:36 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 47D781FFF6; Sat, 30 Dec 2006 17:54:36 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id CC19320002 for ; Sat, 30 Dec 2006 17:54:33 +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 31466-02-3 for ; Sat, 30 Dec 2006 17:54:29 +0100 (CET) Original-Received: from hackers.mr.itd.umich.edu (smtp.mail.umich.edu [141.211.14.81]) by ronja.ntg.nl (Postfix) with SMTP id 8C46E1FFEE for ; Sat, 30 Dec 2006 17:54:28 +0100 (CET) Original-Received: FROM aditya.annarb01.mi.comcast.net (c-68-40-50-205.hsd1.mi.comcast.net [68.40.50.205]) BY hackers.mr.itd.umich.edu ID 45969A48.1AAB5.1604 ; 30 Dec 2006 11:56:40 -0500 Original-To: mailing list for ConTeXt users In-Reply-To: <45968AED.7040904@gmx.net> 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:32379 Archived-At: On Sat, 30 Dec 2006, Thomas Engel wrote: > Hello, > > i just playing a little bit with macros. > For adding points to a total sum i use this macros > > \global\newcount\summeP \summeP=0 > % ad the points of each question > \def\getPunkte[#1]{\global\advance\summeP by \number#1} > % show the points on the right side > \def\showP[#1]{\inright{\hskip 10mm \framed{#1} }} > % handle the points > \def\pkt[#1]% > {\showP[#1]% > \getPunkte[#1] } > > this is working well but my problem is I want to use \summeP on the > first page to show the total amount of points for the whole exam. > > I know that this needs a second run of texexec, but I don't know how to > store the value at the end of the file and reread this stored value in a > second run the get the right value. Here is how to do the second run. I also use ConTeXt macros (\makecounter etc) instead of plain TeX. Be careful of spurious linebreaks. % It may be better to use \setcounter series of macros for managing counters. % 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? % Now lets define everything in terms of ConTeXt's counter macros % \global\newcount\summeP \makecounter{Points} % I changed summeP to Points just to be consistent % \summeP=0 % \makecounter sets the value of counter to 0. % % ad the points of each question % \def\getPunkte[#1]{\global\advance\summeP by \number#1} % This macro is already been defined using numexpr above. % % show the points on the right side \def\showP[#1]{\inright{\hskip 10mm \framed{#1} }} % % handle the points \def\pkt[#1]% {\showP[#1]% % \getPunkte[#1] } \addtocounter{Points}{#1}} % % Now lets set up the two pass mechanism \def\nofPoints{0} % Number of points from previous run \definetwopasslist {Points} % variable where two pass data is stored % Need to execute this at the start of each file \def\checkPoints {\gettwopassdata{Points} % Retreive the two pass data \iftwopassdatafound \xdef \nofPoints {\twopassdata} \fi \global\let\checkproblems\relax} % An example usage \starttext \checkPoints \title{This exam is of \nofPoints\ Points} % Lets set 10 problems with different points \dorecurse{10} {\pkt[\recurselevel] \input tufte \endgraf} % Now the rest of the magic to take care of the two pass run % Basically this says that rerun if \nofPoints != % \countervalue{Points}. In the next run we set \nofPoints to the % previous value of \countervalue{Points} (the \checkPoints macro in % the beginning), so things should be stable after two runs. \savetwopassdata {Points} {\nofPoints} {\countervalue{Points}} \stoptext HTH, Aditya