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
This commit is contained in:
Vincent van Ravesteijn 2009-12-13 21:32:08 +00:00
parent 43207c17bc
commit c4701b2256
3 changed files with 71 additions and 35 deletions

View 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);
}

View 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_;
};

View 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));