Andre Poenitz wrote:

> I could create something intermediate: insets that "know" waht is "below"
> could say so (i.e. a numerator "knows" that there is something below, since
> they belong to the same fracinset).

Do you mean the same as what I proposed on 2001-07-24 (copy below)? If
not, what's the difference? 

BTW, it's possible to save memory by using virtual methods in the inset
instead of actually storing the 'floor' values in the xcell array.

------------------------------------------------
In the xcell array of math insets, assign an integer called 'floor' to
each cell, denoting relative vertical level: for instance, in \frac the
numerator is on floor 1 and the denominator on floor 0. This gives an
implicit tree structure on all the insets in the formula, with ordering
among the edges of each node (actually partially ordering, in case when
several subinsets are on the same floor). There remains only to traverse
this tree when needed:

Define the pseudofunctions (square brackets mark magic):

  // Return next lowest sibling inset, if any:
  MathInset inset_below(MathInset current, MathInset parent,
                        [horizontal cursor location]        )
  {  
     if [all subinsets of parent have floor >= current.floor]
        return null;
     else {
        floor_below = [ max{ x s.t. x < current->floor and
                             exists subinset S of 'parent' s.t.
                                    x = S->floor          } ];
        candidates = [ subinsets of 'parent' that have 
                       floor == floor_below ];
        return [ element of 'candidates' that's horizontally
                 closest to the cursor                       ];
     }
  }

   // Return topmost subinset:
   MathInset topmost_subinset(MathInset current, 
                              [horizontal cursor position] )
   {
      topmost_floor = [ max floor among all subinsets 
                          of current                        ];
      candidates = [ subinsets of of 'parent' that have
                     floor == topmost_floor ];
      return [ element of 'candidates' that's horizontally
               closest to the cursor                       ];
   }
    

Upon MathCursor action upon <down>:
{
   // Pop up insets until we can move down:
   while ( (below = inset_below(current, parent, [something]) == null )
{
      if (!pop()) [ do something smart ];
   }
   // Go to the topmost subsubsub...sub inset:
   while ( (topmost = topmost_subinset(current, [something]) ) {
      below = topmost;
   }
   [go to inset 'below']
}


Gotcha:
in $\frac{|xxx}{ \frac{y}{z} }$ we want <down> to do
   $\frac{xxx}{ \frac{|y}{z} }$ so the above logic works nicely.
However, in $\frac{xxx|}{ y^{s} }$ we want <down> to do
            $\frac{xxx}{ y^{s|} }$ rather than
            $\frac{xxx}{ y^{|s| }$ even though the superscript is
than the 'y'. This is true in general for scripts. So, give the 
script insets a floor value of +1000 (superscript) and -1000, and
tell topmost_subinset to ignore insets with these floor values.
------------------------------------------------

Reply via email to