]> git.lyx.org Git - lyx.git/commitdiff
Adding TexRow information on math latex output (#4725)
authorGuillaume Munch <gm@lyx.org>
Wed, 7 Oct 2015 03:13:21 +0000 (04:13 +0100)
committerGuillaume Munch <gm@lyx.org>
Mon, 19 Oct 2015 05:55:17 +0000 (06:55 +0100)
WriteStream is now built from an otexstream instead of an odocstream, and
therefore counts lines in a TexRow. Calls to TexRow are added in relevant places
in math insets.

This finishes adding line tracking for math in the source panel and for forward
search.

20 files changed:
src/Cursor.cpp
src/lyxfind.cpp
src/mathed/InsetMath.cpp
src/mathed/InsetMathAMSArray.cpp
src/mathed/InsetMathArray.cpp
src/mathed/InsetMathCases.cpp
src/mathed/InsetMathDiagram.cpp
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathSplit.cpp
src/mathed/InsetMathSubstack.cpp
src/mathed/InsetMathTabular.cpp
src/mathed/InsetMathXYMatrix.cpp
src/mathed/MacroTable.cpp
src/mathed/MathExtern.cpp
src/mathed/MathMacroTemplate.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h
src/mathed/MathSupport.cpp

index 828b0f56d270e54b768d3093df887b69c76a3d1a..cd796458de12c4f551aea72f5e4d2d4094488082 100644 (file)
@@ -1684,7 +1684,9 @@ void Cursor::normalize()
                        << pos() << ' ' << lastpos() <<  " in idx: " << idx()
                       << " in atom: '";
                odocstringstream os;
-               WriteStream wi(os, false, true, WriteStream::wsDefault);
+               TexRow texrow(false);
+               otexrowstream ots(os,texrow);
+               WriteStream wi(ots, false, true, WriteStream::wsDefault);
                inset().asInsetMath()->write(wi);
                lyxerr << to_utf8(os.str()) << endl;
                pos() = lastpos();
index 85b66d071588639d32e4447c9f0358897e016e04..2f7a0b4901d99d58f2c592f0a5ca750eaae0d605 100644 (file)
@@ -1072,7 +1072,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                for (int s = cur.depth() - 1; s >= 0; --s) {
                        CursorSlice const & cs = cur[s];
                        if (cs.asInsetMath() && cs.asInsetMath()->asHullInset()) {
-                               WriteStream ws(ods);
+                               WriteStream ws(os);
                                cs.asInsetMath()->asHullInset()->header_write(ws);
                                break;
                        }
@@ -1094,7 +1094,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                        CursorSlice const & cs = cur[s];
                        InsetMath * inset = cs.asInsetMath();
                        if (inset && inset->asHullInset()) {
-                               WriteStream ws(ods);
+                               WriteStream ws(os);
                                inset->asHullInset()->footer_write(ws);
                                break;
                        }
index 738f6342c358a3801fb44a4858517a810a2d2082..f71febc06de2a97dc386db267739e903c07dd30b 100644 (file)
@@ -53,7 +53,9 @@ void InsetMath::dump() const
 {
        lyxerr << "---------------------------------------------" << endl;
        odocstringstream os;
-       WriteStream wi(os, false, true, WriteStream::wsDefault);
+       TexRow texrow(false);
+       otexrowstream ots(os,texrow);
+       WriteStream wi(ots, false, true, WriteStream::wsDefault);
        write(wi);
        lyxerr << to_utf8(os.str());
        lyxerr << "\n---------------------------------------------" << endl;
@@ -156,7 +158,9 @@ HullType InsetMath::getType() const
 ostream & operator<<(ostream & os, MathAtom const & at)
 {
        odocstringstream oss;
-       WriteStream wi(oss, false, false, WriteStream::wsDefault);
+       TexRow texrow(false);
+       otexrowstream ots(oss,texrow);
+       WriteStream wi(ots, false, false, WriteStream::wsDefault);
        at->write(wi);
        return os << to_utf8(oss.str());
 }
@@ -164,7 +168,9 @@ ostream & operator<<(ostream & os, MathAtom const & at)
 
 odocstream & operator<<(odocstream & os, MathAtom const & at)
 {
-       WriteStream wi(os, false, false, WriteStream::wsDefault);
+       TexRow texrow(false);
+       otexrowstream ots(os,texrow);
+       WriteStream wi(ots, false, false, WriteStream::wsDefault);
        at->write(wi);
        return os;
 }
index e615e1dff886e7cf2e997d397f73457a5300d91c..12a92da0803176e67ccdfbbd88c446217a1aae47 100644 (file)
@@ -134,8 +134,11 @@ void InsetMathAMSArray::write(WriteStream & os) const
 {
        MathEnsurer ensurer(os);
        os << "\\begin{" << name_ << '}';
+       bool open = os.startOuterRow();
        InsetMathGrid::write(os);
        os << "\\end{" << name_ << '}';
+       if (open)
+               os.startOuterRow();
 }
 
 
index 821f4605e8f119a5fa74210d319ad9e9d06f4887..d5f9164273f93263ec21528b2b4b406bf0468c85 100644 (file)
@@ -103,6 +103,7 @@ void InsetMathArray::write(WriteStream & os) const
        if (os.fragile())
                os << "\\protect";
        os << "\\begin{" << name_ << '}';
+       bool open = os.startOuterRow();
 
        char const v = verticalAlignment();
        if (v == 't' || v == 'b')
@@ -114,6 +115,8 @@ void InsetMathArray::write(WriteStream & os) const
        if (os.fragile())
                os << "\\protect";
        os << "\\end{" << name_ << '}';
+       if (open)
+               os.startOuterRow();
        // adding a \n here is bad if the array is the last item
        // in an \eqnarray...
 }
index d6f7133e2a1c33cbb0bda78ebd55ac1ddb36125c..17b4fb146968aea388ab9023853fd5f5994c6f15 100644 (file)
@@ -132,11 +132,14 @@ void InsetMathCases::write(WriteStream & os) const
        MathEnsurer ensurer(os);
        if (os.fragile())
                os << "\\protect";
+       bool open = os.startOuterRow();
        os << "\\begin{cases}\n";
        InsetMathGrid::write(os);
        if (os.fragile())
                os << "\\protect";
        os << "\\end{cases}";
+       if (open)
+               os.startOuterRow();
 }
 
 
index 25ad63ca5f967096ef80fffa80e4dff595eae3f8..5c8887c76f80a981d0c22aa09c7ab90e8c398aa7 100644 (file)
@@ -56,9 +56,12 @@ void InsetMathDiagram::write(WriteStream & os) const
 {
        MathEnsurer ensurer(os);
        os << "\\Diagram";
+       bool open = os.startOuterRow();
        os << '{';
        InsetMathGrid::write(os);
        os << "}\n";
+       if (open)
+               os.startOuterRow();
 }
 
 
index 781d921b1292738880d5fbb93b71084a6feb2568..8ea3940729ddda53882883d05df44807b7b85992 100644 (file)
@@ -1266,9 +1266,16 @@ void InsetMathGrid::write(WriteStream & os,
                                emptyline = false;
                        }
                }
