On 12/7/2022 1:42 PM, Gavin via ntg-context wrote:
Hi List,

I solved my original problem 2, allowing me to reuse the same \hpos labels in 
different equations without interference. I added an equation counter and set 
up my custom math version of \hpos to use the count as part of the label 
internally. I tried to do this with a regular ConTeXt counter, but had all 
sorts of mysterious, wrong behavior. When I switched to using a Lua counter, 
everything worked immediately. So, while there is nothing brilliant about this 
solution, I’ll share it for anyone who might want to do something similar in 
the future.

Using this could work

\newcount\SFNum

\global\advance\SFNum\plusone

\the\SFNum

(you now use a (global) lua counter

The code I added is below, with some comments. The complete example file is 
attached. The result is two equations.



Each equation was written using the same labels (X,Y,Z), but internally they 
have separate sets, (1:X and 2:X, etc.).

The moral of the story for me: Use more Lua.

but ... work local ... so

   document.sfnum

etc in order to avoid clashes
Gavin


% Lua counts the spin formulas
\ctxlua{sfnum = 0} % Count starts at zero
\def\sfID{\ctxlua{context(sfnum)}} % ConTeXt can call the count from Lua to use 
as an ID for each equation.

% Spin formulas increase the spin formula count and typeset the formula as 
usual.
\define\startspinformula{
   \ctxlua{sfnum = sfnum + 1}
   \startformula
}
\define\stopspinformula{\stopformula}

% My own \mpos uses the spin formula ID as part of the box label, then sets the 
contents as math.
\define[2]\mpos{\hpos{\sfID:#1}{$#2$}}

% Two commands for requesting contractions (the connections between spinors), 
using the spin formula ID.
\define[2]\contract{%
   \startpositionoverlay{graphics}%
     \setMPpositiongraphic{\sfID:#1}{mypos:contract}{to=\sfID:#2}%
   \stoppositionoverlay%
}
\define[2]\contractbelow{%
   \startpositionoverlay{graphics}%
     \setMPpositiongraphic{\sfID:#1}{mypos:contractbelow}{to=\sfID:#2}%
   \stoppositionoverlay%
}
Attached what you can do in a next upload (on the million math test files MS and I have by now)

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

Attachment: 221206-1.pdf
Description: Adobe PDF document

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

Reply via email to