]> git.lyx.org Git - features.git/commitdiff
improve end-of-line handling in the presence of optional args to \\
authorAndré Pönitz <poenitz@gmx.net>
Fri, 10 Aug 2001 10:39:56 +0000 (10:39 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 10 Aug 2001 10:39:56 +0000 (10:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2477 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_gridinset.C
src/mathed/math_gridinset.h
src/mathed/math_matrixinset.C
src/mathed/math_parser.C

index 33b211b9ff4492bd931d0ee479e00f3e107875b8..95d76d4262468bf88d592b162eb2ebdde5cdf6f3 100644 (file)
@@ -206,17 +206,37 @@ void MathGridInset::draw(Painter & pain, int x, int y) const
 void MathGridInset::write(std::ostream & os, bool fragile) const
 {
        for (int row = 0; row < nrows(); ++row) {
-               if (row)
-                       os << " \\\\\n";
                for (int col = 0; col < ncols(); ++col) {
-                       if (col)
-                               os << " & ";
                        cell(index(row, col)).write(os, fragile);
+                       os << eocString(row);
                }
+               os << eolString(row);
        }
 }
 
 
+string MathGridInset::eolString(int row) const
+{
+       if (row == nrows() - 1) 
+               return "";
+
+       // make sure an upcoming '[' does not break anything
+       MathArray const & c = cell(index(row + 1, 0));
+       if (c.size() && (*c.begin())->getChar() == '[')
+               return "\\\\[0pt]\n";
+
+       return "\\\\\n";
+}
+
+
+string MathGridInset::eocString(int col) const
+{
+       if (col == ncols() - 1)
+               return "";
+       return " & ";
+}
+
+
 void MathGridInset::addRow(int row)
 {
        rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
index 101d506fc3cf8618f4e37afa20ea31b01e75ee06..45356556a6d141893918bff17bbea11ef45223d5 100644 (file)
@@ -125,6 +125,11 @@ public:
        std::vector<int> idxBetween(int from, int to) const;
 
 protected:
+       /// returns proper 'end of line' code for LaTeX
+       string eolString(int row) const;
+       /// returns proper 'end of column' code for LaTeX
+       string eocString(int col) const;
+
        /// row info
        std::vector<RowInfo> rowinfo_;
        /// column info
index c521e819b06731b889f326dac0b1e1be75f9f29a..30b38627c6e7393a4e4eb1a4826a46777f3e96eb 100644 (file)
@@ -141,11 +141,8 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const
        bool n = numberedType();
 
        for (int row = 0; row < nrows(); ++row) {
-               if (row)
-                       os << " \\\\\n";
                for (int col = 0; col < ncols(); ++col) {
-                       if (col)
-                               os << " & ";
+                       os << eocString(col);
                        cell(index(row, col)).write(os, fragile);
                }
                if (n) {
@@ -154,6 +151,7 @@ void MathMatrixInset::write(std::ostream & os, bool fragile) const
                        if (nonum_[row])
                                os << "\\nonumber ";
                }
+               os << eolString(row);
        }
 
   footer_write(os);
index 37e3d4be9536bf8437bee90f632c45844b549e19..86270f47acf9a39f0c7416c36d3b12f6094b6bde 100644 (file)
@@ -303,7 +303,7 @@ int Parser::yylex()
        
        while (is_.good()) {
                unsigned char c = getuchar();
-               //lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
+               lyxerr << "reading byte: '" << c << "' code: " << lexcode[c] << endl;
                
                if (lexcode[c] == LexNewLine) {
                        ++lineno_; 
@@ -672,6 +672,8 @@ void Parser::parse_into(MathArray & array, unsigned flags)
                        break;
                
                case LM_TK_NEWLINE:
+               {
+                       lexArg('['); // ignore things like  \\[5pt] for a while
                        if (flags & FLAG_NEWLINE) {
                                flags &= ~FLAG_NEWLINE;
                                --plevel;
@@ -680,6 +682,7 @@ void Parser::parse_into(MathArray & array, unsigned flags)
                        lyxerr[Debug::MATHED]
                                << "found newline unexpectedly, array: '" << array << "'\n";
                        break;
+               }
                
                case LM_TK_PROTECT: 
                        break;