ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Gavin via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Gavin <gavinpublic@comcast.net>
Subject: \hpos in math
Date: Mon, 5 Dec 2022 16:39:56 -0700	[thread overview]
Message-ID: <4809FBC9-09D4-4055-A37C-23BE177454A7@comcast.net> (raw)

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

             reply	other threads:[~2022-12-05 23:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 23:39 Gavin via ntg-context [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4809FBC9-09D4-4055-A37C-23BE177454A7@comcast.net \
    --to=ntg-context@ntg.nl \
    --cc=gavinpublic@comcast.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).