Re: [NTG-context] store counter or variable and reread again

2007-01-04 Thread Hans Hagen
� wrote:
> On Mon, 1 Jan 2007, Hans Hagen wrote:
>
>   
>> hm, long long ago i played with strategies for this ... the attached 
>> file shows some of this ... food for thought
>> 
>
> Thanks Hans, it's quite similar to my old LaTeX letter class option file,
> that I would like to port to ConTeXt.
>
> What is the difference between
> \savecurrentvalue ...
>   
just saves a value
> and
> \setstrategyvariable ... ?
>   
this is a prelude to multi pass optimizations (till criterium met)
> It seems, that both are doing what I'm looking for.
>
> Is there somewhere some documentation about
> - texexec --optimize
> - strategies
> - twopassentries
>   
collections of saved data
> and so on?
>   
yes ; btw, when you run context mkiv, all that data is no longer in the 
tuo file but in a lua table structure, and it's all loaded at the same 
time; this drastically speeds up some of the tuo related stuff

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
-

___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2007-01-02 Thread Peter Münster
On Mon, 1 Jan 2007, Hans Hagen wrote:

> hm, long long ago i played with strategies for this ... the attached 
> file shows some of this ... food for thought

Thanks Hans, it's quite similar to my old LaTeX letter class option file,
that I would like to port to ConTeXt.

What is the difference between
\savecurrentvalue ...
and
\setstrategyvariable ... ?

It seems, that both are doing what I'm looking for.

Is there somewhere some documentation about
- texexec --optimize
- strategies
- twopassentries
and so on?

Cheers, Peter

-- 
http://pmrb.free.fr/contact/
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2007-01-01 Thread Hans Hagen
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
>[EMAIL PROTECTED]
> \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
-

___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2007-01-01 Thread Hans Hagen



On Mon, 1 Jan 2007, Aditya Mahajan wrote:

  

is it also possible to specify the maximum number of runs in the TeX-file,
for example "\maxruns{11}" ?
  

AFAIU, no. I have not checked if runs=11 on top of the file is read.



No, runs=11 is not read. But anyway, I would need something like
"\maxruns{11}", because I would like to put it in a module, that needs a
lot of runs to converge (vertical spacing adjustment to get a letter where
the last page is filled at least to 30%).
Cheers, Peter

  
hm, long long ago i played with strategies for this ... the attached 
file shows some of this ... food for thought


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
-



opti-pag.tex
Description: TeX document
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2007-01-01 Thread Peter Münster
On Mon, 1 Jan 2007, Aditya Mahajan wrote:

> > is it also possible to specify the maximum number of runs in the TeX-file,
> > for example "\maxruns{11}" ?
> 
> AFAIU, no. I have not checked if runs=11 on top of the file is read.

No, runs=11 is not read. But anyway, I would need something like
"\maxruns{11}", because I would like to put it in a module, that needs a
lot of runs to converge (vertical spacing adjustment to get a letter where
the last page is filled at least to 30%).
Cheers, Peter

-- 
http://pmrb.free.fr/contact/
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2007-01-01 Thread Aditya Mahajan
On Mon, 1 Jan 2007, Peter Münster wrote:

> On Sat, 30 Dec 2006, Aditya Mahajan wrote:
> 
> > you will get two runs the first time you process the file, and a 
> > single run if you reprocess the file. By default, the maximum number 
> > of runs that you can have is 8, but you can change this by passing
> > --runs= to texexec
> 
> Hello,
> is it also possible to specify the maximum number of runs in the TeX-file,
> for example "\maxruns{11}" ?

AFAIU, no. I have not checked if runs=11 on top of the file is read.

Aditya
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2007-01-01 Thread Peter Münster
On Sat, 30 Dec 2006, Aditya Mahajan wrote:

> you will get two runs the first time you process the file, and a 
> single run if you reprocess the file. By default, the maximum number 
> of runs that you can have is 8, but you can change this by passing
> --runs= to texexec

Hello,
is it also possible to specify the maximum number of runs in the TeX-file,
for example "\maxruns{11}" ?
Cheers, Peter

-- 
http://pmrb.free.fr/contact/
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-31 Thread Aditya Mahajan
On Sun, 31 Dec 2006, Thomas Engel wrote:

