ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* \hpos in math
@ 2022-12-05 23:39 Gavin via ntg-context
  2022-12-06  9:15 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 10+ messages in thread
From: Gavin via ntg-context @ 2022-12-05 23:39 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Gavin

[-- Attachment #1: Type: text/plain, Size: 90 bytes --]

Hello List,

I am working on a project which combines graphics with formulas, like this:


[-- Attachment #2: hposQuestion.pdf --]
[-- Type: application/pdf, Size: 6369 bytes --]

[-- Attachment #3: Type: text/plain, Size: 1966 bytes --]



My code for creating this formula is attached. It works well, but I have a couple of questions that could make it work better.

1) Is there a mathematics version of \hpos? The contents of \hpos are set as text, even when \hpos is in mathematics, so I wrote an \mpos macro that uses \hpos but sets the contents as display-style math. This isn’t great for spacing, and it does't adapt to different math styles. \framed has a math version, \mframed, that sets the contents in the appropriate math style. If anyone know a way to accomplish that with \hpos, I’d love to know.

2) Is there a way to limit the scope of the \hpos labels to a single formula. This could turn into a book length project, with several formulas per page and several connections per formula. If every \hpos in the entire book needs a unique identifier, I could go mad. Under no circumstances will I connect one formula to another, so I’d like to be able to use something like \hpos{A}{…}…\hpos{B}{…} in each formula. Any suggestions?

I’ve got to say, LMTX is an absolutely amazing tool for this project, which includes complicated networks of connections above and below many formulas. The integration of TeX, MetaPost, and Lua makes this project tremendous fun.

Thanks!
Gavin

P.S. For the curious, I’m using a method for doing General Relativity based on spinors rather than tensors, following the methods of Penrose and Rindler in their 1985 books “Spinors and Space-time.” In the typesetting example above, the e_\alpha and e_{\dot\beta} are basis spinors (one left-handed, one right-handed). The e^\mu is the Infeld-van der Waerden symbol relating the spin basis to the coordinate basis. The connections are spinor index contractions. The formula above relates the components of the Infeld-van der Waerden symbol to the Pauli sigma matrices. This relationship only works in flat space, so this is an easy example! [Penrose and Rindler, vol 1 p. 125] 


[-- Attachment #4: hposQuestion.tex --]
[-- Type: application/octet-stream, Size: 2381 bytes --]

% Setting up the overlay for \hpos
\defineoverlay [graphics] [\positionoverlay{graphics}]
\setupbackgrounds
  [page]
  [background={foreground,graphics}]

% My own \mpos that sets its contents in math, displaystyle
\define[2]\mpos{\hpos{#1}{$\displaystyle#2$}}

% Two commands for requesting contractions (the connections between spinors).
\define[2]\contract{%
  \startpositionoverlay{graphics}%
    \setMPpositiongraphic{#1}{mypos:contract}{to=#2}%
  \stoppositionoverlay%
}
\define[2]\contractbelow{%
  \startpositionoverlay{graphics}%
    \setMPpositiongraphic{#1}{mypos:contractbelow}{to=#2}%
  \stoppositionoverlay%
}

% The MetaPost code for drawing the contractions.
\startMPpositiongraphic{mypos:contract}
     path pa, pb, pab ; numeric na, nb ; string ta, tb ;
     ta := mpvars("from") ;
     tb := mpvars("to") ;
     na := positionpage(ta) ; % page number of a
     nb := positionpage(tb) ; % page number of b
     pa := positionbox(ta) ;  % box of a
     pb := positionbox(tb) ;  % box of b
     z1 = 0.5[ulcorner pa,urcorner pa] ;
     z2 = 0.5[ulcorner pb,urcorner pb] ;
     y3 = max(y1,y2) + 3pt ; 
     if na = nb : % Check that positions are on the same page
       pab := z1 -- (x1,y3) -- (x2,y3) -- z2{down} ;
       pickup pencircle scaled 0.6pt ;
       draw pab yshifted 1pt ;
       positioninregion ;
     fi ;
\stopMPpositiongraphic

\startMPpositiongraphic{mypos:contractbelow}
     path pa, pb, pab ; numeric na, nb ; string ta, tb ;
     ta := mpvars("from") ;
     tb := mpvars("to") ;
     na := positionpage(ta) ; % page number of a
     nb := positionpage(tb) ; % page number of b
     pa := positionbox(ta) ;  % box of a
     pb := positionbox(tb) ;  % box of b
     z1 = 0.5[llcorner pa,lrcorner pa] ;
     z2 = 0.5[llcorner pb,lrcorner pb] ;
     y3 = min(y1,y2) - 3pt ; 
     if na = nb : % Check that positions are on the same page
       pab := z1 -- (x1,y3) -- (x2,y3) -- z2{down} ;
       pickup pencircle scaled 0.6pt ;
       draw pab yshifted -1pt ;
       positioninregion ;
     fi ;
\stopMPpositiongraphic

% A textstyle fraction to make the normalization factor look nice.
\define[2]\textfrac{{\textstyle\frac{#1}{#2}}}


\starttext

\startformula
  \mpos{X}{e}_\alpha \mpos{Y}{e}^\mu \mpos{Z}{e}_{\dot\beta}
    = \textfrac{1}{\sqrt{2}}\sigma_{\alpha\dot\beta}^\mu
  \contract{X}{Y}
  \contractbelow{Y}{Z}
\stopformula

\stoptext

[-- Attachment #5: Type: text/plain, Size: 496 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math
  2022-12-05 23:39 \hpos in math Gavin via ntg-context
@ 2022-12-06  9:15 ` Hans Hagen via ntg-context
  2022-12-06 13:22   ` Gavin via ntg-context
  0 siblings, 1 reply; 10+ messages in thread
From: Hans Hagen via ntg-context @ 2022-12-06  9:15 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

[-- Attachment #1: Type: text/plain, Size: 2796 bytes --]

On 12/6/2022 12:39 AM, Gavin via ntg-context wrote:
> Hello List,
> 
> I am working on a project which combines graphics with formulas, like this:
> 
> My code for creating this formula is attached. It works well, but I have a couple of questions that could make it work better.
> 
> 1) Is there a mathematics version of \hpos? The contents of \hpos are set as text, even when \hpos is in mathematics, so I wrote an \mpos macro that uses \hpos but sets the contents as display-style math. This isn’t great for spacing, and it does't adapt to different math styles. \framed has a math version, \mframed, that sets the contents in the appropriate math style. If anyone know a way to accomplish that with \hpos, I’d love to know.

there actually is a subsystem that keeps math as-is-it (styles and 
spacing and such), see attached

> 2) Is there a way to limit the scope of the \hpos labels to a single formula. This could turn into a book length project, with several formulas per page and several connections per formula. If every \hpos in the entire book needs a unique identifier, I could go mad. Under no circumstances will I connect one formula to another, so I’d like to be able to use something like \hpos{A}{…}…\hpos{B}{…} in each formula. Any suggestions?

one problem is (and i'm working on that) that one could want multiple 
anchors on a math atom as well as pu tit on the nuclues only

> I’ve got to say, LMTX is an absolutely amazing tool for this project, which includes complicated networks of connections above and below many formulas. The integration of TeX, MetaPost, and Lua makes this project tremendous fun.

that's the idea

> P.S. For the curious, I’m using a method for doing General Relativity based on spinors rather than tensors, following the methods of Penrose and Rindler in their 1985 books “Spinors and Space-time.” In the typesetting example above, the e_\alpha and e_{\dot\beta} are basis spinors (one left-handed, one right-handed). The e^\mu is the Infeld-van der Waerden symbol relating the spin basis to the coordinate basis. The connections are spinor index contractions. The formula above relates the components of the Infeld-van der Waerden symbol to the Pauli sigma matrices. This relationship only works in flat space, so this is an easy example! [Penrose and Rindler, vol 1 p. 125]

in your example we need a way to anchor on just the 'e' right? or do you 
want it on the e + super/subscript?

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 #2: xx.tex --]
[-- Type: text/plain, Size: 1385 bytes --]

\usemodule[article-basic]

\setupbodyfont[dejavu]

\starttext

\setupboxanchorcontent
  [top,left]
  [rulecolor=darkyellow]

\setupboxanchorcontent
  [bottom,right]
  [rulecolor=darkblue]

\input tufte

$
    \connectboxanchors[top][top]{one}{two}
    x + \frac[source=\namedboxanchor{one}]{1+x}{2-x} =
    z + \frac[source=\namedboxanchor{two}]{1+x^2}{2-x^3}
$

\input ward


\connectboxanchors[top][top]{one}{two}

So how about
$
    x + \frac[source=\namedboxanchor{one}]{1+x}{2-x}
$
and
$
    z + \frac[source=\namedboxanchor{two}]{1+x^2}{2-x^3}
$
then. Of course we need to handle page crossing then.

\connectboxanchors[top][top]        {one}{two}
\connectboxanchors[top][top][dash=1]{three}{four}

And can we do
$
%     \showboxes
    x + \frac{1 \mathboxanchored{one}{+} x \mathboxanchored{three}{-} z}{2-x}
$
and
$
%     \showboxes
    z + \frac{1 \mathboxanchored{two}{+} x^2 \mathboxanchored{four}{-} z}{2-x^3}
$
to be more granular?

\blank[2*big]

\connectboxanchors[top]   [top]   [text={\small\small\strut\bf watch}]{one}  {two}
\connectboxanchors[bottom][bottom][text={\small\small\strut\bf out}]  {three}{four}

And can we do
$
%     \showboxes
    x + \frac{1 \mathboxanchored{one}{+} x - z}{2 \mathboxanchored{three}{-} x}
$
and
$
%     \showboxes
    z + \frac{1 \mathboxanchored{two}{+} x^2 - z}{2 \mathboxanchored{four}{-} x^3}
$
to be more granular?

\stoptext


[-- Attachment #3: Type: text/plain, Size: 496 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math
  2022-12-06  9:15 ` Hans Hagen via ntg-context
@ 2022-12-06 13:22   ` Gavin via ntg-context
  2022-12-07 12:42     ` \hpos in math - Half solved Gavin via ntg-context
  0 siblings, 1 reply; 10+ messages in thread
From: Gavin via ntg-context @ 2022-12-06 13:22 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Gavin

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

Hi Hans,

> On Dec 6, 2022, at 2:15 AM, Hans Hagen via ntg-context <ntg-context@ntg.nl> wrote:
> On 12/6/2022 12:39 AM, Gavin via ntg-context wrote:
>> 1) Is there a mathematics version of \hpos? The contents of \hpos are set as text, even when \hpos is in mathematics, so I wrote an \mpos macro that uses \hpos but sets the contents as display-style math. This isn’t great for spacing, and it does't adapt to different math styles. \framed has a math version, \mframed, that sets the contents in the appropriate math style. If anyone know a way to accomplish that with \hpos, I’d love to know.
> 
> there actually is a subsystem that keeps math as-is-it (styles and spacing and such), see attached

I tried using \mathboxanchored, and was able to get the bottom two equations shown here. (The top equation uses \hpos, for comparison.)


[-- Attachment #2: mathboxanchored.pdf --]
[-- Type: application/pdf, Size: 15881 bytes --]

[-- Attachment #3: Type: text/plain, Size: 1012 bytes --]


There are two problems that I didn’t know how to fix.

1) The line connects to the box including the subscript or superscript, not just to the e.
2) I cannot make multiple connections to a single object, like the e^\mu in the center. If I try to connect top and bottom, I get no connections anywhere in the entire document.

The code for the formulas is:

\startformula
  % Each \connectboxanchors works alone, but both together make trouble:
    \connectboxanchors[top][top]{X}{Y}
    %\connectboxanchors[bottom][bottom]{Y}{Z}
  \mathboxanchored{X}{e}_\alpha \mathboxanchored{Y}{e}^\mu \mathboxanchored{Z}{e}_{\dot\beta}
    = \textfrac{1}{\sqrt{2}}\sigma_{\alpha\dot\beta}^\mu
\stopformula

I added code to turn the arrow produced by \connectboxanchors into my contraction overlay, but that doesn’t affect these issues.

> in your example we need a way to anchor on just the 'e' right? or do you want it on the e + super/subscript?

Yes, we only need to anchor to e. 

Thanks!
Gavin

[-- Attachment #4: Type: text/plain, Size: 496 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-06 13:22   ` Gavin via ntg-context
@ 2022-12-07 12:42     ` Gavin via ntg-context
  2022-12-07 15:30       ` Hans Hagen via ntg-context
  2022-12-07 22:25       ` Hans Hagen via ntg-context
  0 siblings, 2 replies; 10+ messages in thread
From: Gavin via ntg-context @ 2022-12-07 12:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Gavin

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

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.

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

[-- Attachment #2: hposQuestionEquations.pdf --]
[-- Type: application/pdf, Size: 6141 bytes --]

[-- Attachment #3: Type: text/plain, Size: 1139 bytes --]


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.

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



[-- Attachment #4: hposQuestion.tex --]
[-- Type: application/octet-stream, Size: 3796 bytes --]

% !TEX useAlternatePath
% !TEX useConTeXtSyncParser

% Setting up the overlay for \hpos
\defineoverlay [graphics] [\positionoverlay{graphics}]
\setupbackgrounds
  [page]
  [background={foreground,graphics}]

% The MetaPost code for drawing the contractions.
\startMPpositiongraphic{mypos:contract}
     path pa, pb, pab ; numeric na, nb ; string ta, tb ;
     ta := mpvars("from") ;
     tb := mpvars("to") ;
     na := positionpage(ta) ; % page number of a
     nb := positionpage(tb) ; % page number of b
     pa := positionbox(ta) ;  % box of a
     pb := positionbox(tb) ;  % box of b
     z1 = 0.5[ulcorner pa,urcorner pa] ;
     z2 = 0.5[ulcorner pb,urcorner pb] ;
     y3 = max(y1,y2) + 3pt ; 
     if na = nb : % Check that positions are on the same page
       pab := z1 -- (x1,y3) -- (x2,y3) -- z2{down} ;
       pickup pencircle scaled 0.6pt ;
       draw pab yshifted 1pt ;
       positioninregion ;
     fi ;
\stopMPpositiongraphic

\startMPpositiongraphic{mypos:contractbelow}
     path pa, pb, pab ; numeric na, nb ; string ta, tb ;
     ta := mpvars("from") ;
     tb := mpvars("to") ;
     na := positionpage(ta) ; % page number of a
     nb := positionpage(tb) ; % page number of b
     pa := positionbox(ta) ;  % box of a
     pb := positionbox(tb) ;  % box of b
     z1 = 0.5[llcorner pa,lrcorner pa] ;
     z2 = 0.5[llcorner pb,lrcorner pb] ;
     y3 = min(y1,y2) - 3pt ; 
     if na = nb : % Check that positions are on the same page
       pab := z1 -- (x1,y3) -- (x2,y3) -- z2{down} ;
       pickup pencircle scaled 0.6pt ;
       draw pab yshifted -1pt ;
       positioninregion ;
     fi ;
\stopMPpositiongraphic

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

% A textstyle fraction to make the normalization factor look nice.
\define[2]\textfrac{{\textstyle\frac{#1}{#2}}}


\starttext

\startspinformula
  \mpos{X}{e}_\alpha \mpos{Y}{e}^\mu \mpos{Z}{e}_{\dot\beta}
    = \textfrac{1}{\sqrt{2}}\sigma_{\alpha\dot\beta}^\mu
  \contract{X}{Y}
  \contractbelow{Y}{Z}
\stopformula

\startspinformula
  \mpos{X}{e}^{\dot\alpha} \mpos{Y}{e}_\mu \mpos{Z}{e}^{\beta}
    = \textfrac{1}{\sqrt{2}}\bar\sigma^{\dot\alpha\beta}_\mu
  \contractbelow{X}{Y}
  \contract{Y}{Z}
\stopformula

%\startformula
%  % Each \connectboxanchors works alone, but both together make trouble:
%    %\connectboxanchors[top][top]{X}{Y}
%    \connectboxanchors[bottom][bottom]{Y}{Z}
%  \mathboxanchored{X}{e}_\alpha \mathboxanchored{Y}{e}^\mu \mathboxanchored{Z}{e}_{\dot\beta}
%    = \textfrac{1}{\sqrt{2}}\sigma_{\alpha\dot\beta}^\mu
%\stopformula
%\blank[8mm]
%
%\startformula
%  % Each \connectboxanchors works alone, but both together make trouble:
%    \connectboxanchors[top][top]{X}{Y}
%    %\connectboxanchors[bottom][bottom]{Y}{Z}
%  \mathboxanchored{X}{e}_\alpha \mathboxanchored{Y}{e}^\mu \mathboxanchored{Z}{e}_{\dot\beta}
%    = \textfrac{1}{\sqrt{2}}\sigma_{\alpha\dot\beta}^\mu
%\stopformula

\stoptext

[-- Attachment #5: Type: text/plain, Size: 496 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-07 12:42     ` \hpos in math - Half solved Gavin via ntg-context
@ 2022-12-07 15:30       ` Hans Hagen via ntg-context
  2022-12-07 22:25       ` Hans Hagen via ntg-context
  1 sibling, 0 replies; 10+ messages in thread
From: Hans Hagen via ntg-context @ 2022-12-07 15:30 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

[-- Attachment #1: Type: text/plain, Size: 2549 bytes --]

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 #2: 221206-1.pdf --]
[-- Type: application/pdf, Size: 14968 bytes --]

[-- Attachment #3: Type: text/plain, Size: 496 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-07 12:42     ` \hpos in math - Half solved Gavin via ntg-context
  2022-12-07 15:30       ` Hans Hagen via ntg-context
@ 2022-12-07 22:25       ` Hans Hagen via ntg-context
  2022-12-08  0:03         ` Gavin via ntg-context
  1 sibling, 1 reply; 10+ messages in thread
From: Hans Hagen via ntg-context @ 2022-12-07 22:25 UTC (permalink / raw)
  To: ntg-context; +Cc: Hans Hagen

[-- Attachment #1: Type: text/plain, Size: 1029 bytes --]

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.
attached an example by Mikael ... it should work with tonights update

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 #2: 221206-3.mkxl --]
[-- Type: text/plain, Size: 1334 bytes --]

 \usemodule[article-basic]

\starttext

\startboxanchoring[+]
\connectboxanchors[top]    [top]    [distance=1ex] {c1}{c2}
\connectboxanchors[bottom] [bottom] [distance=1ex] {d1}{d2}
\startformula
    \mathboxanchored[nucleus]{c1}{e}_{\alpha}
    \mathboxanchored[nucleus]{c2}{e}^{\mu}
    \mathboxanchored[nucleus]{d1}{todo}
    \mathboxanchored[nucleus]{d2}{e}_{\dot{\beta}} = \frac{1}{\sqrt{2}}
    \sigma_{\alpha,\dot{\beta}}^{\mu}
\stopformula
\stopboxanchoring

\startboxanchoring[+]
\connectboxanchors[top]    [top]    [distance=0.5ex,arrow=no] {c1}{c2}
\connectboxanchors[bottom] [bottom] [distance=0.5ex,arrow=no] {c2}{c3}
\startformula
    \mathboxanchored[nucleus]{c1}{e}_{\alpha}
    \mathboxanchored[nucleus]{c2}{e}^{\mu}
    \mathboxanchored[nucleus]{c3}{e}_{\dot{\beta}} = \frac{1}{\sqrt{2}}
    \sigma_{\alpha,\dot{\beta}}^{\mu}
\stopformula
\stopboxanchoring

\startboxanchoring[+]
\connectboxanchors[top]    [top]    [text={\smallinfofont upper limits}]{b1}{b2}
\connectboxanchors[bottom] [bottom] [text={\smallinfofont lower limits}]{a1}{a2}
\startformula
\int_{\mathboxanchored{a1}{0}}^{\mathboxanchored{b1}{1}} \frac{1}{1+x^2} \dd x
=
\int_{\mathboxanchored{a2}{0}}^{\pi\mathboxanchored{b2}{/}4} \frac{1}{1+\tan^2 t}(1+\tan^2 t)\dd t
\stopformula
\stopboxanchoring

\stoptext

[-- Attachment #3: Type: text/plain, Size: 496 bytes --]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-07 22:25       ` Hans Hagen via ntg-context
@ 2022-12-08  0:03         ` Gavin via ntg-context
  2022-12-08  6:14           ` Mikael Sundqvist via ntg-context
  0 siblings, 1 reply; 10+ messages in thread
From: Gavin via ntg-context @ 2022-12-08  0:03 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Gavin

Hi Hans and Mikael,

This is amazing! Mikael's example works for me. I will start using these tools in my project, and I’ll tell you how it goes. It might be a couple weeks, because the physics is also quite challenging.

Thank you!
Gavin


> On Dec 7, 2022, at 3:25 PM, Hans Hagen via ntg-context <ntg-context@ntg.nl> wrote:
> 
> 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.
> attached an example by Mikael ... it should work with tonights update
> 
> 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
> -----------------------------------------------------------------
> <221206-3.mkxl>___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-08  0:03         ` Gavin via ntg-context
@ 2022-12-08  6:14           ` Mikael Sundqvist via ntg-context
  2022-12-08 19:54             ` Otared Kavian via ntg-context
  0 siblings, 1 reply; 10+ messages in thread
From: Mikael Sundqvist via ntg-context @ 2022-12-08  6:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Mikael Sundqvist

Hi,

On Thu, Dec 8, 2022 at 1:07 AM Gavin via ntg-context <ntg-context@ntg.nl> wrote:
>
> Hi Hans and Mikael,
>
> This is amazing! Mikael's example works for me. I will start using these tools in my project, and I’ll tell you how it goes.

Very good that it works and that it gets tested!

> It might be a couple weeks, because the physics is also quite challenging.

Haha, I can imagine that the spinors are even more challenging. Good luck!

/Mikael
___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-08  6:14           ` Mikael Sundqvist via ntg-context
@ 2022-12-08 19:54             ` Otared Kavian via ntg-context
  2022-12-08 21:47               ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 10+ messages in thread
From: Otared Kavian via ntg-context @ 2022-12-08 19:54 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Otared Kavian

Hi Hans, Mikael,

These features are amazing! Many many thanks!
Thanks also to Gavin for having stated so precisely these kinds of needs, so that Hans and Mikael could come up with this solution.
Gavin, good luck with your project, and plaese share what you get at the end.

Best regards : Otared

> On 8 Dec 2022, at 07:14, Mikael Sundqvist via ntg-context <ntg-context@ntg.nl> wrote:
> 
> Hi,
> 
> On Thu, Dec 8, 2022 at 1:07 AM Gavin via ntg-context <ntg-context@ntg.nl> wrote:
>> 
>> Hi Hans and Mikael,
>> 
>> This is amazing! Mikael's example works for me. I will start using these tools in my project, and I’ll tell you how it goes.
> 
> Very good that it works and that it gets tested!
> 
>> It might be a couple weeks, because the physics is also quite challenging.
> 
> Haha, I can imagine that the spinors are even more challenging. Good luck!
> 
> /Mikael
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________

Otared Kavian
e-mail: otared@gmail.com
Phone: +33 6 88 26 70 95



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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: \hpos in math - Half solved
  2022-12-08 19:54             ` Otared Kavian via ntg-context
@ 2022-12-08 21:47               ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 10+ messages in thread
From: Hans Hagen via ntg-context @ 2022-12-08 21:47 UTC (permalink / raw)
  To: Otared Kavian via ntg-context; +Cc: Hans Hagen

On 12/8/2022 8:54 PM, Otared Kavian via ntg-context wrote:
> Hi Hans, Mikael,
> 
> These features are amazing! Many many thanks!
> Thanks also to Gavin for having stated so precisely these kinds of needs, so that Hans and Mikael could come up with this solution.
> Gavin, good luck with your project, and plaese share what you get at the end.
For the record: this features is already there for a while, we also have 
some matrix specific trickery as well as for instance annotated fences 
and so. However, the interfaces will evolve and eventually get 
documented in the upcoming (big) math manual. It's mostly a matter of 
consistent interfacing i.e. it has to fit into the way we do things in 
context (it's of course easy to come up with a quick and dirty ugly non 
extensible and non standard interface).

What is new in the latest greatest is (1) namespaces, so that one can 
reuse the references, which Gavin needs, and (2) sourcing a nucleus 
and/or the whole atom including scripts, which Gavin also needs. Some 
more granularity might show up depending on needs. As some depends on 
the tex engine there are limitations (performance, memory and complexity 
constraints: adding features like these might definitely not impact 
performance).

Source and target properties were added in order to avoid interference 
with math spacing but can also be used in text, where they are part of 
the larger package of box properties that was already around.

\startTEXpage[offset=2cm]

     \setbox 0 \ruledhbox
         source  123
         anchors 1 2
         {one}
     \setbox 2 \ruledhbox
         target 123
         {test 1}

     \dontleavehmode \box2 \box0

     \setbox 0 \ruledhbox
         target      124
         orientation 2
         anchors     1 4
         xoffset    -10pt
         {two}
     \setbox 2 \ruledhbox
         source 124
         {test 2}

     \dontleavehmode \box2 \box0

\stopTEXpage

With sources and targets one has to keep in mind that they don't 
participate in the box dimensions! Although excessive usage puts some 
strain on the backend in practice it probably goes unnoticed.  Also, be 
careful with the source and target id's! There is currently no low level 
allocation mechanism so stick to positive numbers.

So, lots to play with, if you're in the mood,

Hans

(There is quite some experimental code around but to what extend it ends 
up in the core depends on demand, time, motivation etc. As you can 
guess, Mikael and I having a lot of math fun is motivating.)

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-12-08 21:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-05 23:39 \hpos in math Gavin via ntg-context
2022-12-06  9:15 ` Hans Hagen via ntg-context
2022-12-06 13:22   ` Gavin via ntg-context
2022-12-07 12:42     ` \hpos in math - Half solved Gavin via ntg-context
2022-12-07 15:30       ` Hans Hagen via ntg-context
2022-12-07 22:25       ` Hans Hagen via ntg-context
2022-12-08  0:03         ` Gavin via ntg-context
2022-12-08  6:14           ` Mikael Sundqvist via ntg-context
2022-12-08 19:54             ` Otared Kavian via ntg-context
2022-12-08 21:47               ` Hans Hagen via ntg-context

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).