]> git.lyx.org Git - lyx.git/commitdiff
Display the correct horizontal alignment in AMS environments
authorGuillaume Munch <gm@lyx.org>
Sun, 13 Dec 2015 03:32:32 +0000 (03:32 +0000)
committerUwe Stöhr <uwestoehr@lyx.org>
Tue, 19 Jan 2016 21:22:22 +0000 (22:22 +0100)
A longstanding problem... (related: #1861)

The columns in AMS math environments have a fixed alignment (colAlign() in
InsetMathGrid.cpp). We set this alignment for display (Georg's
displayColAlign()) in InsetMathHull and InsetMathSplit. This is done according
to tests and documentation for the various environments.

There is also some mechanical code factoring via colAlign().

Finally, I disable setting the horizontal alignment in InsetMathSplit, which has
no impact on the LaTeX output, and has no longer any impact on the screen. (As
for vertical alignment I discovered that it was in fact customisable for
\aligned & friends! I hope that the more faithful interface will let other
users discover that too.)

src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathGrid.h
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathSplit.cpp
src/mathed/InsetMathSplit.h

index 536f4bd163a671347d7a15150f7da6c407a1d4bb..00d9a6f20fbf2b2369a976d01edf49a00ef1b9a6 100644 (file)
@@ -1838,4 +1838,29 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+// static\r
+char InsetMathGrid::colAlign(HullType type, col_type col)\r
+{\r
+       switch (type) {\r
+       case hullEqnArray:\r
+               return "rcl"[col % 3];\r
+\r
+       case hullMultline:\r
+       case hullGather:\r
+               return 'c';\r
+\r
+       case hullAlign:\r
+       case hullAlignAt:\r
+       case hullXAlignAt:\r
+       case hullXXAlignAt:\r
+       case hullFlAlign:\r
+               return "rl"[col & 1];\r
+\r
+       default:\r
+               return 'c';\r
+       }\r
+}\r
+\r
+\r
+\r
 } // namespace lyx
index bd3066db0b2e85b662925eff3c00af65d6987ab3..6199b7dafc8fef516acaa7934f8e8298dab0ce79 100644 (file)
@@ -258,10 +258,11 @@ protected:
        virtual docstring eocString(col_type col, col_type lastcol) const;
        /// splits cells and shifts right part to the next cell
        void splitCell(Cursor & cur);
-       /// Column aligmment for display of cell \p idx.
+       /// Column alignment for display of cell \p idx.\r
        /// Must not be written to file!
        virtual char displayColAlign(idx_type idx) const;
-
+       /// The value of a fixed col align for a certain hull type \r
+       static char colAlign(HullType type, col_type col);\r
 
        /// row info.
        /// rowinfo_[nrows()] is a dummy row used only for hlines.
index 097a3445c5f5196b6ba65ecd06de5716d2efeee6..cce029f6cedf25f98b3f3293ac45ea8cb8476974 100644 (file)
@@ -349,28 +349,34 @@ bool InsetMathHull::idxLast(Cursor & cur) const
 }
 
 
+//FIXME: This has probably no effect and can be removed.\r
 char InsetMathHull::defaultColAlign(col_type col)
 {
-       if (type_ == hullEqnArray)
-               return "rcl"[col];
-       if (type_ == hullMultline)
-               return 'c';
-       if (type_ == hullGather)
-               return 'c';
-       if (type_ >= hullAlign)
-               return "rl"[col & 1];
-       return 'c';
+       return colAlign(type_, col);\r
 }
 
 
 char InsetMathHull::displayColAlign(idx_type idx) const
 {
-       if (type_ == hullMultline) {
+       switch (type_) {\r
+       case hullMultline: {\r
                row_type const r = row(idx);
                if (r == 0)
                        return 'l';
                if (r == nrows() - 1)
                        return 'r';
+               return 'c';\r
+       }\r
+       case hullEqnArray:\r
+       case hullGather:\r
+       case hullAlign:\r
+       case hullAlignAt:\r
+       case hullXAlignAt:\r
+       case hullXXAlignAt:\r
+       case hullFlAlign:\r
+               return colAlign(type_, col(idx));\r
+       default:\r
+               break;\r
        }
        return InsetMathGrid::displayColAlign(idx);
 }
@@ -1241,6 +1247,27 @@ void InsetMathHull::setType(HullType type)
 }
 
 
+bool InsetMathHull::isMutable(HullType type)\r
+{\r
+       switch (type) {\r
+       case hullNone:\r
+       case hullSimple:\r
+       case hullEquation:\r
+       case hullEqnArray:\r
+       case hullAlign:\r
+       case hullFlAlign:\r
+       case hullAlignAt:\r
+       case hullXAlignAt:\r
+       case hullXXAlignAt:\r
+       case hullMultline:\r
+       case hullGather:\r
+               return true;\r
+       default:\r
+               return false;\r
+       }\r
+}\r
+\r
+\r
 void InsetMathHull::mutate(HullType newtype)
 {
        //lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << endl;
index 5c425fb00297dc03ee448daa03442a777532b15a..f85e664eefee0647053320b9329cb4c7cf387fe9 100644 (file)
@@ -48,20 +48,41 @@ Inset * InsetMathSplit::clone() const
 }
 
 
+//FIXME: This has probably no effect and can be removed.\r
 char InsetMathSplit::defaultColAlign(col_type col)
 {
-       if (name_ == "split")
-               return 'l';
        if (name_ == "gathered")
                return 'c';
-       if (name_ == "aligned" || name_ == "align")
-               return (col & 1) ? 'l' : 'r';
-       if (name_ == "alignedat")
-               return (col & 1) ? 'l' : 'r';
+       if (name_ == "lgathered")\r
+               return 'l';\r
+       if (name_ == "rgathered")\r
+               return 'r';\r
+       if (name_ == "split"\r
+           || name_ == "aligned"\r
+           || name_ == "align"\r
+           || name_ == "alignedat")\r
+               return colAlign(hullAlign, col);\r
        return 'l';
 }
 
 
+char InsetMathSplit::displayColAlign(idx_type idx) const\r
+{\r
+       if (name_ == "gathered")\r
+               return 'c';\r
+       if (name_ == "lgathered")\r
+               return 'l';\r
+       if (name_ == "rgathered")\r
+               return 'r';\r
+       if (name_ == "split"\r
+           || name_ == "aligned"\r
+           || name_ == "align"\r
+           || name_ == "alignedat")\r
+               return colAlign(hullAlign, col(idx));\r
+       return InsetMathGrid::displayColAlign(idx);\r
+}\r
+\r
+\r
 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
 {
        InsetMathGrid::draw(pi, x, y);
@@ -86,6 +107,10 @@ bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
                        flag.setEnabled(false);
                        return true;
                }
+               if (s == "align-left" || s == "align-center" || s == "align-right") {\r
+                       flag.setEnabled(false);\r
+                       return true;\r
+               }\r
                break;
        }
        default:
index b0ff437f3ddcc5a2920f24f718024eca9062447a..6136b6faf6806aeb62f7020ed3d098d232018afc 100644 (file)
@@ -43,6 +43,8 @@ public:
        ///
        char defaultColAlign(col_type);
        ///
+       char displayColAlign(idx_type idx) const;\r
+       ///\r
        InsetCode lyxCode() const { return MATH_SPLIT_CODE; }
 
 private: