anchor.diff:          begin
             BottomMargin := Block.MargArray[MarginBottom];
             Block.MargArray[MarginBottom] := 0;
  -          MargArray[MarginBottom] := Max(MargArray[MarginBottom], BottomMargin);
  +          MargArray[MarginBottom] := Collapse(MargArray[MarginBottom], BottomMargin);
           end;
       end;
     end;
  
positive.code:       begin
          LastMargin := TBlock(TB).MargArray[MarginBottom];
          TBlock(TB).MargArray[MarginBottom] := 0;
          Negs := 0;
          if LastMargin < 0 then {figure out how many are negative}
            Inc(Negs);
          if MargArray[MarginTop] < 0 then
            Inc(Negs);
          case Negs of
            0: MargArray[MarginTop] := Max(MargArray[MarginTop], LastMargin);
            1: MargArray[MarginTop] :=     MargArray[MarginTop] + LastMargin;
            2: MargArray[MarginTop] := Min(MargArray[MarginTop], LastMargin);
          end;
        end
        else if (Tag = LISy) and TopAuto and (Symbol in [ULSy, OLSy]) then
          MargArray[MarginTop] := 0; {removes space from nested lists}
  
negative.code:   {$ENDIF}
  end;
  
  //-- BG ---------------------------------------------------------- 17.05.2014 --
  function Collapse(A, B: Integer): Integer; {$ifdef UseInline} inline; {$endif}
  begin
    if A >= 0 then
      if B >= 0 then
        Result := Max(A, B)
      else
        Result := A + B
    else
      if B >= 0 then
        Result := B + A
      else
        Result := Min(A, B);
  end;
  
  procedure TBlock.CollapseMargins;
  {adjacent vertical margins need to be reduced}
  var
    TopAuto: boolean;
    TB: TSectionBase;
    LastMargin, I: Integer;
    Tag: TElemSymb;
    CD: ThtConvData;
  begin
  