The branch, betterspacing, has been updated.
  discards  15825bd45672dc54a819bbf179cee9d3a0bf48be (commit)
  discards  c0451d23aabcd01b1db8af793fe0af02684613fa (commit)
  discards  390262a1553867d807fe36782268d83f9cb35825 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (15825bd45672dc54a819bbf179cee9d3a0bf48be)
            \
             N -- N -- N (56077f3a213e4050a5c7c63e1ec8174cd1da6244)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

- Log -----------------------------------------------------------------

commit 56077f3a213e4050a5c7c63e1ec8174cd1da6244
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Nov 14 15:33:51 2016 +0100

    Cleanup of lib/symbols
    
    Try as far as possible to use the same definitions as in the LaTeX files.
    
    An example of that is the definition and subsequent use of \joinrel,
    \relbar and \Relbar.
    
    This is mostly Guillaume's work.

diff --git a/lib/symbols b/lib/symbols
index 481aa81..aadcd0d 100644
--- a/lib/symbols
+++ b/lib/symbols
@@ -300,8 +300,7 @@ spadesuit          cmsy        127 170 mathord  &spades;
 # We define lyxnot as mathrel in order to have proper alignment
 lyxnot             cmsy         54  47 mathrel  /           hiddensymbol
 iffont cmsy
-# 10mu is the extra space added to relation operators
-\def\not{\lyxnot\kern-20mu}
+\def\not{\lyxnot\mathrel{\kern-11mu}}
 else
 \def\not{\kern4mu\lyxnot\kern-19mu}
 endif
@@ -669,7 +668,7 @@ hslash             msb         125   0 mathord  &plankv;
 hbar               msb         126   0 mathord  &planck;
 backepsilon        msb         127   0 mathrel  &bepsi;
 
-lyxbar             cmsy        161   0 mathord   &mdash;  hiddensymbol
+lyxbar             cmsy        161   0 mathrel   &mdash;  hiddensymbol
 lyxminus           cmsy        161   0 mathbin   &mdash;  hiddensymbol
 lyxplus            cmr          43  43 mathbin   +        hiddensymbol
 lyxeq              cmr          61  61 mathord   =        hiddensymbol
@@ -795,7 +794,7 @@ APLup              wasy          0   0 x        x
 APLdown            wasy          70  0 x        x
 APLinput           wasy          125 0 x        x
 APLcomment         wasy          127 0 x        x
-\def\APLinv{\div\kern-17.9mu\APLbox}                       wasysym
+\def\APLinv{\mathord{\div\kern-13.9mu\APLbox}}  wasysym
 APLuparrowbox      wasy         110  0 x        &#x2350;
 APLdownarrowbox    wasy         111  0 x        &#x2357;
 APLleftarrowbox    wasy         112  0 x        &#x2347;
@@ -976,15 +975,15 @@ bignplus           stmry 112   0 mathop     x  stmaryrd # 
caution: named hugenpl
 #Largerrbracketbot  stmry 126   0 mathclose  x  stmaryrd # only in the font, 
not the .sty caution: named Hugerrbracketbot in the font
 #rrbracketex        stmry 127   0 mathclose  x  stmaryrd # only in the font, 
not the .sty caution: named Hugerrbracketex in the font
 
-\def\varcopyright{c\kern-14mu\varbigcirc}                   stmaryrd
-\def\longarrownot{\kern5.5mu\arrownot\kern-5.5mu}           stmaryrd
-\def\Longarrownot{\kern5.5mu\Arrownot\kern-5.5mu}           stmaryrd
-\def\Mapsto{\Mapstochar\kern-9mu\Rightarrow}                stmaryrd
+\def\varcopyright{\mathord{c\kern-11mu\varbigcirc}}         stmaryrd
+\def\longarrownot{\mathrel{\kern5.5mu}\arrownot\mathrel{\kern-5.5mu}} stmaryrd
+\def\Longarrownot{\mathrel{\kern5.5mu}\Arrownot\mathrel{\kern-5.5mu}} stmaryrd
+\def\Mapsto{\Mapstochar\mathrel{\kern-2mu}\Rightarrow}      stmaryrd
 \def\mapsfrom{\leftarrow\kern-9mu\mapsfromchar}             stmaryrd
 \def\Mapsfrom{\Leftarrow\kern-9mu\Mapsfromchar}             stmaryrd
-\def\Longmapsto{\Mapstochar\kern-7mu\Longrightarrow}        stmaryrd
-\def\longmapsfrom{\longleftarrow\kern-7mu\mapsfromchar}     stmaryrd
-\def\Longmapsfrom{\Longleftarrow\kern-7mu\Mapsfromchar}     stmaryrd
+\def\Longmapsto{\Mapstochar\Longrightarrow}                 stmaryrd
+\def\longmapsfrom{\longleftarrow\mapsfromchar}              stmaryrd
+\def\Longmapsfrom{\Longleftarrow\mathrel{\kern1mu}\Mapsfromchar}      stmaryrd
 
 # symbols from the mhchem package, all of them are equivalent to a math symbol
 # mhchem is not loaded because these commands can only be used inside
@@ -1115,21 +1114,21 @@ pod                lyxblacktext  0   0 func     x     
amsmath
 
 
 # mathtools.sty
-vcentcolon         cmr          58  58            mathrel :        mathtools
-ordinarycolon      cmr          58  58            mathrel :        mathtools
-\def\dblcolon{\vcentcolon\kern-10.9mu\vcentcolon} mathrel ::       mathtools
-\def\coloneqq{\vcentcolon\kern-11.2mu=}           mathrel &#x2254; mathtools
-\def\Coloneqq{\dblcolon\kern-11.2mu=}             mathrel ::=      mathtools
-\def\coloneq{\vcentcolon\kern-11.2mu-}            mathrel :-       mathtools
-\def\Coloneq{\dblcolon\kern-11.2mu-}              mathrel ::-      mathtools
-\def\eqqcolon{=\kern-11.2mu\vcentcolon}           mathrel &#x2255; mathtools
-\def\Eqqcolon{=\kern-11.2mu\dblcolon}             mathrel =::      mathtools
-\def\eqcolon{-\kern-11.2mu\vcentcolon}            mathrel -:       mathtools
-\def\Eqcolon{-\kern-11.2mu\dblcolon}              mathrel -::      mathtools
-\def\colonapprox{\vcentcolon\kern-11.2mu\approx}  mathrel :&ap;    mathtools
-\def\Colonapprox{\dblcolon\kern-11.2mu\approx}    mathrel ::&ap;   mathtools
-\def\colonsim{\vcentcolon\kern-11.2mu\sim}        mathrel :&sim;   mathtools
-\def\Colonsim{\dblcolon\kern-11.2mu\sim}          mathrel ::&sim;  mathtools
+vcentcolon         cmr          58  58    mathrel :             mathtools
+ordinarycolon      cmr          58  58    mathrel :             mathtools
+\def\dblcolon{\vcentcolon\mathrel{\kern-0.9mu}\vcentcolon}      mathrel ::     
  mathtools
