[EMAIL PROTECTED] wrote: > Author: baum > Date: Thu Aug 9 14:47:06 2007 > New Revision: 19373 > > URL: http://www.lyx.org/trac/changeset/19373 > Log: > parse some more column types and separators > > Modified: > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.C > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.h
This enables additional column separators I needed in math arrays, such as @{}. I can put this in trunk and 1.5.x as well if you want, it is safe since the new code gets only executed if somebody creates a file with the new stuff, e.g. by tex2lyx. Georg > Modified: > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.C > URL: > http://www.lyx.org/trac/file/lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.C?rev=19373 > ============================================================================== > --- > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.C > (original) > +++ > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.C > Thu Aug 9 14:47:06 2007 @@ -30,6 +30,7 @@ > #include "insets/mailinset.h" > > #include "support/lstrings.h" > +#include "support/lyxalgo.h" > > #include <sstream> > > @@ -212,6 +213,7 @@ > for (col_type col = 0; col < ncols(); ++col) { > colinfo_[col].align_ = defaultColAlign(col); > colinfo_[col].skip_ = defaultColSpace(col); > + colinfo_[col].special_.clear(); > } > } > > @@ -223,13 +225,68 @@ > char c = *it; > if (c == '|') { > colinfo_[col].lines_++; > + } else if ((c == 'p' || c == 'm' || c == 'b'|| > + c == '!' || c == '@' || c == '>' || c == '<') && > + it + 1 != hh.end() && *(it + 1) == '{') { > + // @{decl.} and p{width} are standard LaTeX, the > + // others are extensions by array.sty > + bool const newcolumn = c == 'p' || c == 'm' || c == 'b'; > + if (newcolumn) { > + // this declares a new column > + if (col >= ncols()) > + // Only intercolumn stuff is allowed > + // in the last dummy column > + break; > + colinfo_[col].align_ = 'l'; > + } else { > + // this is intercolumn stuff > + if (colinfo_[col].special_.empty()) > + // Overtake possible lines > + colinfo_[col].special_ = > string(colinfo_[col].lines_, '|'); > + } > + int brace_open = 0; > + int brace_close = 0; > + while (it != hh.end()) { > + c = *it; > + colinfo_[col].special_ += c; > + if (c == '{') > + ++brace_open; > + else if (c == '}') > + ++brace_close; > + ++it; > + if (brace_open > 0 && brace_open == brace_close) > + break; > + } > + --it; > + if (newcolumn) { > + colinfo_[col].lines_ = lyx::count( > + colinfo_[col].special_.begin(), > + colinfo_[col].special_.end(), '|'); > + lyxerr << "special column separator: `" > + << colinfo_[col].special_ << '\'' > + << endl; > + ++col; > + colinfo_[col].lines_ = 0; > + colinfo_[col].special_.clear(); > + } > } else if (col >= ncols()) { > - // Only '|' is allowed in the last dummy column > + // Only intercolumn stuff is allowed in the last > + // dummy column > break; > } else if (c == 'c' || c == 'l' || c == 'r') { > colinfo_[col].align_ = c; > + if (!colinfo_[col].special_.empty()) { > + colinfo_[col].special_ += c; > + colinfo_[col].lines_ = lyx::count( > + colinfo_[col].special_.begin(), > + colinfo_[col].special_.end(), '|'); > + lyxerr << "special column separator: `" > + << colinfo_[col].special_ << '\'' > + << endl; > + } > ++col; > colinfo_[col].lines_ = 0; > + colinfo_[col].special_.clear(); > } else { > lyxerr << "unknown column separator: '" << c << "'" << endl; > } > @@ -249,7 +306,8 @@ > { > col_type col = 0; > for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) > - if (*it == 'c' || *it == 'l' || *it == 'r') > + if (*it == 'c' || *it == 'l' || *it == 'r'|| > + *it == 'p' || *it == 'm' || *it == 'b') > ++col; > // let's have at least one column, even if we did not recognize its > // alignment > @@ -262,6 +320,12 @@ > void MathGridInset::halign(char h, col_type col) > { > colinfo_[col].align_ = h; > + if (!colinfo_[col].special_.empty()) { > + char & c = colinfo_[col].special_[colinfo_[col].special_.size() > - 1]; > + if (c == 'l' || c == 'c' || c == 'r') > + c = h; > + } > + // FIXME: Change alignment of p, m and b columns, too > } > > > @@ -275,10 +339,15 @@ > { > string res; > for (col_type col = 0; col < ncols(); ++col) { > - res += string(colinfo_[col].lines_, '|'); > - res += colinfo_[col].align_; > - } > - return res + string(colinfo_[ncols()].lines_, '|'); > + if (colinfo_[col].special_.empty()) { > + res += string(colinfo_[col].lines_, '|'); > + res += colinfo_[col].align_; > + } else > + res += colinfo_[col].special_; > + } > + if (colinfo_[ncols()].special_.empty()) > + return res + string(colinfo_[ncols()].lines_, '|'); > + return res + colinfo_[ncols()].special_; > } > > > @@ -1187,14 +1256,34 @@ > swapCol(cur.col()); > cur.pos() = 0; // trick, see above > } > - else if (s == "add-vline-left") > + else if (s == "add-vline-left") { > colinfo_[cur.col()].lines_++; > - else if (s == "add-vline-right") > + if (!colinfo_[cur.col()].special_.empty()) > + colinfo_[cur.col()].special_ += '|'; > + } > + else if (s == "add-vline-right") { > colinfo_[cur.col()+1].lines_++; > - else if (s == "delete-vline-left") > + if (!colinfo_[cur.col()+1].special_.empty()) > + colinfo_[cur.col()+1].special_.insert(0, 1, > '|'); > + } > + else if (s == "delete-vline-left") { > colinfo_[cur.col()].lines_--; > - else if (s == "delete-vline-right") > + string & special = colinfo_[cur.col()].special_; > + if (!special.empty()) { > + string::size_type i = special.rfind('|'); > + BOOST_ASSERT(i != string::npos); > + special.erase(i, 1); > + } > + } > + else if (s == "delete-vline-right") { > colinfo_[cur.col()+1].lines_--; > + string & special = colinfo_[cur.col()+1].special_; > + if (!special.empty()) { > + string::size_type i = special.find('|'); > + BOOST_ASSERT(i != string::npos); > + special.erase(i, 1); > + } > + } > else { > cur.undispatched(); > break; > > Modified: > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.h > URL: > http://www.lyx.org/trac/file/lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.h?rev=19373 > ============================================================================== > --- > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.h > (original) > +++ > lyx-devel/branches/personal/baum/BRANCH_1_4_X_GB/src/mathed/math_gridinset.h > Thu Aug 9 14:47:06 2007 @@ -78,6 +78,11 @@ > unsigned int lines_; > /// additional amount to be skipped when drawing > int skip_; > + /// Special alignment. > + /// This does also contain align_ and lines_ if it is nonempty. > + /// It needs to be in sync with align_ and lines_ because some > + /// code only uses align_ and lines_. > + std::string special_; > }; > > public: