]> git.lyx.org Git - features.git/commitdiff
Add support for amsmath's smallmatrix
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 15 Jul 2019 11:36:28 +0000 (13:36 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:36 +0000 (15:48 +0200)
This is a tight matrix in script size that is suitable for using inline.

Patch from our own Martin Vermeer and myself.

src/LyXAction.cpp
src/MetricsInfo.cpp
src/MetricsInfo.h
src/frontends/qt4/GuiMathMatrix.cpp
src/frontends/qt4/ui/MathMatrixUi.ui
src/mathed/InsetMathAMSArray.cpp
src/mathed/InsetMathAMSArray.h
src/mathed/InsetMathNest.cpp

index b91786515255c1aa06af4e9b05b7e52a1a1bfa25..9b951ce52ab8316ee1ff2f309f325b60e08dd765 100644 (file)
@@ -2602,7 +2602,7 @@ void LyXAction::init()
  * \li Syntax: math-matrix <COLS> <ROWS> [<DECORATION>]
  * \li Params: <DECORATION>: Decoration determines the LaTeX name of the matrix
                              that should be created. Possible values include
-                             pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix and
+                             pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix, smallmatrix, and
                              matrix. The default is 'matrix'.
  * \li Sample: math-ams-matrix 3 3 bmatrix
  * \endvar
index 3ec1529ba642827e69424243f59014367c70d67a..e7bbefbf0dbe62beb36b1efcbf967e8027469e17 100644 (file)
@@ -221,8 +221,10 @@ Changer MetricsBase::changeFrac()
 }
 
 
-Changer MetricsBase::changeArray()
+Changer MetricsBase::changeArray(bool small)
 {
+       if (small)
+               return font.changeStyle(SCRIPT_STYLE);
        return (font.style() == DISPLAY_STYLE) ? font.changeStyle(TEXT_STYLE)
                : Changer();
 }
index 08efedb9f651208a3efe7adb1284d734b992637e..066d87ce3f1f5b074b4a328e6d2d7ff673eefa94 100644 (file)
@@ -61,7 +61,8 @@ public:
        // Temporarily change to the style suitable for use in fractions
        Changer changeFrac();
        // Temporarily change to the style suitable for use in arrays
-       Changer changeArray();
+       // or to style suitable for smallmatrix when \c small is true.
+       Changer changeArray(bool small = false);
        // Temporarily change the style to (script)script style
        Changer changeScript();
        ///
index 3a9768b0943bd4491baa21a3b27b9fa63971deb8..b7719319d8be44d59a6e2538761e3329a1727931 100644 (file)
@@ -36,6 +36,7 @@ static char const * const DecoChars[] = {
        N_("{x}"),
        N_("|x|"),
        N_("||x||"),
+       N_("small"),
        ""
 };
 
@@ -45,6 +46,7 @@ static char const * const DecoNames[] = {
        N_("Bmatrix"),
        N_("vmatrix"),
        N_("Vmatrix"),
+       N_("smallmatrix"),
        ""
 };
 
index f495680fb5ebeb45bec0b0fdc67623994b26ecfe..8da4fd9888ee27f8cac99f53cc7c1a9ffd570da6 100644 (file)
    <item row="3" column="2">
     <widget class="QGroupBox" name="decorationtGB">
      <property name="title">
-      <string>Decoration</string>
+      <string>Appearance</string>
      </property>
      <property name="flat">
       <bool>true</bool>
index 9a9a3495bc7434392afc1e41aa5e6d2c5519106c..61608041867202287dab071026bf6940d70b7dbe 100644 (file)
@@ -83,10 +83,28 @@ char const * InsetMathAMSArray::name_right() const
 }
 
 
+int InsetMathAMSArray::rowsep() const
+{
+       return small() ? 0 : InsetMathGrid::rowsep();
+}
+
+
+int InsetMathAMSArray::colsep() const
+{
+       return small() ? InsetMathGrid::colsep() / 2 : InsetMathGrid::colsep();
+}
+
+
+int InsetMathAMSArray::border() const
+{
+       return small() ? 0 : InsetMathGrid::border();
+}
+
+
 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        Changer dummy2 = mi.base.changeEnsureMath();
-       Changer dummy = mi.base.changeArray();
+       Changer dummy = mi.base.changeArray(small());
        InsetMathGrid::metrics(mi, dim);
 }
 
@@ -94,12 +112,14 @@ void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
 {
        Changer dummy2 = pi.base.changeEnsureMath();
-       Dimension const dim = dimension(*pi.base.bv);
-       int const yy = y - dim.ascent();
-       // Drawing the deco after changeStyle does not work
-       mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
-       mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
-       Changer dummy = pi.base.changeArray();
+       if (name_ != "smallmatrix") {
+               Dimension const dim = dimension(*pi.base.bv);
+               int const yy = y - dim.ascent();
+               // Drawing the deco after changeStyle does not work
+               mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
+               mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right()));
+       }
+       Changer dummy = pi.base.changeArray(small());
        InsetMathGrid::draw(pi, x, y);
 }
 
index 930a2bef4ba5a0166531fdfd5f6002067a234772..25b81339dc650a85e20c5eee1901dbca786818eb 100644 (file)
@@ -23,7 +23,14 @@ public:
        ///
        InsetMathAMSArray(Buffer * buf, docstring const &, int m, int n);
        ///
-       InsetMathAMSArray(Buffer * buf, docstring const &);
+       InsetMathAMSArray(Buffer * buf, docstring const &);     ///
+
+       ///
+       int rowsep() const;
+       ///
+       int colsep() const;
+       ///
+       int border() const;
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
@@ -55,15 +62,17 @@ public:
        ///
        char const * name_right() const;
        ///
-       int leftMargin() const { return 6; } //override
+       int leftMargin() const { return small() ? 3 : 6; } //override
        ///
-       int rightMargin() const { return 8; } //override
+       int rightMargin() const { return small() ? 3: 6; } //override
        ///
        bool handlesMulticolumn() const { return true; } //override
 
 private:
        virtual Inset * clone() const;
        ///
+       bool small() const { return name_ == "smallmatrix"; }
+       ///
        docstring name_;
 };
 
index 67793e7e512e7184872162188cacceee196493ce..896ca664c29cde0d2067a974637c1a29093e1f5a 100644 (file)
@@ -1091,7 +1091,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                // check if we have a valid decoration
                if (name != "pmatrix" && name != "bmatrix"
                        && name != "Bmatrix" && name != "vmatrix"
-                       && name != "Vmatrix" && name != "matrix")
+                       && name != "Vmatrix" && name != "matrix"
+                       && name != "smallmatrix")
                        name = from_ascii("matrix");
 
                cur.niceInsert(