+\def\coloneqq{\vcentcolon\mathrel{\kern-1.2mu}=}                mathrel 
&#x2254; mathtools
+\def\Coloneqq{\dblcolon\mathrel{\kern-1.2mu}=}                  mathrel ::=    
  mathtools
+\def\coloneq{\vcentcolon\mathrel{\kern-1.2mu}\mathrel{-}}       mathrel :-     
  mathtools
+\def\Coloneq{\dblcolon\mathrel{\kern-1.2mu}\mathrel{-}}         mathrel ::-    
  mathtools
+\def\eqqcolon{=\mathrel{\kern-1.2mu}\vcentcolon}                mathrel 
&#x2255; mathtools
+\def\Eqqcolon{=\mathrel{\kern-1.2mu}\dblcolon}                  mathrel =::    
  mathtools
+\def\eqcolon{\mathrel{-}\mathrel{\kern-1.2mu}\vcentcolon}                 
mathrel -:       mathtools
+\def\Eqcolon{\mathrel{-}\mathrel{\kern-1.2mu}\dblcolon}                   
mathrel -::      mathtools
+\def\colonapprox{\vcentcolon\mathrel{\kern-1.2mu}\approx}       mathrel :&ap;  
  mathtools
+\def\Colonapprox{\dblcolon\mathrel{\kern-1.2mu}\approx}         mathrel ::&ap; 
  mathtools
+\def\colonsim{\vcentcolon\mathrel{\kern-1.2mu}\sim}             mathrel :&sim; 
  mathtools
+\def\Colonsim{\dblcolon\mathrel{\kern-1.2mu}\sim}               mathrel 
::&sim;  mathtools
 
 
 #
@@ -1144,50 +1143,53 @@ ordinarycolon      cmr          58  58            
mathrel :        mathtools
 \def\notin{\not\in}                                             mathrel &notin;
 \def\slash{/}
 
-\def\longleftrightarrow{\leftarrow\kern-12.5mu\rightarrow}
-\def\Longleftrightarrow{\Leftarrow\kern-12.5mu\Rightarrow}
-\def\iff{\Leftarrow\kern-12.5mu\Rightarrow}
+\def\joinrel{\mathrel{\kern-3mu}}
+\def\relbar{\lyxbar}
+\def\Relbar{\mathrel{=}}
+\def\longleftrightarrow{\leftarrow\joinrel\rightarrow}
+\def\Longleftrightarrow{\Leftarrow\joinrel\Rightarrow}
+\def\iff{\Leftarrow\joinrel\Rightarrow}
 \def\doteq{\stackrel{\cdot}{=}}
 
 iffont cmsy
-\def\longrightarrow{\lyxbar\kern-11mu\rightarrow}               mathrel &xrarr;
-\def\longleftarrow{\leftarrow\kern-11mu\lyxbar}                 mathrel &xlarr;
-\def\Longrightarrow{\lyxeq\kern-9.5mu\Rightarrow}               mathrel 
&#x27F9;
-\def\Longleftarrow{\Leftarrow\kern-9.5mu\lyxeq}                 mathrel 
&#x27F8;
+\def\longrightarrow{\relbar\joinrel\rightarrow}                 mathrel &xrarr;
+\def\longleftarrow{\leftarrow\joinrel\relbar}                   mathrel &xlarr;
+\def\Longrightarrow{\Relbar\joinrel\Rightarrow}                 mathrel 
&#x27F9;
+\def\Longleftarrow{\Leftarrow\joinrel\Relbar}                   mathrel 
&#x27F8;
 \def\implies{\Longrightarrow}                                   mathrel 
&#x27F9; amsmath
 \def\impliedby{\Longleftarrow}                                  mathrel 
&#x27F8; amsmath
-\def\mapsto{\mapstochar\kern-9mu\rightarrow}                    mathrel 
&#x21A4;
-\def\longmapsto{\mapstochar\kern-6mu\lyxbar\kern-11mu\rightarrow} mathrel 
&#x27FB;
-\def\models{\vert\kern-3mu\lyxeq}                               mathrel &vDash;
+\def\mapsto{\mapstochar\mathrel{\kern-2mu}\rightarrow}          mathrel 
&#x21A4;
+\def\longmapsto{\mapstochar\joinrel\relbar\joinrel\rightarrow}  mathrel 
&#x27FB;
+\def\models{\mathrel{\vert}\joinrel\Relbar}                     mathrel &vDash;
 else
 \def\implies{=>}                                                mathrel 
&#x27F9; amsmath
 \def\impliedby{<=}                                              mathrel 
&#x27F8; amsmath
 endif
 iffont cmm
-\def\hookrightarrow{\lhook\kern-12mu\rightarrow}                mathrel 
&#x21AA;
-\def\hookleftarrow{\leftarrow\kern-12mu\rhook}                  mathrel 
&#x21A9;
-\def\bowtie{\triangleright\kern-10mu\triangleleft}              mathrel 
&#x22C8;
+\def\hookrightarrow{\lhook\joinrel\rightarrow}                  mathrel 
&#x21AA;
+\def\hookleftarrow{\leftarrow\joinrel\rhook}                    mathrel 
&#x21A9;
+\def\bowtie{\mathrel\triangleright\joinrel\mathrel\triangleleft} mathrel 
&#x22C8;
 endif
 iffont msa
-\def\dashrightarrow{\lyxdabar\lyxdabar\lyxright}                mathrel 
&#x290F; amssymb
-\def\dashleftarrow{\lyxleft\lyxdabar\lyxdabar}                  mathrel 
&#x290E; amssymb
+\def\dashrightarrow{\mathrel{\lyxdabar\lyxdabar\lyxright}}      mathrel 
&#x290F; amssymb
+\def\dashleftarrow{\mathrel{\lyxleft\lyxdabar\lyxdabar}}        mathrel 
&#x290E; amssymb
 else
 \def\dashrightarrow{- - \rightarrow}                            mathrel 
&#x290F; amssymb
 \def\dashleftarrow{\leftarrow{} - -}                            mathrel 
&#x290E; amssymb
 endif
 \def\dasharrow{\dashrightarrow}                                 mathrel 
&#x290F; amssymb
 iffont msb
-\def\Join{\ltimes\kern-22mu\rtimes}                             amssymb
+\def\Join{\mathrel{\ltimes\kern-13.5mu\rtimes}}                 amssymb
 else
 \def\Join{|x|}                                                  amssymb
 endif
-# Fixme: latin-1 chars in text file
+# FIXME: UTF-8 chars in text file
 \def\AA{\AA}{Å} textmode &Aring;  amstext,lyxmathsym
 \def\O{\O}{Ø}   textmode &Oslash; amstext,lyxmathsym
 
 iffont cmsy
 # The \sim is placed too high...
