getting metafun positions within (displayed) math mode
Dear ConTeXters, For my sins, and to make students unhappy all over the world, I am writing another book: _A Student's Guide to Newton's Laws of Motion_ (for Cambridge University Press, aka CUP). As partial compensation, I convinced CUP that I may typeset it in ConTeXt and deliver them PDF. Being hopefully a guide actually useful to students, it will annotate every symbol in important equations, a feature cribbed from the first book of the _Student's Guide_ series, Dan Fleisch's _A Student's Guide to Maxwell's Equations_. I've attached an image of what such an annotated equation looks like (from page 2 of Fleisch's book). It's like a labeled part diagram (say, for a laptop), where each part (here, each symbol) is connected with an line to its explanation. I'm trying to do so with a combination of ConTeXt, MetaPost/MetaFun, TikZ, and whatever else might work. But I am a bit stuck at the following spot. My plan is to use MetaFun to get the coordinates of each symbol in a (displayed) equation and then, with MetaFun, connect those symbols to mini-paragraphs of explanation that surround the equation. But I am stuck on how to use \hpos in math mode. I'd like to do something like: \startformula \hpos{n1}{\sum}_{\hpos{n2}{0}}^{\hpos{n3}{1}} \stopformula to get the locations of the nodes n1, n2, and n3 without interfering with the math typesetting -- e.g., the engine should still know that \sum is in display-math mode, so it should be large and have its sub- and super-scripts below and above it, rather than next to it. However, the \hpos hides its argument in an \hbox, and thus hides it from the math layout. Thus, I have to do something like this minimal example: \starttext \startformula \sum_0^1 % what it should look like \quad \hpos{n1}{$\displaystyle\sum$}_{\hpos{n2}{$0$}}^{\hpos{n3}{$1$}} \stopformula \stoptext The hpos'ed version after the \quad looks different, even after the \displaystyle hack. Is there a version of \hpos for math mode? That would be the cleanest solution, because who knows what else would be needed for other cases, even if the limits can be placed correctly. Or is there a better way to annotate equations? (TikZ seems to have the same issue, in that it cannot see into equations.) Regards, -- -Sanjoy http://savelongwharfpark.org/ Save Long Wharf Park in Boston Harbor! http://streetfightingmath.com/ Six reasoning tools to make hard problems easy.
Wow. I learnt about Maxwell's Equation 48 years ago. I never understood it then nor on the intervening time despite sometimes helping design antennas. The picture and its annotation definitely helps creating clarity. For my twopenneth the effort is very worthwhile. Thanks --- Nigel King Mob: +44 7917 803879 Work:+44 1364 655516
On 16 Nov 2017, at 21:10, Sanjoy Mahajan
wrote: Dear ConTeXters,
For my sins, and to make students unhappy all over the world, I am writing another book: _A Student's Guide to Newton's Laws of Motion_ (for Cambridge University Press, aka CUP). As partial compensation, I convinced CUP that I may typeset it in ConTeXt and deliver them PDF.
Being hopefully a guide actually useful to students, it will annotate every symbol in important equations, a feature cribbed from the first book of the _Student's Guide_ series, Dan Fleisch's _A Student's Guide to Maxwell's Equations_.
I've attached an image of what such an annotated equation looks like (from page 2 of Fleisch's book). It's like a labeled part diagram (say, for a laptop), where each part (here, each symbol) is connected with an line to its explanation.
I'm trying to do so with a combination of ConTeXt, MetaPost/MetaFun, TikZ, and whatever else might work. But I am a bit stuck at the following spot.
My plan is to use MetaFun to get the coordinates of each symbol in a (displayed) equation and then, with MetaFun, connect those symbols to mini-paragraphs of explanation that surround the equation.
But I am stuck on how to use \hpos in math mode. I'd like to do something like:
\startformula \hpos{n1}{\sum}_{\hpos{n2}{0}}^{\hpos{n3}{1}} \stopformula
to get the locations of the nodes n1, n2, and n3 without interfering with the math typesetting -- e.g., the engine should still know that \sum is in display-math mode, so it should be large and have its sub- and super-scripts below and above it, rather than next to it.
However, the \hpos hides its argument in an \hbox, and thus hides it from the math layout. Thus, I have to do something like this minimal example:
\starttext \startformula \sum_0^1 % what it should look like \quad \hpos{n1}{$\displaystyle\sum$}_{\hpos{n2}{$0$}}^{\hpos{n3}{$1$}} \stopformula \stoptext
The hpos'ed version after the \quad looks different, even after the \displaystyle hack.
Is there a version of \hpos for math mode? That would be the cleanest solution, because who knows what else would be needed for other cases, even if the limits can be placed correctly.
Or is there a better way to annotate equations?
(TikZ seems to have the same issue, in that it cannot see into equations.)
Regards, -- -Sanjoy
http://savelongwharfpark.org/ Save Long Wharf Park in Boston Harbor!
http://streetfightingmath.com/ Six reasoning tools to make hard problems easy.
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On Thu, 16 Nov 2017, Sanjoy Mahajan wrote:
However, the \hpos hides its argument in an \hbox, and thus hides it from the math layout. Thus, I have to do something like this minimal example:
\starttext \startformula \sum_0^1 % what it should look like \quad \hpos{n1}{$\displaystyle\sum$}_{\hpos{n2}{$0$}}^{\hpos{n3}{$1$}} \stopformula \stoptext
The hpos'ed version after the \quad looks different, even after the \displaystyle hack.
Is there a version of \hpos for math mode? That would be the cleanest solution, because who knows what else would be needed for other cases, even if the limits can be placed correctly.
Or is there a better way to annotate equations?
No time for a detailed answer, but what you need is the following: \starttext \startformula \sum_0^1 % what it should look like \quad \mathop{\hpos{n1}{\mathsurround\zeropoint$\displaystyle\sum$}}_{\hpos{n2}{\mathsurround\zeropoint$\scriptstyle0$}}^{\hpos{n3}{\mathsurround\zeropoint$\scriptstyle1$}} \stopformula \stoptext So what you need to do is find the mathmode of the current symbol (mathbin, mathord, etc) and find the mathstyle of the current symbol (\displaystyle, \scriptstyle, \scriptscriptstyle, etc), and reapply those. There is some code in the core to do detect whether the current symbol is a bin or not (and perhaps that can be adapted to see if the current symbol is an op or not). But a simpler solution will be use luatex to traverse the mathlist after it has been typeset (but I don't understand who that works). Of course, an ideal solution will be to define a macro \mpos{...} that does this behind the scenes. Aditya
[Sorry for probably breaking the threading -- long story with not using the mailing-list administrative interface correctly at first.] Aditya writes:
No time for a detailed answer, but what you need is the following: ...
Thank you -- that should work. I won't have many of these equation beasts, and I can annotate them with \mathop, \mathord, etc. without much trouble. If I get ambitious, I'll look into the LuaTeX parsing. But I fear that there aren't enough such equations to force me into learning that much of the internals. Maybe there's even an easier way with \mpos creating some kind of callback, whereby LuaTeX talks back to it after typesetting the math node? Perhaps it adds a field to the node tree (if that's the right word). But I am rapidly spiraling beyond my LuaTeX understanding... Nigel King writes:
Wow. I learnt about Maxwell's Equation 48 years ago. I never understood it then nor on the intervening time despite sometimes helping design antennas. The picture and its annotation definitely helps creating clarity. For my twopenneth the effort is very worthwhile.
The _Maxwell's Equations_ book is really good. I hope that mine can be two-thirds as good. -Sanjoy
participants (3)
-
Aditya Mahajan
-
Nigel King
-
Sanjoy Mahajan