> Aditya Mahajan wrote:
> 
> > \unprotect
> > \def\addtocounter#1#2% #1 name #2 value
> >
> [EMAIL PROTECTED]
> > \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
> >
> > \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
> >
> Thanks for your help. It's great!
> 
> What I recognized is when I put this on layer for better placement of
> the header it doesn't work.
> Here is an example:
> 
> \def\Schulaufgabekopf%
>   {\bf \tfa
>   \setupTABLE[option=stretch]
>   \setupTABLE[frame=off]
>   \setupTABLE[column][1][width=0.7\textwidth]
>   \setupTABLE[column][2][width=0.3\textwidth]
> 
> \setupTABLE[row][2,3,4][background=color,backgroundcolor=gray,frame=off]
>   \setupTABLE[row][5][height=1cm]
>   \bTABLE
>   \bTR \bTD \strut \eTD \bTD \strut \eTD \eTR
>   \bTR \bTD \AAnr \eTD \bTD Date: \eTD \eTR
>   \bTR \bTD  Name:\eTD \bTD Points: \hfill of \nofPoints \eTD\eTR
>   \bTR \bTD  Form: \Klnr   \eTD \bTD Mark: \eTD \eTR
>   \bTR \bTD [nc=3, align=low] \tfxx   Unterschrift eines
> Erziehungsberechtigten: \thinrule \eTD \eTR
>   \eTABLE}
> 
> \definelayer[kopf][width=\paperwidth, height=\paperheight]
> 
> %Klassenarbeiten Kopf
> \def\AAnr{2. Schulaufgabe Englisch 2006/2007}
> \def\Klnr{10 \hfill}
> %\definelogo[SAK] [top][left][command=\Schulaufgabekopf]
> %\placelogos[SAK]
> 
> 
> \setlayer[kopf][x=1.9cm, y=1cm]{\Schulaufgabekopf}

Change this line to

\appendtoks \setlayer[kopf][x=1.9cm, y=1cm]{\Schulaufgabekopf} \to 
\everystarttext

or

\appendtoks \setlayer[kopf][x=1.9cm, y=1cm]{\Schulaufgabekopf} \to 
\everyafterutilityread

> \setupbackgrounds[page][background=kopf]
> \starttext
> 
> % Lets set 10 problems with different points
> \dorecurse{10}
>{\pkt[\recurselevel] \input tufte \endgraf}
> 
> \stoptext
> 
> What's going wrong?

The layer kopf is being set before the tui file is read. So, the value 
of \nofPoints is still 0. You need to set this layer after the 
utility file is read by appending the code to \everyafterutilityread 
or to \everystarttext (which happens after reading utility file).

Aditya
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-31 Thread Thomas Engel
Aditya Mahajan wrote:

> \unprotect
> \def\addtocounter#1#2% #1 name #2 value
>
[EMAIL PROTECTED]
> \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
>
> \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
>
Thanks for your help. It's great!

What I recognized is when I put this on layer for better placement of
the header it doesn't work.
Here is an example:

\def\Schulaufgabekopf%
  {\bf \tfa
  \setupTABLE[option=stretch]
  \setupTABLE[frame=off]
  \setupTABLE[column][1][width=0.7\textwidth]
  \setupTABLE[column][2][width=0.3\textwidth]

\setupTABLE[row][2,3,4][background=color,backgroundcolor=gray,frame=off]
  \setupTABLE[row][5][height=1cm]
  \bTABLE
  \bTR \bTD \strut \eTD \bTD \strut \eTD \eTR
  \bTR \bTD \AAnr \eTD \bTD Date: \eTD \eTR
  \bTR \bTD  Name:\eTD \bTD Points: \hfill of \nofPoints \eTD\eTR
  \bTR \bTD  Form: \Klnr   \eTD \bTD Mark: \eTD \eTR
  \bTR \bTD [nc=3, align=low] \tfxx   Unterschrift eines
Erziehungsberechtigten: \thinrule \eTD \eTR
  \eTABLE}

\definelayer[kopf][width=\paperwidth, height=\paperheight]

%Klassenarbeiten Kopf
\def\AAnr{2. Schulaufgabe Englisch 2006/2007}
\def\Klnr{10 \hfill}
%\definelogo[SAK] [top][left][command=\Schulaufgabekopf]
%\placelogos[SAK]


\setlayer[kopf][x=1.9cm, y=1cm]{\Schulaufgabekopf}
\setupbackgrounds[page][background=kopf]
\starttext

% Lets set 10 problems with different points
\dorecurse{10}
   {\pkt[\recurselevel] \input tufte \endgraf}

\stoptext

What's going wrong?

Thomas


___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-30 Thread Aditya Mahajan
On Sat, 30 Dec 2006, Aditya Mahajan wrote:

> On Sat, 30 Dec 2006, Hans Hagen wrote:
> 
> > how about
> > 
> > \savecurrentvalue\SomeVar{someval}
> 
> I was just copying the way it is done with other macros \lastpage, 
> etc. I will look at \savecurrentvalue also.

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

% 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
   [EMAIL PROTECTED]
\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

\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?

Aditya
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-30 Thread Aditya Mahajan
On Sat, 30 Dec 2006, Hans Hagen wrote:

