This patch makes it possible to read and write all \xymatrix commands. 
There is no UI, meaning it is not possible to enter the extended commands 
in mathed other than copying the pure LaTeX from outside of LyX or texted, 
and you cannot see the aditional arguments on screen other than in the 
status line.
I am not sure about the validate() method: Do we consider that as a file 
format change?
José, would this patch be OK?


Georg
Index: src/mathed/InsetMathXYMatrix.C
===================================================================
--- src/mathed/InsetMathXYMatrix.C	(Revision 15627)
+++ src/mathed/InsetMathXYMatrix.C	(Arbeitskopie)
@@ -12,7 +12,6 @@
 
 #include "InsetMathXYMatrix.h"
 #include "MathStream.h"
-#include "MathStream.h"
 
 #include "LaTeXFeatures.h"
 #include "support/std_ostream.h"
@@ -21,8 +20,8 @@
 namespace lyx {
 
 
-InsetMathXYMatrix::InsetMathXYMatrix()
-	: InsetMathGrid(1, 1)
+InsetMathXYMatrix::InsetMathXYMatrix(LyXLength const & s, char c)
+	: InsetMathGrid(1, 1), spacing_(s), spacing_code_(c)
 {}
 
 
@@ -54,7 +53,22 @@ void InsetMathXYMatrix::metrics(MetricsI
 
 void InsetMathXYMatrix::write(WriteStream & os) const
 {
-	os << "\\xymatrix{";
+	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());
+	}
+	os << '{';
 	InsetMathGrid::write(os);
 	os << "}\n";
 }
@@ -63,6 +77,20 @@ void InsetMathXYMatrix::write(WriteStrea
 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()) << ' ';
+	}
 	InsetMathGrid::infoize(os);
 }
 
@@ -83,4 +111,11 @@ void InsetMathXYMatrix::maple(MapleStrea
 }
 
 
+void InsetMathXYMatrix::validate(LaTeXFeatures & features) const
+{
+	features.require("xy");
+	InsetMathGrid::validate(features);
+}
+
+
 } // namespace lyx
Index: src/mathed/InsetMathXYMatrix.h
===================================================================
--- src/mathed/InsetMathXYMatrix.h	(Revision 15627)
+++ src/mathed/InsetMathXYMatrix.h	(Arbeitskopie)
@@ -22,7 +22,7 @@ namespace lyx {
 class InsetMathXYMatrix : public InsetMathGrid {
 public:
 	///
-	InsetMathXYMatrix();
+	InsetMathXYMatrix(LyXLength const & = LyXLength(), char c = '\0');
 	///
 	void metrics(MetricsInfo &, Dimension &) const;
 	///
@@ -42,9 +42,15 @@ public:
 	void normalize(NormalStream &) const;
 	///
 	void maple(MapleStream &) const;
+	///
+	void validate(LaTeXFeatures & features) const;
 private:
 	///
 	virtual std::auto_ptr<InsetBase> doClone() const;
+	/// extra spacing, may be empty
+	LyXLength spacing_;
+	///
+	char spacing_code_;
 };
 
 
Index: src/mathed/MathFactory.C
===================================================================
--- src/mathed/MathFactory.C	(Revision 15627)
+++ src/mathed/MathFactory.C	(Arbeitskopie)
@@ -310,8 +310,33 @@ MathAtom createInsetMath(docstring const
 		return MathAtom(new InsetMathMakebox);
 	if (s == "kern")
 		return MathAtom(new InsetMathKern);
-	if (s == "xymatrix")
-		return MathAtom(new InsetMathXYMatrix);
+	if (s.substr(0, 8) == "xymatrix") {
+		char spacing_code = '\0';
+		LyXLength spacing;
+		size_t const len = s.length();
+		size_t i = 8;
+		if (i < len && s[i] == '@') {
+			++i;
+			if (i < len) {
+				switch (s[i]) {
+				case 'R':
+				case 'C':
+				case 'M':
+				case 'W':
+				case 'H':
+				case 'L':
+					spacing_code = s[i];
+					++i;
+					break;
+				}
+			}
+			if (i < len && s[i] == '=') {
+				++i;
+				spacing = LyXLength(to_ascii(s.substr(i)));
+			}
+		}
+		return MathAtom(new InsetMathXYMatrix(spacing, spacing_code));
+	}
 	if (s == "xrightarrow" || s == "xleftarrow")
 		return MathAtom(new InsetMathXArrow(s));
 	if (s == "split" || s == "gathered" || s == "aligned" || s == "alignedat")
Index: src/mathed/MathParser.C
===================================================================
--- src/mathed/MathParser.C	(Revision 15627)
+++ src/mathed/MathParser.C	(Arbeitskopie)
@@ -1267,7 +1267,10 @@ void Parser::parse1(InsetMathGrid & grid
 		}
 
 		else if (t.cs() == "xymatrix") {
-			cell->push_back(createInsetMath(t.cs()));
+			odocstringstream os;
+			while (good() && nextToken().cat() != catBegin)
+				os << getToken().asInput();
+			cell->push_back(createInsetMath(t.cs() + os.str()));
 			parse2(cell->back(), FLAG_ITEM, mode, false);
 		}
 

Reply via email to