-\def\cong{\stackrel{_\sim}{=}}                                  mathrel &cong;
+\def\cong{\stackrel{\sim}{=}}                                   mathrel &cong;
 lyxsurd               cmsy        112 0 mathord  &radic;
 \def\surd{^\lyxsurd}                                            mathord &radic;
 \def\textdegree{\kern-1mu^{\circ}\kern-4mu} textmode &deg; 
textcomp,amstext,lyxmathsym

commit 188ebc4d0ef19e0ea1f41f5d33617eb176064232
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Nov 14 18:01:56 2016 +0100

    Skip drawing of markers in non-editable math data
    
    There is no reason to reserve pixel space in macros replacement text,
    which is not editable. This makes macros more compact and eases the
    writing of lib/symbols.
    
    * introduce new InsetMath::drawMarkers and friends that do nothing
      when nested inside a macro. This required to move macro_nesting
      inside MetricsBase, and to pass MetricsInfo & to metricsMarkers.
    
    * keep track of nesting when drawing rows or macros.

diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index 02bbab3..fdde05f 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -38,8 +38,8 @@ namespace lyx {
 
 MetricsBase::MetricsBase(BufferView * b, FontInfo f, int w)
        : bv(b), font(move(f)), style(LM_ST_TEXT), fontname("mathnormal"),
-         textwidth(w), solid_line_thickness_(1), solid_line_offset_(1),
-         dotted_line_thickness_(1)
+         textwidth(w), macro_nesting(0),
+         solid_line_thickness_(1), solid_line_offset_(1), 
dotted_line_thickness_(1)
 {
        if (lyxrc.zoom >= 200) {
                // derive the line thickness from zoom factor
@@ -88,7 +88,7 @@ Changer MetricsBase::changeFontSet(string const & name, bool 
cond)
 
 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
                          MacroContext const & mc)
-       : base(bv, font, textwidth), macro_nesting(0), macrocontext(mc)
+       : base(bv, font, textwidth), macrocontext(mc)
 {}
 
 
diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h
index 415fe25..a48b45c 100644
--- a/src/MetricsInfo.h
+++ b/src/MetricsInfo.h
@@ -65,6 +65,8 @@ public:
        std::string fontname;
        /// This is the width available in pixels
        int textwidth;
+       /// count wether the current mathdata is nested in macro(s)
+       int macro_nesting;
 
        /// Temporarily change a full font.
        Changer changeFontSet(std::string const & font, bool cond = true);
@@ -101,8 +103,6 @@ public:
 
        ///
        MetricsBase base;
-       /// count wether the current mathdata is nested in macro(s)
-       int macro_nesting;
        /// The context to resolve macros
        MacroContext const & macrocontext;
 };
diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp
index d2182a5..cbf33cd 100644
--- a/src/mathed/InsetMath.cpp
+++ b/src/mathed/InsetMath.cpp
@@ -16,13 +16,15 @@
 #include "MathRow.h"
 #include "MathStream.h"
 
+#include "MetricsInfo.h"
+
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
-#include "support/lassert.h"
 
 using namespace std;
 
@@ -65,6 +67,36 @@ bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & 
mi) const
        return true;
 }
 
+void InsetMath::metricsMarkers(MetricsInfo & mi, Dimension & dim,
+                           int framesize) const
+{
+       if (!mi.base.macro_nesting)
+               Inset::metricsMarkers(dim, framesize);
+}
+
+
+void InsetMath::metricsMarkers2(MetricsInfo & mi, Dimension & dim,
+                            int framesize) const
+{
+       if (!mi.base.macro_nesting)
+               Inset::metricsMarkers2(dim, framesize);
+}
+
+
+void InsetMath::drawMarkers(PainterInfo & pi, int x, int y) const
+{
+       if (!pi.base.macro_nesting)
+               Inset::drawMarkers(pi, x, y);
+}
+
+
+void InsetMath::drawMarkers2(PainterInfo & pi, int x, int y) const
+{
+       if (!pi.base.macro_nesting)
+               Inset::drawMarkers2(pi, x, y);
+}
+
+
 
 void InsetMath::dump() const
 {
diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h
index f8e70c7..e8c893b 100644
--- a/src/mathed/InsetMath.h
+++ b/src/mathed/InsetMath.h
@@ -169,6 +169,15 @@ public:
        /// Add this inset to a math row. Return true if contents got added
        virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
 
+       /// draw four angular markers
+       void drawMarkers(PainterInfo & pi, int x, int y) const;
+       /// draw two angular markers
+       void drawMarkers2(PainterInfo & pi, int x, int y) const;
+       /// add space for markers
+       void metricsMarkers(MetricsInfo & mi, Dimension & dim, int framesize = 
1) const;
+       /// add space for markers
+       void metricsMarkers2(MetricsInfo & mi, Dimension & dim, int framesize = 
1) const;
+
        /// identifies things that can get scripts
        virtual bool isScriptable() const { return false; }
        /// will this get written as a single block in {..}
diff --git a/src/mathed/InsetMathBoldSymbol.cpp 
b/src/mathed/InsetMathBoldSymbol.cpp
index 215bd5f..ade29f7 100644
--- a/src/mathed/InsetMathBoldSymbol.cpp
+++ b/src/mathed/InsetMathBoldSymbol.cpp
@@ -51,7 +51,7 @@ void InsetMathBoldSymbol::metrics(MetricsInfo & mi, Dimension 
& dim) const
 {
        //Changer dummy = mi.base.changeFontSet("mathbf");
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
        ++dim.wid;  // for 'double stroke'
 }
 
diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp
index e9e483c..d0ac82f 100644
--- a/src/mathed/InsetMathBox.cpp
+++ b/src/mathed/InsetMathBox.cpp
@@ -83,7 +83,7 @@ void InsetMathBox::metrics(MetricsInfo & mi, Dimension & dim) 
const
 {
        Changer dummy = mi.base.changeFontSet("textnormal");
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
@@ -135,7 +135,7 @@ void InsetMathFBox::metrics(MetricsInfo & mi, Dimension & 
dim) const
 {
        Changer dummy = mi.base.changeFontSet("textnormal");
        cell(0).metrics(mi, dim);
-       metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
+       metricsMarkers2(mi, dim, 3); // 1 pixel space, 1 frame, 1 space
 }
 
 
@@ -246,7 +246,7 @@ void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension 
& dim) const
                dim.des += 1;
        }
        
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
@@ -360,7 +360,7 @@ InsetMathBoxed::InsetMathBoxed(Buffer * buf)
 void InsetMathBoxed::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers2(dim, 3); // 1 pixel space, 1 frame, 1 space
+       metricsMarkers2(mi, dim, 3); // 1 pixel space, 1 frame, 1 space
 }
 
 
diff --git a/src/mathed/InsetMathBrace.cpp b/src/mathed/InsetMathBrace.cpp
index 52ccc01..6870fa6 100644
--- a/src/mathed/InsetMathBrace.cpp
+++ b/src/mathed/InsetMathBrace.cpp
@@ -55,7 +55,7 @@ void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc = max(dim0.asc, t.asc);
        dim.des = max(dim0.des, t.des);
        dim.wid = dim0.width() + 2 * t.wid;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathCancel.cpp b/src/mathed/InsetMathCancel.cpp
