From 5212beb79f8bcc715f54e0ac42188ffea3665862 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 15 Jul 2019 13:36:28 +0200 Subject: [PATCH] Add support for amsmath's smallmatrix 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 | 2 +- src/MetricsInfo.cpp | 4 +++- src/MetricsInfo.h | 3 ++- src/frontends/qt4/GuiMathMatrix.cpp | 2 ++ src/frontends/qt4/ui/MathMatrixUi.ui | 2 +- src/mathed/InsetMathAMSArray.cpp | 34 ++++++++++++++++++++++------ src/mathed/InsetMathAMSArray.h | 15 +++++++++--- src/mathed/InsetMathNest.cpp | 3 ++- 8 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index b917865152..9b951ce52a 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2602,7 +2602,7 @@ void LyXAction::init() * \li Syntax: math-matrix [] * \li Params: : 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 diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp index 3ec1529ba6..e7bbefbf0d 100644 --- a/src/MetricsInfo.cpp +++ b/src/MetricsInfo.cpp @@ -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(); } diff --git a/src/MetricsInfo.h b/src/MetricsInfo.h index 08efedb9f6..066d87ce3f 100644 --- a/src/MetricsInfo.h +++ b/src/MetricsInfo.h @@ -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(); /// diff --git a/src/frontends/qt4/GuiMathMatrix.cpp b/src/frontends/qt4/GuiMathMatrix.cpp index 3a9768b094..b7719319d8 100644 --- a/src/frontends/qt4/GuiMathMatrix.cpp +++ b/src/frontends/qt4/GuiMathMatrix.cpp @@ -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"), "" }; diff --git a/src/frontends/qt4/ui/MathMatrixUi.ui b/src/frontends/qt4/ui/MathMatrixUi.ui index f495680fb5..8da4fd9888 100644 --- a/src/frontends/qt4/ui/MathMatrixUi.ui +++ b/src/frontends/qt4/ui/MathMatrixUi.ui @@ -228,7 +228,7 @@ - Decoration + Appearance true diff --git a/src/mathed/InsetMathAMSArray.cpp b/src/mathed/InsetMathAMSArray.cpp index 9a9a3495bc..6160804186 100644 --- a/src/mathed/InsetMathAMSArray.cpp +++ b/src/mathed/InsetMathAMSArray.cpp @@ -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); } diff --git a/src/mathed/InsetMathAMSArray.h b/src/mathed/InsetMathAMSArray.h index 930a2bef4b..25b81339dc 100644 --- a/src/mathed/InsetMathAMSArray.h +++ b/src/mathed/InsetMathAMSArray.h @@ -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_; }; diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 67793e7e51..896ca664c2 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -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( -- 2.39.5