-               for (col_type col = beg_col; col < lastcol;) {
+               for (col_type col = beg_col; col < end_col;) {
                        int nccols = 1;
                        idx_type const idx = index(row, col);
+                       TexRow::RowEntry entry = os.texrow().mathEntry(id(),idx);
+                       os.texrow().startMath(id(),idx);
+                       if (col >= lastcol) {
+                               ++col;
+                               continue;
+                       }
+                       os.pushRowEntry(entry);
                        if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
                                size_t s = col + 1;
                                while (s < ncols() &&
@@ -1286,6 +1293,7 @@ void InsetMathGrid::write(WriteStream & os,
                                os << '}';
                        os << eocString(col + nccols - 1, lastcol);
                        col += nccols;
+                       os.popRowEntry();
                }
                eol = eolString(row, os.fragile(), os.latex(), last_eoln);
                os << eol;
index 560c9991c88a39c1a3fbfc8b2c7e59901a231433..08c0dec760a0c76ee702dd123d45983eab03a702 100644 (file)
@@ -575,7 +575,9 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
                InsetMathGrid::metricsT(mi, dim);
        } else {
                odocstringstream os;
-               WriteStream wi(os, false, true, WriteStream::wsDefault);
+               TexRow texrow(false);
+               otexrowstream ots(os,texrow);
+               WriteStream wi(ots, false, true, WriteStream::wsDefault);
                write(wi);
                dim.wid = os.str().size();
                dim.asc = 1;
@@ -590,7 +592,9 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
                InsetMathGrid::drawT(pain, x, y);
        } else {
                odocstringstream os;
-               WriteStream wi(os, false, true, WriteStream::wsDefault);
+               TexRow texrow(false);
+               otexrowstream ots(os,texrow);
+               WriteStream wi(ots, false, true, WriteStream::wsDefault);
                write(wi);
                pain.draw(x, y, os.str().c_str());
        }
@@ -608,7 +612,9 @@ static docstring latexString(InsetMathHull const & inset)
        static Encoding const * encoding = 0;
        if (inset.isBufferValid())
                encoding = &(inset.buffer().params().encoding());
-       WriteStream wi(ls, false, true, WriteStream::wsPreview, encoding);
+       TexRow texrow(false);
+       otexrowstream ots(ls,texrow);
+       WriteStream wi(ots, false, true, WriteStream::wsPreview, encoding);
        inset.write(wi);
        return ls.str();
 }
@@ -921,22 +927,25 @@ void InsetMathHull::validate(LaTeXFeatures & features) const
 void InsetMathHull::header_write(WriteStream & os) const
 {
        bool n = numberedType();
-
+       
        switch(type_) {
        case hullNone:
                break;
 
        case hullSimple:
                os << '$';
+               os.startOuterRow();
                if (cell(0).empty())
                        os << ' ';
                break;
 
        case hullEquation:
+               os << "\n";
+               os.startOuterRow();
                if (n)
-                       os << "\n\\begin{equation" << star(n) << "}\n";
+                       os << "\\begin{equation" << star(n) << "}\n";
                else
-                       os << "\n\\[\n";
+                       os << "\\[\n";
                break;
 
        case hullEqnArray:
@@ -944,17 +953,23 @@ void InsetMathHull::header_write(WriteStream & os) const
        case hullFlAlign:
        case hullGather:
        case hullMultline:
-               os << "\n\\begin{" << hullName(type_) << star(n) << "}\n";
+               os << "\n";
+               os.startOuterRow();
+               os << "\\begin{" << hullName(type_) << star(n) << "}\n";
                break;
 
        case hullAlignAt:
        case hullXAlignAt:
-               os << "\n\\begin{" << hullName(type_) << star(n) << '}'
+               os << "\n";
+               os.startOuterRow();
+               os << "\\begin{" << hullName(type_) << star(n) << '}'
                  << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
                break;
 
        case hullXXAlignAt:
-               os << "\n\\begin{" << hullName(type_) << '}'
+               os << "\n";
+               os.startOuterRow();
+               os << "\\begin{" << hullName(type_) << '}'
                  << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
                break;
 
@@ -963,7 +978,9 @@ void InsetMathHull::header_write(WriteStream & os) const
                break;
 
        default:
-               os << "\n\\begin{unknown" << star(n) << "}\n";
+               os << "\n";
+               os.startOuterRow();
+               os << "\\begin{unknown" << star(n) << "}\n";
                break;
        }
 }
@@ -983,10 +1000,12 @@ void InsetMathHull::footer_write(WriteStream & os) const
                break;
 
        case hullEquation:
+               os << "\n";
+               os.startOuterRow();
                if (n)
-                       os << "\n\\end{equation" << star(n) << "}\n";
+                       os << "\\end{equation" << star(n) << "}\n";
                else
-                       os << "\n\\]\n";
+                       os << "\\]\n";
                break;
 
        case hullEqnArray:
@@ -996,11 +1015,15 @@ void InsetMathHull::footer_write(WriteStream & os) const
        case hullXAlignAt:
        case hullGather:
        case hullMultline:
-               os << "\n\\end{" << hullName(type_) << star(n) << "}\n";
+               os << "\n";
+               os.startOuterRow();
+               os << "\\end{" << hullName(type_) << star(n) << "}\n";
                break;
 
        case hullXXAlignAt:
-               os << "\n\\end{" << hullName(type_) << "}\n";
+               os << "\n";
+               os.startOuterRow();
+               os << "\\end{" << hullName(type_) << "}\n";
                break;
 
        case hullRegexp:
@@ -1009,7 +1032,9 @@ void InsetMathHull::footer_write(WriteStream & os) const
                break;
 
        default:
-               os << "\n\\end{unknown" << star(n) << "}\n";
+               os << "\n";
+               os.startOuterRow();
+               os << "\\end{unknown" << star(n) << "}\n";
                break;
        }
 }