index dcda5b6..0a8aad9 100644
--- a/src/mathed/InsetMathCancel.cpp
+++ b/src/mathed/InsetMathCancel.cpp
@@ -38,7 +38,7 @@ Inset * InsetMathCancel::clone() const
 void InsetMathCancel::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathCancelto.cpp b/src/mathed/InsetMathCancelto.cpp
index 6a04cfa..6170cbd 100644
--- a/src/mathed/InsetMathCancelto.cpp
+++ b/src/mathed/InsetMathCancelto.cpp
@@ -47,7 +47,7 @@ void InsetMathCancelto::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc = max(dim0.ascent() + 2, dim0.ascent() + dim1.ascent()) + 2 + 8;
        dim.des = max(dim0.descent() - 2, dim1.descent()) + 2;
        dim.wid = dim0.width() + dim1.width() + 10;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathClass.cpp b/src/mathed/InsetMathClass.cpp
index 931a68b..0237f25 100644
--- a/src/mathed/InsetMathClass.cpp
+++ b/src/mathed/InsetMathClass.cpp
@@ -31,7 +31,7 @@ Inset * InsetMathClass::clone() const
 void InsetMathClass::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathColor.cpp b/src/mathed/InsetMathColor.cpp
index 0a6d0aa..966fe5e 100644
--- a/src/mathed/InsetMathColor.cpp
+++ b/src/mathed/InsetMathColor.cpp
@@ -49,7 +49,7 @@ Inset * InsetMathColor::clone() const
 void InsetMathColor::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathComment.cpp b/src/mathed/InsetMathComment.cpp
index ff91991..b8c157b 100644
--- a/src/mathed/InsetMathComment.cpp
+++ b/src/mathed/InsetMathComment.cpp
@@ -50,7 +50,7 @@ Inset * InsetMathComment::clone() const
 void InsetMathComment::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathDecoration.cpp 
b/src/mathed/InsetMathDecoration.cpp
index cd34d4d..acc4974 100644
--- a/src/mathed/InsetMathDecoration.cpp
+++ b/src/mathed/InsetMathDecoration.cpp
@@ -122,7 +122,7 @@ void InsetMathDecoration::metrics(MetricsInfo & mi, 
Dimension & dim) const
                dim.des += dh_ + 2;
        }
 
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathEnsureMath.cpp 
b/src/mathed/InsetMathEnsureMath.cpp
index d1e69fb..382c6fe 100644
--- a/src/mathed/InsetMathEnsureMath.cpp
+++ b/src/mathed/InsetMathEnsureMath.cpp
@@ -41,7 +41,7 @@ void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension 
& dim) const
        bool really_change_font = isTextFont(mi.base.fontname);
        Changer dummy = mi.base.changeFontSet("mathnormal", really_change_font);
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathEnv.cpp b/src/mathed/InsetMathEnv.cpp
index cc613fd..7582201 100644
--- a/src/mathed/InsetMathEnv.cpp
+++ b/src/mathed/InsetMathEnv.cpp
@@ -39,7 +39,7 @@ Inset * InsetMathEnv::clone() const
 void InsetMathEnv::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp
index 40623f6..825cf33 100644
--- a/src/mathed/InsetMathFont.cpp
+++ b/src/mathed/InsetMathFont.cpp
@@ -86,7 +86,7 @@ void InsetMathFont::metrics(MetricsInfo & mi, Dimension & 
dim) const
 {
        Changer dummy = mi.base.changeFontSet(font());
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathFontOld.cpp b/src/mathed/InsetMathFontOld.cpp
index 20f3b1d..aa574bd 100644
--- a/src/mathed/InsetMathFontOld.cpp
+++ b/src/mathed/InsetMathFontOld.cpp
@@ -61,7 +61,7 @@ void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & 
dim) const
 
        Changer dummy = mi.base.changeFontSet(fontname, really_change_font);
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathFrac.cpp b/src/mathed/InsetMathFrac.cpp
index 263587e..6254924 100644
--- a/src/mathed/InsetMathFrac.cpp
+++ b/src/mathed/InsetMathFrac.cpp
@@ -207,7 +207,7 @@ void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & 
dim) const
                        dim.des = dim1.height() + 2 - 5;
                }
        }
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
@@ -582,7 +582,7 @@ void InsetMathBinom::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc = dim0.height() + 4 + 5;
        dim.des = dim1.height() + 4 - 5;
        dim.wid = max(dim0.wid, dim1.wid) + 2 * dw(dim.height()) + 4;
-       metricsMarkers2(dim);
+       metricsMarkers2(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 053958d..fca8f38 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -588,7 +588,7 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & 
dim) const
        }
 */
        dim.wid += leftMargin() + rightMargin();
-       metricsMarkers2(dim);
+       metricsMarkers2(mi, dim);
        // Cache the inset dimension.
        setDimCache(mi, dim);
 }
diff --git a/src/mathed/InsetMathLefteqn.cpp b/src/mathed/InsetMathLefteqn.cpp
index ec4fe7e..176c743 100644
--- a/src/mathed/InsetMathLefteqn.cpp
+++ b/src/mathed/InsetMathLefteqn.cpp
@@ -34,7 +34,7 @@ void InsetMathLefteqn::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc += 2;
        dim.des += 2;
        dim.wid = 4;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathOverset.cpp b/src/mathed/InsetMathOverset.cpp
index f05bbd7..b791c24 100644
--- a/src/mathed/InsetMathOverset.cpp
+++ b/src/mathed/InsetMathOverset.cpp
@@ -39,7 +39,7 @@ void InsetMathOverset::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.wid = max(dim0.width(), dim1.wid) + 4;
        dim.asc = dim1.asc + dim0.height() + 4;
        dim.des = dim1.des;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathPhantom.cpp b/src/mathed/InsetMathPhantom.cpp
index 4a190ea..6d0b88d 100644
--- a/src/mathed/InsetMathPhantom.cpp
+++ b/src/mathed/InsetMathPhantom.cpp
@@ -39,7 +39,7 @@ Inset * InsetMathPhantom::clone() const
 void InsetMathPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathRoot.cpp b/src/mathed/InsetMathRoot.cpp
index 2b4b668..aa0a81b 100644
--- a/src/mathed/InsetMathRoot.cpp
+++ b/src/mathed/InsetMathRoot.cpp
@@ -47,7 +47,7 @@ void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc = max(dim0.ascent()  + 5, dim1.ascent())  + 2;
        dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
        dim.wid = dim0.width() + dim1.width() + 10;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp
index 8098a1a..7363c88 100644
--- a/src/mathed/InsetMathScript.cpp
+++ b/src/mathed/InsetMathScript.cpp
@@ -333,7 +333,7 @@ void InsetMathScript::metrics(MetricsInfo & mi, Dimension & 
dim) const
                dim.des = max(nd, des);
        } else
                dim.des = nd;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathSideset.cpp b/src/mathed/InsetMathSideset.cpp
index 37f437d..b04eca7 100644
--- a/src/mathed/InsetMathSideset.cpp
+++ b/src/mathed/InsetMathSideset.cpp
@@ -221,7 +221,7 @@ void InsetMathSideset::metrics(MetricsInfo & mi, Dimension 
& dim) const
        int nd = ndes(bv);
        int des = dyb(bv) + max(dimbl.descent(), dimbr.descent());
        dim.des = max(nd, des);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathSize.cpp b/src/mathed/InsetMathSize.cpp
index 31cdb6a..46ea29b 100644
--- a/src/mathed/InsetMathSize.cpp
+++ b/src/mathed/InsetMathSize.cpp
@@ -45,7 +45,7 @@ void InsetMathSize::metrics(MetricsInfo & mi, Dimension & 
dim) const
 {
        Changer dummy = mi.base.changeStyle(style_);
        cell(0).metrics(mi, dim);
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathSqrt.cpp b/src/mathed/InsetMathSqrt.cpp
index d04eab3..3e49abc 100644
--- a/src/mathed/InsetMathSqrt.cpp
+++ b/src/mathed/InsetMathSqrt.cpp
@@ -41,7 +41,7 @@ void InsetMathSqrt::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.asc += 4;
        dim.des += 2;
        dim.wid += 12;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathStackrel.cpp b/src/mathed/InsetMathStackrel.cpp
index 3dda0da..e34448a 100644
--- a/src/mathed/InsetMathStackrel.cpp
+++ b/src/mathed/InsetMathStackrel.cpp
@@ -77,7 +77,7 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & 
dim) const
                dim.asc = dim1.ascent() + dim0.height() + 4;
                dim.des = dim1.descent();
        }
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathUnderset.cpp b/src/mathed/InsetMathUnderset.cpp
index 46f5277..2027cf2 100644
--- a/src/mathed/InsetMathUnderset.cpp
+++ b/src/mathed/InsetMathUnderset.cpp
@@ -40,7 +40,7 @@ void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.wid = max(dim0.width(), dim1.width()) + 4;
        dim.asc = dim1.ascent();
        dim.des = dim1.descent() + dim0.height() + 4;
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/InsetMathXArrow.cpp b/src/mathed/InsetMathXArrow.cpp
index 96fdc83..a4c1c12 100644
--- a/src/mathed/InsetMathXArrow.cpp
+++ b/src/mathed/InsetMathXArrow.cpp
@@ -51,7 +51,7 @@ void InsetMathXArrow::metrics(MetricsInfo & mi, Dimension & 
dim) const
        dim.wid = max(dim0.width(), dim1.width()) + 10;
        dim.asc = dim0.height() + 10;
        dim.des = dim1.height();
-       metricsMarkers(dim);
+       metricsMarkers(mi, dim);
 }
 
 
diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index a748821..5820572 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -71,9 +71,9 @@ public:
        bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const
        {
                // macro arguments are in macros
-               LATTEST(mi.macro_nesting > 0);
-               if (mi.macro_nesting == 1)
-                       mi.macro_nesting = 0;
+               LATTEST(mi.base.macro_nesting > 0);
+               if (mi.base.macro_nesting == 1)
+                       mi.base.macro_nesting = 0;
 
                MathRow::Element e_beg(MathRow::BEG_ARG, mi);
                e_beg.macro = mathMacro_;
@@ -107,9 +107,9 @@ public:
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const {
                // macro arguments are in macros
-               LATTEST(mi.macro_nesting > 0);
-               if (mi.macro_nesting == 1)
-                       mi.macro_nesting = 0;
+               LATTEST(mi.base.macro_nesting > 0);
+               if (mi.base.macro_nesting == 1)
+                       mi.base.macro_nesting = 0;
 
                mathMacro_->macro()->unlock();
                mathMacro_->cell(idx_).metrics(mi, dim);
@@ -119,8 +119,8 @@ public:
                        def_.metrics(mi, dim);
 
                mathMacro_->macro()->lock();
-               if (mi.macro_nesting == 0)
-                       mi.macro_nesting = 1;
+               if (mi.base.macro_nesting == 0)
+                       mi.base.macro_nesting = 1;
        }
        // write(), normalize(), infoize() and infoize2() are not needed since
        // MathMacro uses the definition and not the expanded cells.
@@ -138,6 +138,10 @@ public:
        void octave(OctaveStream & os) const { os << mathMacro_->cell(idx_); }
        ///
        void draw(PainterInfo & pi, int x, int y) const {
+               LATTEST(pi.base.macro_nesting > 0);
+               if (pi.base.macro_nesting == 1)
+                       pi.base.macro_nesting = 0;
+
                if (mathMacro_->editMetrics(pi.base.bv)) {
                        // The only way a ArgumentProxy can appear is in a cell 
of the
                        // MathMacro. Moreover the cells are only drawn in the 
DISPLAY_FOLDED
@@ -155,6 +159,9 @@ public:
                        def_.draw(pi, x, y);
                } else
                        mathMacro_->cell(idx_).draw(pi, x, y);
+
+               if (pi.base.macro_nesting == 0)
+                       pi.base.macro_nesting = 1;
        }
        ///
        size_t idx() const { return idx_; }
@@ -324,7 +331,7 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & 
mi) const
        e_beg.macro = this;
        mrow.push_back(e_beg);
 
-       ++mi.macro_nesting;
+       ++mi.base.macro_nesting;
 
        d->macro_->lock();
        bool has_contents = d->expanded_.addToMathRow(mrow, mi);
@@ -332,14 +339,14 @@ bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo 
& mi) const
 
        // if there was no contents and the array is editable, then we
        // insert a grey box instead.
-       if (!has_contents && mi.macro_nesting == 1) {
+       if (!has_contents && mi.base.macro_nesting == 1) {
                MathRow::Element e(MathRow::BOX, mi);
                e.color = Color_mathmacroblend;
                mrow.push_back(e);
                has_contents = true;
        }
 
-       --mi.macro_nesting;
+       --mi.base.macro_nesting;
 
        MathRow::Element e_end(MathRow::END_MACRO, mi);
        e_end.macro = this;
@@ -442,7 +449,7 @@ bool MathMacro::editMetrics(BufferView const * bv) const
 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        // the macro contents is not editable (except the arguments)
-       ++mi.macro_nesting;
+       ++mi.base.macro_nesting;
 
        // set edit mode for which we will have calculated metrics. But only
        d->editing_[mi.base.bv] = editMode(mi.base.bv);
@@ -457,7 +464,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) 
const
                dim.wid += bsdim.width() + 1;
                dim.asc = max(bsdim.ascent(), dim.ascent());
                dim.des = max(bsdim.descent(), dim.descent());