> Aditya Mahajan wrote:
> > On Sat, 30 Dec 2006, Peter M???nster wrote:
> >
> > 
> >> On Sat, 30 Dec 2006, Aditya Mahajan wrote:
> >>
> >> 
> >>> % 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}}
> >>> 
> >> Hello Aditya,
> >>
> >> with the following example, I get always 2 runs:
> >>
> >> \definetwopasslist{test}
> >> \starttext
> >> bla
> >> \savetwopassdata{test}{1}{2}
> >> \stoptext
> >>
> >> Is this normal or a bug?
> >> 
> >
> > Hmm... I would have guessed that you will keep on getting infinite 
> > runs, but apparently texexec decides that two are enough. I need to 
> > look deeper to see if this is the intended behaviour. I would call it 
> > a bug, since there can be cases which need more than two runs to 
> > converge.
> >
> > 
> how about
> 
> \savecurrentvalue\SomeVar{someval}

I was just copying the way it is done with other macros \lastpage, 
etc. I will look at \savecurrentvalue also. However, something seems 
to be wrong in tex.rb

Change

def processfile

  while ! stoprunning && (texruns < nofruns) && ok do

  end
...
end

to

def processfile

  while ! stoprunning && (texruns < nofruns) && ok do

  report("stoprunning #{stoprunning}")
  report("texruns=#{texruns}, nofruns=#{nofruns}")
  report("ok=#{ok}")
  report("while=#{! stoprunning && (texruns < nofruns) && ok}")
  end
...
end

so that we can see what takes us out of the while loop.

Take Petar's test file and run it through texexec. I get

TeXExec | stoprunning true
TeXExec | texruns=2, nofruns=8
TeXExec | ok=counter.tex
TeXExec | while=counter.tex

Notice that ok=\jobname. Shouldn't ok be a boolean. And the condition 
for while is a string rather than a boolean. I am not too sure on what 
ruby does for non boolean conditionals, but the present implementation 
can break (under some crazy conditions, maybe). How about if in

def runtexutil(...)

there is a return ok in the end, for example

  begin
  logger = Logger.new('TeXUtil')
  if tu = TeXUtil::Converter.new(logger) and tu.loaded(fname) then
  ok = tu.processed && tu.saved && tu.finalized
  end
  rescue
  Kpse.runscript('texutil',fname,options)
  else
return ok #<- added.
  end



Back to Peter's question, I gave a wrong explaination earlier. texexec 
just checks if the tui file has changed. If the file did not change 
from the last run, then it stops processing. So with

\savetwopassdata{test}{1}{2}

you will get two runs the first time you process the file, and a 
single run if you reprocess the file. By default, the maximum number 
of runs that you can have is 8, but you can change this by passing
--runs= to texexec


Aditya


___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-30 Thread Hans Hagen
Aditya Mahajan wrote:
> On Sat, 30 Dec 2006, Peter M�nster wrote:
>
>   
>> On Sat, 30 Dec 2006, Aditya Mahajan wrote:
>>
>> 
>>> % 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}}
>>>   
>> Hello Aditya,
>>
>> with the following example, I get always 2 runs:
>>
>> \definetwopasslist{test}
>> \starttext
>> bla
>> \savetwopassdata{test}{1}{2}
>> \stoptext
>>
>> Is this normal or a bug?
>> 
>
> Hmm... I would have guessed that you will keep on getting infinite 
> runs, but apparently texexec decides that two are enough. I need to 
> look deeper to see if this is the intended behaviour. I would call it 
> a bug, since there can be cases which need more than two runs to 
> converge.
>
>   
how about

\savecurrentvalue\SomeVar{someval}




-- 

-
  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
-

___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-30 Thread Aditya Mahajan
On Sat, 30 Dec 2006, Peter Münster wrote:

> On Sat, 30 Dec 2006, Aditya Mahajan wrote:
> 
> > % 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}}
> 
> Hello Aditya,
> 
> with the following example, I get always 2 runs:
> 
> \definetwopasslist{test}
> \starttext
> bla
> \savetwopassdata{test}{1}{2}
> \stoptext
> 
> Is this normal or a bug?

Hmm... I would have guessed that you will keep on getting infinite 
runs, but apparently texexec decides that two are enough. I need to 
look deeper to see if this is the intended behaviour. I would call it 
a bug, since there can be cases which need more than two runs to 
converge.

Aditya
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-30 Thread Peter Münster
On Sat, 30 Dec 2006, Aditya Mahajan wrote:

> % 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}}

Hello Aditya,

with the following example, I get always 2 runs:

\definetwopasslist{test}
\starttext
bla
\savetwopassdata{test}{1}{2}
\stoptext

Is this normal or a bug?

Cheers, Peter

-- 
http://pmrb.free.fr/contact/
___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context


Re: [NTG-context] store counter or variable and reread again

2006-12-30 Thread Aditya Mahajan
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
[EMAIL PROTECTED]
\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

___
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context