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.
This commit is contained in:
Jean-Marc Lasgouttes 2019-07-15 13:36:28 +02:00
parent 3c716cc300
commit 732395ef1e
8 changed files with 50 additions and 15 deletions

View File

@ -2602,7 +2602,7 @@ void LyXAction::init()
* \li Syntax: math-matrix <COLS> <ROWS> [<DECORATION>] * \li Syntax: math-matrix <COLS> <ROWS> [<DECORATION>]
* \li Params: <DECORATION>: Decoration determines the LaTeX name of the matrix * \li Params: <DECORATION>: Decoration determines the LaTeX name of the matrix
that should be created. Possible values include 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'. matrix. The default is 'matrix'.
* \li Sample: math-ams-matrix 3 3 bmatrix * \li Sample: math-ams-matrix 3 3 bmatrix
* \endvar * \endvar

View 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) return (font.style() == DISPLAY_STYLE) ? font.changeStyle(TEXT_STYLE)
: Changer(); : Changer();
} }

View File

@ -61,7 +61,8 @@ public:
// Temporarily change to the style suitable for use in fractions // Temporarily change to the style suitable for use in fractions
Changer changeFrac(); Changer changeFrac();
// Temporarily change to the style suitable for use in arrays // 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 // Temporarily change the style to (script)script style
Changer changeScript(); Changer changeScript();
/// ///

View File

@ -36,6 +36,7 @@ static char const * const DecoChars[] = {
N_("{x}"), N_("{x}"),
N_("|x|"), N_("|x|"),
N_("||x||"), N_("||x||"),
N_("small"),
"" ""
}; };
@ -45,6 +46,7 @@ static char const * const DecoNames[] = {
N_("Bmatrix"), N_("Bmatrix"),
N_("vmatrix"), N_("vmatrix"),
N_("Vmatrix"), N_("Vmatrix"),
N_("smallmatrix"),
"" ""
}; };

View File

@ -228,7 +228,7 @@
<item row="3" column="2"> <item row="3" column="2">
<widget class="QGroupBox" name="decorationtGB"> <widget class="QGroupBox" name="decorationtGB">
<property name="title"> <property name="title">
<string>Decoration</string> <string>Appearance</string>
</property> </property>
<property name="flat"> <property name="flat">
<bool>true</bool> <bool>true</bool>

View 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 void InsetMathAMSArray::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
Changer dummy2 = mi.base.changeEnsureMath(); Changer dummy2 = mi.base.changeEnsureMath();
Changer dummy = mi.base.changeArray(); Changer dummy = mi.base.changeArray(small());
InsetMathGrid::metrics(mi, dim); 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 void InsetMathAMSArray::draw(PainterInfo & pi, int x, int y) const
{ {
Changer dummy2 = pi.base.changeEnsureMath(); Changer dummy2 = pi.base.changeEnsureMath();
Dimension const dim = dimension(*pi.base.bv); if (name_ != "smallmatrix") {
int const yy = y - dim.ascent(); Dimension const dim = dimension(*pi.base.bv);
// Drawing the deco after changeStyle does not work int const yy = y - dim.ascent();
mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left())); // Drawing the deco after changeStyle does not work
mathed_draw_deco(pi, x + dim.width() - 8, yy, 5, dim.height(), from_ascii(name_right())); mathed_draw_deco(pi, x + 1, yy, 5, dim.height(), from_ascii(name_left()));
Changer dummy = pi.base.changeArray(); 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); InsetMathGrid::draw(pi, x, y);
} }

View File

@ -23,7 +23,14 @@ public:
/// ///
InsetMathAMSArray(Buffer * buf, docstring const &, int m, int n); 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; void metrics(MetricsInfo & mi, Dimension & dim) const;
/// ///
@ -55,15 +62,17 @@ public:
/// ///
char const * name_right() const; 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 bool handlesMulticolumn() const { return true; } //override
private: private:
virtual Inset * clone() const; virtual Inset * clone() const;
/// ///
bool small() const { return name_ == "smallmatrix"; }
///
docstring name_; docstring name_;
}; };

View File

@ -1091,7 +1091,8 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
// check if we have a valid decoration // check if we have a valid decoration
if (name != "pmatrix" && name != "bmatrix" if (name != "pmatrix" && name != "bmatrix"
&& name != "Bmatrix" && name != "vmatrix" && name != "Bmatrix" && name != "vmatrix"
&& name != "Vmatrix" && name != "matrix") && name != "Vmatrix" && name != "matrix"
&& name != "smallmatrix")
name = from_ascii("matrix"); name = from_ascii("matrix");
cur.niceInsert( cur.niceInsert(