-               metricsMarkers(dim);
+               metricsMarkers(mi, dim);
        } else if (lyxrc.macro_edit_style == LyXRC::MACRO_EDIT_LIST
                   && d->editing_[mi.base.bv]) {
                // Macro will be edited in a old-style list mode here:
@@ -497,7 +504,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) 
const
                dim.asc += 1;
                dim.des += 1;
                dim.wid += 2;
-               metricsMarkers2(dim);
+               metricsMarkers2(mi, dim);
        } else {
                LBUFERR(d->macro_);
 
@@ -534,7 +541,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) 
const
        }
 
        // restore macro nesting
-       --mi.macro_nesting;
+       --mi.base.macro_nesting;
 }
 
 
@@ -703,6 +710,9 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                                  dim.height() - 2, Color_mathmacroframe);
                drawMarkers2(pi, expx, expy);
        } else {
+               // the macro contents is not editable (except the arguments)
+               ++pi.base.macro_nesting;
+
                bool drawBox = lyxrc.macro_edit_style == 
LyXRC::MACRO_EDIT_INLINE_BOX;
                bool upshape = currentMode() == TEXT_MODE;
                Changer dummy = pi.base.font.changeShape(upshape ? UP_SHAPE
@@ -737,8 +747,11 @@ void MathMacro::draw(PainterInfo & pi, int x, int y) const
                } else
                        d->expanded_.draw(pi, expx, expy);
 
+               --pi.base.macro_nesting;
+
                if (!drawBox)
                        drawMarkers(pi, x, y);
+
        }
 
        // edit mode changed?
diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp
index cf74272..b4d1c1c 100644
--- a/src/mathed/MathMacroTemplate.cpp
+++ b/src/mathed/MathMacroTemplate.cpp
@@ -269,7 +269,7 @@ Inset * InsetMathWrapper::clone() const
 void InsetMathWrapper::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        value_->metrics(mi, dim);
-       //metricsMarkers2(dim);
+       //metricsMarkers2(mi, dim);
 }
 
 
diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp
index 8b9378b..3dbfda6 100644
--- a/src/mathed/MathRow.cpp
+++ b/src/mathed/MathRow.cpp
@@ -37,7 +37,7 @@ namespace lyx {
 
 
 MathRow::Element::Element(Type t, MetricsInfo &mi)
-       : type(t), macro_nesting(mi.macro_nesting),
+       : type(t), macro_nesting(mi.base.macro_nesting),
          inset(0), mclass(MC_ORD), before(0), after(0), compl_unique_to(0),
          macro(0), color(Color_red)
 {}
@@ -130,7 +130,7 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) 
const
        CoordCache & coords = mi.base.bv->coordCache();
        for (Element const & e : elements_) {
                Dimension d;
-               mi.macro_nesting = e.macro_nesting;
+               mi.base.macro_nesting = e.macro_nesting;
                switch (e.type) {
                case BEGIN:
                case END:
@@ -195,6 +195,7 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) 
const
 {
        CoordCache & coords = pi.base.bv->coordCache();
        for (Element const & e : elements_) {
+               pi.base.macro_nesting = e.macro_nesting;
                switch (e.type) {
                case INSET: {
                        // This is hackish: the math inset does not know that 
space

commit f3f9b083d180412a62a50bdef06ab236dca5fc9d
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Wed Oct 5 00:25:38 2016 +0200

    Only display a blue rectangle for editable empty insets
    
    Empty insets should use a minimal amount of space, especially when
    they are part of a built-in macro in lib/symbols.
    
    With this change, blue rectangles signal actually editable places.
    Empty macros in editable data are shown as grey boxes, but they do not
    appear when further nested.
    
    This is done by adding a new type BOX of MathRow::Element object and a
    MetricsInfo::macro_nesting that keeps track of macros (and is reset to
    0 in editable macro arguments).

diff --git a/src/Dimension.h b/src/Dimension.h
index bd8f10d..0607be6 100644
--- a/src/Dimension.h
+++ b/src/Dimension.h
@@ -32,6 +32,8 @@ public:
        void operator+=(Dimension const & dim);
        /// set to empty box
        void clear() { wid = asc = des = 0; }
+       /// check if box is empty
+       bool empty() const { return wid == 0 && asc == 0 && wid == 0; }
        /// get height
        int height() const { return asc + des; }
        /// get ascent
diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index ea3bf02..02bbab3 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -88,7 +88,7 @@ Changer MetricsBase::changeFontSet(string const & name, bool 
cond)
 
 MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
                          MacroContext const & mc)
-       : base(bv, font, textwidth), macrocontext(mc)
+       : base(bv, font, textwidth), macro_nesting(0), macrocontext(mc)
 {}
 
 
diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h
index d2dd8b7..415fe25 100644
--- a/src/MetricsInfo.h
+++ b/src/MetricsInfo.h
@@ -101,6 +101,8 @@ public:
 
        ///
        MetricsBase base;
+       /// count wether the current mathdata is nested in macro(s)
+       int macro_nesting;
        /// The context to resolve macros
        MacroContext const & macrocontext;
 };
diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp
index a8642c1..d2182a5 100644
--- a/src/mathed/InsetMath.cpp
+++ b/src/mathed/InsetMath.cpp
@@ -56,9 +56,9 @@ MathClass InsetMath::mathClass() const
 }
 
 
-bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo const &) const
+bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
 {
-       MathRow::Element e;
+       MathRow::Element e(MathRow::INSET, mi);
        e.inset = this;
        e.mclass = mathClass();
        mrow.push_back(e);
diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h
index 3949010..f8e70c7 100644
--- a/src/mathed/InsetMath.h
+++ b/src/mathed/InsetMath.h
@@ -167,7 +167,7 @@ public:
        /// The class of the math object (used primarily for spacing)
        virtual MathClass mathClass() const;
        /// Add this inset to a math row. Return true if contents got added
-       virtual bool addToMathRow(MathRow &, MetricsInfo const & mi) const;
+       virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
 
        /// identifies things that can get scripts
        virtual bool isScriptable() const { return false; }
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index 8b7a89d..f2100af 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -31,7 +31,6 @@
 #include "mathed/InsetMathUnknown.h"
 
 #include "frontends/FontMetrics.h"
-#include "frontends/Painter.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -217,7 +216,7 @@ void MathData::touch() const
 }
 
 
-bool MathData::addToMathRow(MathRow & mrow, MetricsInfo const & mi) const
+bool MathData::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
 {
        bool has_contents = false;
        BufferView * bv = mi.base.bv;
@@ -275,12 +274,6 @@ void MathData::metrics(MetricsInfo & mi, Dimension & dim) 
const
        slevel_ = (4 * xascent) / 5;
        sshift_ = xascent / 4;
 
-       if (empty()) {
-               // Cache the dimension.
-               mi.base.bv->coordCache().arrays().add(this, dim);
-               return;
-       }
-
        MathRow mrow(mi, this);
        mrow_cache_[mi.base.bv] = mrow;
        mrow.metrics(mi, dim);
@@ -299,11 +292,6 @@ void MathData::draw(PainterInfo & pi, int const x, int 
const y) const
 
        Dimension const & dim = bv.coordCache().getArrays().dim(this);
 
-       if (empty()) {
-               pi.pain.rectangle(x, y - dim.ascent(), dim.width(), 
dim.height(), Color_mathline);
-               return;
-       }
-
        // don't draw outside the workarea
        if (y + dim.descent() <= 0
                || y - dim.ascent() >= bv.workHeight()
diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h
index fa82ee9..9eae466 100644
--- a/src/mathed/MathData.h
+++ b/src/mathed/MathData.h
@@ -122,7 +122,7 @@ public:
        MathAtom const & operator[](pos_type) const;
 
        /// Add this array to a math row. Return true if contents got added
-       bool addToMathRow(MathRow &, MetricsInfo const & mi) const;
+       bool addToMathRow(MathRow &, MetricsInfo & mi) const;
 
        /// rebuild cached metrics information
        void metrics(MetricsInfo & mi, Dimension & dim) const;
diff --git a/src/mathed/MathMacro.cpp b/src/mathed/MathMacro.cpp
index c4401d2..a748821 100644
--- a/src/mathed/MathMacro.cpp
+++ b/src/mathed/MathMacro.cpp
@@ -68,28 +68,49 @@ public:
        ///
        InsetCode lyxCode() const { return ARGUMENT_PROXY_CODE; }
        ///
-       bool addToMathRow(MathRow & mrow, MetricsInfo const & mi) const
+       bool addToMathRow(MathRow & mrow, MetricsInfo & mi) const
        {
-               MathRow::Element e(MathRow::BEG_ARG);
-               e.macro = mathMacro_;
-               e.ar = &mathMacro_->cell(idx_);
-               mrow.push_back(e);
+               // macro arguments are in macros
+               LATTEST(mi.macro_nesting > 0);
+               if (mi.macro_nesting == 1)
+                       mi.macro_nesting = 0;
+
+               MathRow::Element e_beg(MathRow::BEG_ARG, mi);
+               e_beg.macro = mathMacro_;
+               e_beg.ar = &mathMacro_->cell(idx_);
+               mrow.push_back(e_beg);
 
                mathMacro_->macro()->unlock();
-               bool const has_contents = 
mathMacro_->cell(idx_).addToMathRow(mrow, mi);
+               bool has_contents = mathMacro_->cell(idx_).addToMathRow(mrow, 
mi);
                mathMacro_->macro()->lock();
 
-               e.type = MathRow::END_ARG;
-               mrow.push_back(e);
+               // if there was no contents, and the contents is editable,
+               // then we insert a box instead.
+               if (!has_contents && mi.macro_nesting == 0) {
+                       MathRow::Element e(MathRow::BOX, mi);
+                       e.color = Color_mathline;
+                       mrow.push_back(e);
+                       has_contents = true;
+               }
 
-               if (has_contents)
-                       return true;
-               // if there was no contents, then we insert the empty macro 
inset
-               // instead.
-               return InsetMath::addToMathRow(mrow, mi);
+               if (mi.macro_nesting == 0)
+                       mi.macro_nesting = 1;
+
+               MathRow::Element e_end(MathRow::END_ARG, mi);
+               e_end.macro = mathMacro_;
+               e_end.ar = &mathMacro_->cell(idx_);
+
+               mrow.push_back(e_end);
+
+               return has_contents;
        }
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const {
+               // macro arguments are in macros
+               LATTEST(mi.macro_nesting > 0);
+               if (mi.macro_nesting == 1)
+                       mi.macro_nesting = 0;
+
                mathMacro_->macro()->unlock();
                mathMacro_->cell(idx_).metrics(mi, dim);
 
@@ -98,6 +119,8 @@ public:
                        def_.metrics(mi, dim);
 
                mathMacro_->macro()->lock();
+               if (mi.macro_nesting == 0)
+                       mi.macro_nesting = 1;
        }
        // write(), normalize(), infoize() and infoize2() are not needed since
        // MathMacro uses the definition and not the expanded cells.
@@ -287,31 +310,42 @@ MathMacro::~MathMacro()
 }
 
 
-bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo const & mi) const
+bool MathMacro::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
 {
        // set edit mode for which we will have calculated row.
        // This is the same as what is done in metrics().
        d->editing_[mi.base.bv] = editMode(mi.base.bv);
 
-       if (displayMode() == MathMacro::DISPLAY_NORMAL
-           && !d->editing_[mi.base.bv]) {
-               MathRow::Element e(MathRow::BEG_MACRO);
-               e.macro = this;
-               mrow.push_back(e);
+       if (displayMode() != MathMacro::DISPLAY_NORMAL
+           || d->editing_[mi.base.bv])
+               return InsetMath::addToMathRow(mrow, mi);
 
-               d->macro_->lock();
-               bool const has_contents = d->expanded_.addToMathRow(mrow, mi);
-               d->macro_->unlock();
+       MathRow::Element e_beg(MathRow::BEG_MACRO, mi);
+       e_beg.macro = this;
+       mrow.push_back(e_beg);
 
-               e.type = MathRow::END_MACRO;
-               mrow.push_back(e);
+       ++mi.macro_nesting;
 
-               if (has_contents)
-                       return true;
-               // if there was no contents, then we insert the empty macro 
inset
-               // instead.
+       d->macro_->lock();
+       bool has_contents = d->expanded_.addToMathRow(mrow, mi);
+       d->macro_->unlock();
+
+       // if there was no contents and the array is editable, then we
+       // insert a grey box instead.
+       if (!has_contents && mi.macro_nesting == 1) {
+               MathRow::Element e(MathRow::BOX, mi);
+               e.color = Color_mathmacroblend;
+               mrow.push_back(e);
+               has_contents = true;
        }
-       return InsetMath::addToMathRow(mrow, mi);
+
+       --mi.macro_nesting;
+
+       MathRow::Element e_end(MathRow::END_MACRO, mi);
+       e_end.macro = this;
+       mrow.push_back(e_end);
+
+       return has_contents;
 }
 
 
@@ -407,6 +441,9 @@ bool MathMacro::editMetrics(BufferView const * bv) const
 
 void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       // the macro contents is not editable (except the arguments)
+       ++mi.macro_nesting;
+
        // set edit mode for which we will have calculated metrics. But only
        d->editing_[mi.base.bv] = editMode(mi.base.bv);
 
@@ -495,6 +532,9 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) 
const
                        dim.des += 2;
                }
        }
+
+       // restore macro nesting
+       --mi.macro_nesting;
 }
 
 
diff --git a/src/mathed/MathMacro.h b/src/mathed/MathMacro.h
index 9c6fdb1..4eb93ba 100644
--- a/src/mathed/MathMacro.h
+++ b/src/mathed/MathMacro.h
@@ -39,7 +39,7 @@ public:
        ///
        /// If the macro is in normal edit mode, dissolve its contents in
        /// the row. Otherwise, just insert the inset.