@@ -1367,7 +1392,6 @@ docstring InsetMathHull::eolString(row_type row, bool fragile, bool latex,
        return res + InsetMathGrid::eolString(row, fragile, latex, last_eoln);
 }
 
-
 void InsetMathHull::write(WriteStream & os) const
 {
        ModeSpecifier specifier(os, MATH_MODE);
@@ -2004,7 +2028,9 @@ bool InsetMathHull::searchForward(BufferView * bv, string const & str,
 void InsetMathHull::write(ostream & os) const
 {
        odocstringstream oss;
-       WriteStream wi(oss, false, false, WriteStream::wsDefault);
+       TexRow texrow(false);
+       otexrowstream ots(oss,texrow);
+       WriteStream wi(ots, false, false, WriteStream::wsDefault);
        oss << "Formula ";
        write(wi);
        os << to_utf8(oss.str());
@@ -2046,8 +2072,10 @@ int InsetMathHull::plaintext(odocstringstream & os,
        }
 
        odocstringstream oss;
+       TexRow texrow(false);
+       otexrowstream ots(oss,texrow);
        Encoding const * const enc = encodings.fromLyXName("utf8");
-       WriteStream wi(oss, false, true, WriteStream::wsDefault, enc);
+       WriteStream wi(ots, false, true, WriteStream::wsDefault, enc);
 
        // Fix Bug #6139
        if (type_ == hullRegexp)
@@ -2087,12 +2115,14 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
        ++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>';
 
        odocstringstream ls;
+       TexRow texrow;
+       otexstream ols(ls, texrow);
        if (runparams.flavor == OutputParams::XML) {
                ms << MTag("alt role='tex' ");
                // Workaround for db2latex: db2latex always includes equations with
                // \ensuremath{} or \begin{display}\end{display}
                // so we strip LyX' math environment
-               WriteStream wi(ls, false, false, WriteStream::wsDefault, runparams.encoding);
+               WriteStream wi(ols, false, false, WriteStream::wsDefault, runparams.encoding);
                InsetMathGrid::write(wi);
                ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&amp;"), "<", "&lt;"));
                ms << ETag("alt");
@@ -2102,9 +2132,6 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons
                InsetMathGrid::mathmlize(ms);
                ms << ETag("math");
        } else {
-               TexRow texrow;
-               texrow.reset();
-               otexstream ols(ls, texrow);
                ms << MTag("alt role='tex'");
                latex(ols, runparams);
                res = texrow.rows();
@@ -2354,7 +2381,9 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
                // Unfortunately, we cannot use latexString() because we do not want
                // $...$ or whatever.
                odocstringstream ls;
-               WriteStream wi(ls, false, true, WriteStream::wsPreview);
+               TexRow texrow(false);
+               otexrowstream ots(ls,texrow);
+               WriteStream wi(ots, false, true, WriteStream::wsPreview);
                ModeSpecifier specifier(wi, MATH_MODE);
                mathAsLatex(wi);
                docstring const latex = ls.str();
index 94b4d68e581d70f0e72de69ab91131c0048cb388..473457d71ca016bd8568d1f0b43a24faf96e90b8 100644 (file)
@@ -250,7 +250,9 @@ bool InsetMathNest::idxLast(Cursor & cur) const
 void InsetMathNest::dump() const
 {
        odocstringstream oss;
-       WriteStream os(oss);
+       TexRow texrow(false);
+       otexrowstream ots(oss,texrow);
+       WriteStream os(ots);
        os << "---------------------------------------------\n";
        write(os);
        os << "\n";
@@ -376,8 +378,11 @@ void InsetMathNest::write(WriteStream & os) const
        ModeSpecifier specifier(os, currentMode(), lockedMode());
        docstring const latex_name = name();
        os << '\\' << latex_name;
-       for (size_t i = 0; i < nargs(); ++i)
+       for (size_t i = 0; i < nargs(); ++i) {
+               os.pushRowEntry(TexRow::mathEntry(id(),i));
                os << '{' << cell(i) << '}';
+               os.popRowEntry();
+       }
        if (nargs() == 0)
                os.pendingSpace(true);
        if (lock_ && !os.latex()) {
@@ -398,22 +403,20 @@ void InsetMathNest::normalize(NormalStream & os) const
 
 void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const
 {
-       WriteStream wi(os.os(), runparams.moving_arg, true,
-                      runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault,
-                      runparams.encoding);
+       WriteStream wi(os, runparams.moving_arg, true,
+                       runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault,
+                       runparams.encoding);
        wi.canBreakLine(os.canBreakLine());
-       write(wi);
+       if (runparams.lastid != -1) {
+               wi.pushRowEntry(os.texrow().textEntry(runparams.lastid,
+                                                                                         runparams.lastpos));
+               write(wi);
+               wi.popRowEntry();
+       } else
+               write(wi);
        // Reset parbreak status after a math inset.
        os.lastChar(0);
        os.canBreakLine(wi.canBreakLine());
-
-       int lf = wi.line();
-       if (lf > 0 && runparams.lastid != -1) {
-               --lf;
-               os.texrow().newline();
-               os.texrow().start(runparams.lastid, runparams.lastpos);
-       }
-       os.texrow().newlines(lf);
 }
 
 
index de4ddc03202f9b5bd86b4d1676494ad15a971419..5c425fb00297dc03ee448daa03442a777532b15a 100644 (file)
@@ -104,6 +104,7 @@ void InsetMathSplit::write(WriteStream & ws) const
        if (!numbered_ && name_ == "align")
                suffix = from_ascii("*");
        ws << "\\begin{" << name_ << suffix << '}';
+       bool open = ws.startOuterRow();
        if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
                ws << '[' << verticalAlignment() << ']';
        if (name_ == "alignedat")
@@ -112,6 +113,8 @@ void InsetMathSplit::write(WriteStream & ws) const
        if (ws.fragile())
                ws << "\\protect";
        ws << "\\end{" << name_ << suffix << "}\n";
+       if (open)
+               ws.startOuterRow();
 }
 
 
index d38513738e18259d9e3c5b45e69d408716882844..7810ff479e9065a92d58f6cd588d1172639358aa 100644 (file)
@@ -107,8 +107,11 @@ void InsetMathSubstack::write(WriteStream & os) const
 {
        MathEnsurer ensurer(os);
        os << "\\substack{";
+       bool open = os.startOuterRow();
        InsetMathGrid::write(os);
        os << "}\n";
+       if (open)
+               os.startOuterRow();
 }
 
 
index 083b0e5ef52d99b4d6bd59886ed5f0ed53edea4a..2c814a38c6511ecf654ef5c693dd008dbeca9d29 100644 (file)
@@ -71,6 +71,7 @@ void InsetMathTabular::write(WriteStream & os) const
        if (os.fragile())
                os << "\\protect";
        os << "\\begin{" << name_ << '}';
+       bool open = os.startOuterRow();
 
        char const v = verticalAlignment();
        if (v == 't' || v == 'b')
@@ -82,6 +83,8 @@ void InsetMathTabular::write(WriteStream & os) const
        if (os.fragile())
                os << "\\protect";
        os << "\\end{" << name_ << '}';
+       if (open)
+               os.startOuterRow();
        // adding a \n here is bad if the tabular is the last item
        // in an \eqnarray...
 }
index d04d8f4f71f137d4aa733f26bb4295430a6df1b2..95941b85ce0cdf9faa719180345e9c66d3f73e00 100644 (file)
@@ -57,6 +57,7 @@ void InsetMathXYMatrix::write(WriteStream & os) const
 {
        MathEnsurer ensurer(os);
        os << "\\xymatrix";
+       bool open = os.startOuterRow();
        if (equal_spacing_) {
                os << "@!";
                switch (spacing_code_) {
@@ -83,7 +84,10 @@ void InsetMathXYMatrix::write(WriteStream & os) const
        }
        os << '{';
        InsetMathGrid::write(os);
-       os << "}\n";
+       os << "}";
+       if (open)
+               os.startOuterRow();
+       os << "\n";
 }
 
 
index 919edd453899d34769f20c32985c33ba981f2a52..9ff4bfef7480ee7b8f3a42a74d825cde59bf90e2 100644 (file)
@@ -200,7 +200,9 @@ int MacroData::write(odocstream & os, bool overwriteRedefinition) const
        // output template
        MathMacroTemplate const & tmpl =
                static_cast<MathMacroTemplate const &>(*inset);
-       WriteStream wi(os, false, true, WriteStream::wsDefault);
+       TexRow texrow(false);
+       otexrowstream ots(os,texrow);
+       WriteStream wi(ots, false, true, WriteStream::wsDefault);
        return tmpl.write(wi, overwriteRedefinition);
 }
 
index 1904843b553f885e6618818f75e0c8b3d585b0df..b98097a7b5b118e9f2d9228cbba24a14802bfa35 100644 (file)
@@ -1386,6 +1386,7 @@ void write(MathData const & dat, WriteStream & wi)
        extractStrings(ar);
        wi.firstitem() = true;
        for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it) {
+               //              wi.startOuterRow();
                (*it)->write(wi);
                wi.firstitem() = false;
        }
index f3ba2b480f0a41ca6de1c2482180fce44ebf32ba..30909f2ed72d6317ce7b7dc5d3b30d3315e8a8e2 100644 (file)
@@ -1168,7 +1168,9 @@ void MathMacroTemplate::read(Lexer & lex)
 void MathMacroTemplate::write(ostream & os) const
 {
        odocstringstream oss;
-       WriteStream wi(oss, false, false, WriteStream::wsDefault);
+       TexRow texrow(false);
+       otexrowstream ots(oss,texrow);
+       WriteStream wi(ots, false, false, WriteStream::wsDefault);
        oss << "FormulaMacro\n";
        write(wi);
        os << to_utf8(oss.str());
index ed23eb416040a88a6303bb721d965d33cb5b68f9..dabfc0680f93bb5ff8a03a9b9d880290be681aeb 100644 (file)
@@ -121,8 +121,8 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
 }
 
 
-WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType output,
-                       Encoding const * encoding)
+WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
+                                                OutputType output, Encoding const * encoding)
        : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
          output_(output), pendingspace_(false), pendingbrace_(false),
          textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
@@ -130,11 +130,11 @@ WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType o
 {}
 
 
-WriteStream::WriteStream(odocstream & os)
+WriteStream::WriteStream(otexrowstream & os)
        : os_(os), fragile_(false), firstitem_(false), latex_(false),
          output_(wsDefault), pendingspace_(false), pendingbrace_(false),
          textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
-         line_(0), encoding_(0)
+         line_(0), encoding_(0) 
 {}
 
 
@@ -183,6 +183,29 @@ void WriteStream::asciiOnly(bool ascii)
 }
 
 
+void WriteStream::pushRowEntry(TexRow::RowEntry entry)
+{
+       outer_row_entries_.push_back(entry);
+}
+
+
+void WriteStream::popRowEntry()
+{
+       if (!outer_row_entries_.empty())
+               outer_row_entries_.pop_back();
+}
+
+
+bool WriteStream::startOuterRow()
+{
+       size_t n = outer_row_entries_.size();
+       if (n > 0)
+               return texrow().start(outer_row_entries_[n - 1]);
+       else
+               return false;
+}
+
+
 WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
 {
        at->write(ws);
index ad1baada353dcd214b682442db7def4527a3a0d2..6cfd5855ec5be625e063275804080466a506236a 100644 (file)
@@ -17,6 +17,7 @@
 #include "InsetMath.h"
 // FIXME: Move to individual insets
 #include "MetricsInfo.h"
+#include "texstream.h"
 
 
 namespace lyx {
@@ -39,10 +40,10 @@ public:
                wsPreview
        };
        ///
-       WriteStream(odocstream & os, bool fragile, bool latex, OutputType output,
-               Encoding const * encoding = 0);
+       WriteStream(otexrowstream & os, bool fragile, bool latex, OutputType output,
+                               Encoding const * encoding = 0);
        ///
-       explicit WriteStream(odocstream & os);
+       explicit WriteStream(otexrowstream & os);
        ///
        ~WriteStream();
        ///
@@ -54,7 +55,9 @@ public:
        ///
        OutputType output() const { return output_; }
        ///
-       odocstream & os() { return os_; }
+       otexrowstream & os() { return os_; }
+       ///
+       TexRow & texrow() { return os_.texrow(); }
        ///
        bool & firstitem() { return firstitem_; }
        ///
@@ -85,9 +88,18 @@ public:
        bool asciiOnly() const { return ascii_; }
        /// LaTeX encoding
        Encoding const * encoding() const { return encoding_; }
+
+       /// maintains a stack of texrow informations about outer math insets.
+       /// push an entry
+       void pushRowEntry(TexRow::RowEntry entry);
+       /// pop an entry
+       void popRowEntry();
+       /// TexRow::starts the innermost outer math inset
+       /// returns true if the outer row entry will appear at this line
+       bool startOuterRow();
 private:
        ///
-       odocstream & os_;
+       otexrowstream & os_;
        /// do we have to write \\protect sometimes
        bool fragile_;
        /// are we at the beginning of an MathData?
@@ -112,6 +124,8 @@ private:
        int line_;
        ///
        Encoding const * encoding_;
+       ///
+       std::vector<TexRow::RowEntry> outer_row_entries_;
 };
 
 ///
index 1f90873fec10dae82647e76511081f2d3ce9951a..9801151129454530d7dd48141f7cf2e5ba0411d9 100644 (file)
@@ -877,7 +877,9 @@ bool isAlphaSymbol(MathAtom const & at)
 docstring asString(MathData const & ar)
 {
        odocstringstream os;
-       WriteStream ws(os);
+       TexRow texrow(false);
+       otexrowstream ots(os,texrow);
+       WriteStream ws(ots);
        ws << ar;
        return os.str();
 }
@@ -894,7 +896,9 @@ void asArray(docstring const & str, MathData & ar, Parse::flags pf)
 docstring asString(InsetMath const & inset)
 {
        odocstringstream os;
-       WriteStream ws(os);
+       TexRow texrow(false);
+       otexrowstream ots(os,texrow);
+       WriteStream ws(ots);
        inset.write(ws);
        return os.str();
 }
@@ -903,7 +907,9 @@ docstring asString(InsetMath const & inset)
 docstring asString(MathAtom const & at)
 {
        odocstringstream os;
-       WriteStream ws(os);
+       TexRow texrow(false);
+       otexrowstream ots(os,texrow);
+       WriteStream ws(ots);
        at->write(ws);
        return os.str();
 }