]> git.lyx.org Git - features.git/commitdiff
Fix bug #6341: Can't set equal spacing in xymatrix.
authorVincent van Ravesteijn <vfr@lyx.org>
Sun, 13 Dec 2009 21:32:08 +0000 (21:32 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sun, 13 Dec 2009 21:32:08 +0000 (21:32 +0000)
Now we also 'support' \xymatrix!C (columns), \xymatrix!R (rows), \xymatrix!0 (all equal and ignore entry sizes) and \xymatrix! (all equal).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32518 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/InsetMathXYMatrix.cpp
src/mathed/InsetMathXYMatrix.h
src/mathed/MathFactory.cpp

index 39ac88586ab88dd458957c2e6a70b23b15474147..ac6cafaa43d5b52d4e093b798cb30d42b9ae3e54 100644 (file)
@@ -20,8 +20,9 @@
 namespace lyx {
 
 
-InsetMathXYMatrix::InsetMathXYMatrix(Buffer * buf, Length const & s, char c)
-       : InsetMathGrid(buf, 1, 1), spacing_(s), spacing_code_(c)
+InsetMathXYMatrix::InsetMathXYMatrix(Buffer * buf, Length const & s, char c,
+       bool e) : InsetMathGrid(buf, 1, 1), spacing_(s), spacing_code_(c),
+       equal_spacing_(e)
 {
 }
 
@@ -56,19 +57,29 @@ void InsetMathXYMatrix::write(WriteStream & os) const
 {
        MathEnsurer ensurer(os);
        os << "\\xymatrix";
-       switch (spacing_code_) {
-       case 'R':
-       case 'C':
-       case 'M':
-       case 'W':
-       case 'H':
-       case 'L':
-               os << '@' << spacing_code_ << '='
-                  << from_ascii(spacing_.asLatexString());
-               break;
-       default:
-               if (!spacing_.empty())
-                       os << "@=" << from_ascii(spacing_.asLatexString());
+       if (equal_spacing_) {
+               os << "@!";
+               switch (spacing_code_) {
+               case '0':
+               case 'R':
+               case 'C':
+                       os << spacing_code_;
+               }
+       } else {
+               switch (spacing_code_) {
+               case 'R':
+               case 'C':
+               case 'M':
+               case 'W':
+               case 'H':
+               case 'L':
+                       os << '@' << spacing_code_ << '='
+                          << from_ascii(spacing_.asLatexString());
+                       break;
+               default:
+                       if (!spacing_.empty())
+                               os << "@=" << from_ascii(spacing_.asLatexString());
+               }
        }
        os << '{';
        InsetMathGrid::write(os);
@@ -79,19 +90,28 @@ void InsetMathXYMatrix::write(WriteStream & os) const
 void InsetMathXYMatrix::infoize(odocstream & os) const
 {
        os << "xymatrix ";
-       switch (spacing_code_) {
-       case 'R':
-       case 'C':
-       case 'M':
-       case 'W':
-       case 'H':
-       case 'L':
-               os << spacing_code_ << ' '
-                  << from_ascii(spacing_.asLatexString()) << ' ';
-               break;
-       default:
-               if (!spacing_.empty())
-                       os << from_ascii(spacing_.asLatexString()) << ' ';
+       if (equal_spacing_) {
+               switch (spacing_code_) {
+               case '0':
+               case 'R':
+               case 'C':
+                       os << '!' << spacing_code_ << ' ';
+               }
+       } else {
+               switch (spacing_code_) {
+               case 'R':
+               case 'C':
+               case 'M':
+               case 'W':
+               case 'H':
+               case 'L':
+                       os << spacing_code_ << ' '
+                          << from_ascii(spacing_.asLatexString()) << ' ';
+                       break;
+               default:
+                       if (!spacing_.empty())
+                               os << from_ascii(spacing_.asLatexString()) << ' ';
+               }
        }
        InsetMathGrid::infoize(os);
 }
index ee20149d30d31f29ea61ca2ac8713111698ef685..6d72e8b9e531819a027338f8ed8429104be65515 100644 (file)
@@ -22,7 +22,8 @@ namespace lyx {
 class InsetMathXYMatrix : public InsetMathGrid {
 public:
        ///
-       InsetMathXYMatrix(Buffer * buf, Length const & = Length(), char c = '\0');
+       InsetMathXYMatrix(Buffer * buf, Length const & = Length(), char c = '\0',
+               bool equal_spacing = false);
        ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
@@ -54,6 +55,8 @@ private:
        Length spacing_;
        ///
        char spacing_code_;
+       ///
+       bool equal_spacing_;
 };
 
 
index b1af651497600f3d116a136b87898ae11218b84d..8cce5f010a2a3b4c299798fb9c0c14a103a0e0be 100644 (file)
@@ -374,11 +374,23 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
        if (s.substr(0, 8) == "xymatrix") {
                char spacing_code = '\0';
                Length spacing;
+               bool equal_spacing = false;
                size_t const len = s.length();
                size_t i = 8;
                if (i < len && s[i] == '@') {
                        ++i;
-                       if (i < len) {
+                       if (i < len && s[i] == '!') {
+                               equal_spacing = true;
+                               ++i;
+                               if (i < len) {
+                                       switch (s[i]) {
+                                       case '0':
+                                       case 'R':
+                                       case 'C':
+                                               spacing_code = static_cast<char>(s[i]);
+                                       }
+                               }
+                       } else if (i < len) {
                                switch (s[i]) {
                                case 'R':
                                case 'C':
@@ -390,13 +402,14 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
                                        ++i;
                                        break;
                                }
-                       }
-                       if (i < len && s[i] == '=') {
-                               ++i;
-                               spacing = Length(to_ascii(s.substr(i)));
+                               if (i < len && s[i] == '=') {
+                                       ++i;
+                                       spacing = Length(to_ascii(s.substr(i)));
+                               }
                        }
                }
-               return MathAtom(new InsetMathXYMatrix(buf, spacing, spacing_code));
+               return MathAtom(new InsetMathXYMatrix(buf, spacing, spacing_code,
+                       equal_spacing));
        }
        if (s == "xrightarrow" || s == "xleftarrow")
                return MathAtom(new InsetMathXArrow(buf, s));