-       bool addToMathRow(MathRow &, MetricsInfo const & mi) const;
+       bool addToMathRow(MathRow &, MetricsInfo & mi) const;
        ///
        void draw(PainterInfo & pi, int x, int y) const;
        /// draw selection background
diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp
index 55513bb..8b9378b 100644
--- a/src/mathed/MathRow.cpp
+++ b/src/mathed/MathRow.cpp
@@ -22,6 +22,7 @@
 #include "CoordCache.h"
 #include "MetricsInfo.h"
 
+#include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
 #include "support/debug.h"
@@ -35,26 +36,33 @@ using namespace std;
 namespace lyx {
 
 
-MathRow::Element::Element(Type t, MathClass const mc)
-       : type(t),
-         inset(0), mclass(mc), before(0), after(0), compl_unique_to(0),
-         macro(0)
+MathRow::Element::Element(Type t, MetricsInfo &mi)
+       : type(t), macro_nesting(mi.macro_nesting),
+         inset(0), mclass(MC_ORD), before(0), after(0), compl_unique_to(0),
+         macro(0), color(Color_red)
 {}
 
 
-MathRow::MathRow(MetricsInfo const & mi, MathData const * ar)
+MathRow::MathRow(MetricsInfo & mi, MathData const * ar)
 {
-       if (ar->empty())
-               return;
-
        // First there is a dummy element of type "open"
-       push_back(Element(BEGIN, MC_OPEN));
+       push_back(Element(BEGIN, mi));
+       back().mclass = MC_OPEN;
 
        // Then insert the MathData argument
-       ar->addToMathRow(*this, mi);
+       bool const has_contents = ar->addToMathRow(*this, mi);
+
+       // empty arrays are visible when they are editable
+       // we reserve the necessary space anyway (even if nothing gets drawn)
+       if (!has_contents) {
+               Element e(BOX, mi);
+               e.color = Color_mathline;
+               push_back(e);
+       }
 
        // Finally there is a dummy element of type "close"
-       push_back(Element(END, MC_CLOSE));
+       push_back(Element(END, mi));
+       back().mclass = MC_CLOSE;
 
        /* Do spacing only in math mode. This test is a bit clumsy,
         * but it is used in other places for guessing the current mode.
@@ -120,9 +128,9 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) 
const
        map<MathMacro const *, Dimension> dim_macros;
        map<MathData const *, Dimension> dim_arrays;
        CoordCache & coords = mi.base.bv->coordCache();
-
        for (Element const & e : elements_) {
                Dimension d;
+               mi.macro_nesting = e.macro_nesting;
                switch (e.type) {
                case BEGIN:
                case END:
@@ -131,12 +139,6 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) 
const
                        e.inset->metrics(mi, d);
                        d.wid += e.before + e.after;
                        coords.insets().add(e.inset, d);
-                       dim += d;
-                       // Now add the dimension to current macros and 
arguments.
-                       for (auto & dim_macro : dim_macros)
-                               dim_macro.second += d;
-                       for (auto & dim_array : dim_arrays)
-                               dim_array.second += d;
                        break;
                case BEG_MACRO:
                        e.macro->macro()->lock();
@@ -164,6 +166,19 @@ void MathRow::metrics(MetricsInfo & mi, Dimension & dim) 
const
                        coords.arrays().add(e.ar, dim_arrays[e.ar]);
                        dim_arrays.erase(e.ar);
                        break;
+               case BOX:
+                       d = theFontMetrics(mi.base.font).dimension('I');
+                       d.wid += e.before + e.after;
+                       break;
+               }
+
+               if (!d.empty()) {
+                       dim += d;
+                       // Now add the dimension to current macros and 
arguments.
+                       for (auto & dim_macro : dim_macros)
+                               dim_macro.second += d;
+                       for (auto & dim_array : dim_arrays)
+                               dim_array.second += d;
                }
 
                if (e.compl_text.empty())
@@ -180,7 +195,6 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) 
const
 {
        CoordCache & coords = pi.base.bv->coordCache();
        for (Element const & e : elements_) {
-               Dimension d;
                switch (e.type) {
                case INSET: {
                        // This is hackish: the math inset does not know that 
space
@@ -211,6 +225,15 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) 
const
                        if (e.macro->editMetrics(pi.base.bv))
                                pi.pain.enterMonochromeMode(Color_mathbg, 
Color_mathmacroblend);
                        break;
+               case BOX: {
+                       Dimension const d = 
theFontMetrics(pi.base.font).dimension('I');
+                       // the box is not visible in non-editable context 
(except for grey macro boxes).
+                       if (e.macro_nesting == 0 || e.color == 
Color_mathmacroblend)
+                               pi.pain.rectangle(x + e.before, y - d.ascent(),
+                                                                 d.width(), 
d.height(), e.color);
+                       x += d.wid;
+                       break;
+               }
                case BEGIN:
                case END:
                case END_MACRO:
@@ -277,6 +300,9 @@ ostream & operator<<(ostream & os, MathRow::Element const & 
e)
        case MathRow::END_ARG:
                os << ")";
                break;
+       case MathRow::BOX:
+               os << "@";
+               break;
        }
        return os;
 }
diff --git a/src/mathed/MathRow.h b/src/mathed/MathRow.h
index d0260e2..3d31e1c 100644
--- a/src/mathed/MathRow.h
+++ b/src/mathed/MathRow.h
@@ -14,6 +14,8 @@
 
 #include "MathClass.h"
 
+#include "ColorCode.h"
+
 #include "support/docstring.h"
 
 #include <vector>
@@ -51,16 +53,19 @@ public:
                END_ARG, // a macro argument ends here
                BEGIN, // dummy element before row
                END, // dummy element after row
+               BOX // an empty box
        };
 
        // An elements, together with its spacing
        struct Element
        {
                ///
-               Element(Type t = INSET, MathClass const mc = MC_ORD);
+               Element(Type t, MetricsInfo & mi);
 
                /// Classifies the contents of the object
                Type type;
+               /// count wether the current mathdata is nested in macro(s)
+               int macro_nesting;
 
                /// When type is INSET
                /// the math inset
@@ -80,6 +85,9 @@ public:
 
                // type is BEG_ARG, END_ARG
                MathData const * ar;
+
+               // type is BOX
+               ColorCode color;
        };
 
        ///
@@ -105,7 +113,7 @@ public:
 
        // create the math row by unwinding all macros in the MathData and
        // compute the spacings.
-       MathRow(MetricsInfo const & mi, MathData const * ar);
+       MathRow(MetricsInfo & mi, MathData const * ar);
 
        //
        void metrics(MetricsInfo & mi, Dimension & dim) const;

-----------------------------------------------------------------------

Summary of changes:
 src/mathed/MathMacro.cpp |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
Repository for new features

Reply via email to