]> 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)
committerRichard Heck <rgheck@lyx.org>
Sat, 28 May 2016 21:42:31 +0000 (17:42 -0400)
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 12e871aa5c1256eb308afd99420ccd65d073b415..2ee5ece9f44fd9b00049d4d921210b4b9fe5e7f6 100644 (file)
@@ -1827,4 +1827,29 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
+// static
+char InsetMathGrid::colAlign(HullType type, col_type col)
+{
+       switch (type) {
+       case hullEqnArray:
+               return "rcl"[col % 3];
+
+       case hullMultline:
+       case hullGather:
+               return 'c';
+
+       case hullAlign:
+       case hullAlignAt:
+       case hullXAlignAt:
+       case hullXXAlignAt:
+       case hullFlAlign:
+               return "rl"[col & 1];
+
+       default:
+               return 'c';
+       }
+}
+
+
+
 } // namespace lyx
index bd3066db0b2e85b662925eff3c00af65d6987ab3..709f492b379b602a1f8197cd50978d582ea30f2b 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.
        /// 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 
+       static char colAlign(HullType type, col_type col);
 
        /// row info.
        /// rowinfo_[nrows()] is a dummy row used only for hlines.
index a782751b1048bc9c99e4203cb41c4f857e2a6578..9a5864f314a0b0bc43e3cf01d147b3712afe474e 100644 (file)
@@ -349,28 +349,38 @@ bool InsetMathHull::idxLast(Cursor & cur) const
 }
 
 
+// FIXME: InsetMathGrid should be changed to let the real column alignment be
+// given by a virtual method like displayColAlign, because the values produced
+// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect
+// that for the moment the values produced by defaultColAlign are not used,
+// notably because alignment is not implemented in the LyXHTML output.
 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);
 }
 
 
 char InsetMathHull::displayColAlign(idx_type idx) const
 {
-       if (type_ == hullMultline) {
+       switch (type_) {
+       case hullMultline: {
                row_type const r = row(idx);
                if (r == 0)
                        return 'l';
                if (r == nrows() - 1)
                        return 'r';
+               return 'c';
+       }
+       case hullEqnArray:
+       case hullGather:
+       case hullAlign:
+       case hullAlignAt:
+       case hullXAlignAt:
+       case hullXXAlignAt:
+       case hullFlAlign:
+               return colAlign(type_, col(idx));
+       default:
+               break;
        }
        return InsetMathGrid::displayColAlign(idx);
 }
index 2adb84522b40392ec63b6257572a0df1ee59419c..5929e273030d69c4689a9a195d0afd0788f585d3 100644 (file)
@@ -48,20 +48,45 @@ Inset * InsetMathSplit::clone() const
 }
 
 
+// FIXME: InsetMathGrid should be changed to let the real column alignment be
+// given by a virtual method like displayColAlign, because the values produced
+// by defaultColAlign can be invalidated by lfuns such as add-column. I suspect
+// that for the moment the values produced by defaultColAlign are not used,
+// notably because alignment is not implemented in the LyXHTML output.
 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")
+               return 'l';
+       if (name_ == "rgathered")
+               return 'r';
+       if (name_ == "split"
+           || name_ == "aligned"
+           || name_ == "align"
+           || name_ == "alignedat")
+               return colAlign(hullAlign, col);
        return 'l';
 }
 
 
+char InsetMathSplit::displayColAlign(idx_type idx) const
+{
+       if (name_ == "gathered")
+               return 'c';
+       if (name_ == "lgathered")
+               return 'l';
+       if (name_ == "rgathered")
+               return 'r';
+       if (name_ == "split"
+           || name_ == "aligned"
+           || name_ == "align"
+           || name_ == "alignedat")
+               return colAlign(hullAlign, col(idx));
+       return InsetMathGrid::displayColAlign(idx);
+}
+
+
 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
 {
        InsetMathGrid::draw(pi, x, y);
@@ -82,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") {
+                       flag.setEnabled(false);
+                       return true;
+               }
                break;
        }
        default:
index b0ff437f3ddcc5a2920f24f718024eca9062447a..1b2aa239e4b55bb1b65902bab9b394dc24e88c89 100644 (file)
@@ -43,6 +43,8 @@ public:
        ///
        char defaultColAlign(col_type);
        ///
+       char displayColAlign(idx_type idx) const;
+       ///
        InsetCode lyxCode() const { return MATH_SPLIT_CODE; }
 
 private: