From c4701b225618a741a1c400862d6063d4e9151e1e Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Sun, 13 Dec 2009 21:32:08 +0000 Subject: [PATCH] Fix bug #6341: Can't set equal spacing in xymatrix. 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 | 76 ++++++++++++++++++++------------ src/mathed/InsetMathXYMatrix.h | 5 ++- src/mathed/MathFactory.cpp | 25 ++++++++--- 3 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/mathed/InsetMathXYMatrix.cpp b/src/mathed/InsetMathXYMatrix.cpp index 39ac88586a..ac6cafaa43 100644 --- a/src/mathed/InsetMathXYMatrix.cpp +++ b/src/mathed/InsetMathXYMatrix.cpp @@ -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); } diff --git a/src/mathed/InsetMathXYMatrix.h b/src/mathed/InsetMathXYMatrix.h index ee20149d30..6d72e8b9e5 100644 --- a/src/mathed/InsetMathXYMatrix.h +++ b/src/mathed/InsetMathXYMatrix.h @@ -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_; }; diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index b1af651497..8cce5f010a 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -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(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)); -- 2.39.2