]> git.lyx.org Git - features.git/commitdiff
Support all xymatrix arguments
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 31 Oct 2006 19:10:30 +0000 (19:10 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Tue, 31 Oct 2006 19:10:30 +0000 (19:10 +0000)
* src/LaTeXFeatures.C
(LaTeXFeatures::getPackages): Add package xy

* src/mathed/InsetMathXYMatrix.[Ch]
(spacing_): New
(spacing_code_): New
(validate): New, require xy package

* src/mathed/InsetMathXYMatrix.C
(InsetMathXYMatrix::write): write spacing_ and spacing_code_
(InsetMathXYMatrix::infoize): output spacing_ and spacing_code_

* src/mathed/MathFactory.C
(createInsetMath): handle special arguments of xymatrix

* src/mathed/MathParser.C
(Parser::parse1): ditto

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

src/LaTeXFeatures.C
src/mathed/InsetMathXYMatrix.C
src/mathed/InsetMathXYMatrix.h
src/mathed/MathFactory.C
src/mathed/MathParser.C

index 1ad591446f068d74f711cd3b3c49291f76412f7e..09806e090b6ec7b3c4616fc0c12ec3c92fa9f4e3 100644 (file)
@@ -383,6 +383,9 @@ string const LaTeXFeatures::getPackages() const
                packages << "\\usepackage[dot]{bibtopic}\n";
        }
 
+       if (isRequired("xy"))
+               packages << "\\usepackage[all]{xy}\n";
+
        return packages.str();
 }
 
index 03dd13b65443a6d8966e63c8049892cd5fdebb19..679f2712890268e3bf00df60154b3e1139e65703 100644 (file)
@@ -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(MetricsInfo & mi, Dimension & dim) const
 
 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(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()) << ' ';
+       }
        InsetMathGrid::infoize(os);
 }
 
@@ -83,4 +111,11 @@ void InsetMathXYMatrix::maple(MapleStream & os) const
 }
 
 
+void InsetMathXYMatrix::validate(LaTeXFeatures & features) const
+{
+       features.require("xy");
+       InsetMathGrid::validate(features);
+}
+
+
 } // namespace lyx
index 3dfcd9b4ab03cbf1c1e50d53d053bfa6fc141b4c..8cef0b8656fb46401124749c5e32904f7cd5810a 100644 (file)
@@ -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 ac18853eb0eb2d5ab89763eb6154fdfb3bfa405a..fbdf34220d886de6ca1da8b22646afb1408101b2 100644 (file)
@@ -310,8 +310,33 @@ MathAtom createInsetMath(docstring const & s)
                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 eda20fefffdd9a678d852bc87d47f3700b710870..c3a17c2875b72b2bf7d4706754789b307f444fd7 100644 (file)
@@ -1267,7 +1267,10 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
                }
 
                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);
                }