<< 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();
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;
}
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;
}
{
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;
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());
}
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;
}
{
MathEnsurer ensurer(os);
os << "\\begin{" << name_ << '}';
+ bool open = os.startOuterRow();
InsetMathGrid::write(os);
os << "\\end{" << name_ << '}';
+ if (open)
+ os.startOuterRow();
}
if (os.fragile())
os << "\\protect";
os << "\\begin{" << name_ << '}';
+ bool open = os.startOuterRow();
char const v = verticalAlignment();
if (v == 't' || v == 'b')
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...
}
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();
}
{
MathEnsurer ensurer(os);
os << "\\Diagram";
+ bool open = os.startOuterRow();
os << '{';
InsetMathGrid::write(os);
os << "}\n";
+ if (open)
+ os.startOuterRow();
}
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() &&
os << '}';
os << eocString(col + nccols - 1, lastcol);
col += nccols;
+ os.popRowEntry();
}
eol = eolString(row, os.fragile(), os.latex(), last_eoln);
os << eol;
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;
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());
}
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();
}
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:
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;
break;
default:
- os << "\n\\begin{unknown" << star(n) << "}\n";
+ os << "\n";
+ os.startOuterRow();
+ os << "\\begin{unknown" << star(n) << "}\n";
break;
}
}
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:
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:
break;
default:
- os << "\n\\end{unknown" << star(n) << "}\n";
+ os << "\n";
+ os.startOuterRow();
+ os << "\\end{unknown" << star(n) << "}\n";
break;
}
}
return res + InsetMathGrid::eolString(row, fragile, latex, last_eoln);
}
-
void InsetMathHull::write(WriteStream & os) const
{
ModeSpecifier specifier(os, MATH_MODE);
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());
}
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)
++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()), "&", "&"), "<", "<"));
ms << ETag("alt");
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();
// 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();
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";
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()) {
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);
}
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")
if (ws.fragile())
ws << "\\protect";
ws << "\\end{" << name_ << suffix << "}\n";
+ if (open)
+ ws.startOuterRow();
}
{
MathEnsurer ensurer(os);
os << "\\substack{";
+ bool open = os.startOuterRow();
InsetMathGrid::write(os);
os << "}\n";
+ if (open)
+ os.startOuterRow();
}
if (os.fragile())
os << "\\protect";
os << "\\begin{" << name_ << '}';
+ bool open = os.startOuterRow();
char const v = verticalAlignment();
if (v == 't' || v == 'b')
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...
}
{
MathEnsurer ensurer(os);
os << "\\xymatrix";
+ bool open = os.startOuterRow();
if (equal_spacing_) {
os << "@!";
switch (spacing_code_) {
}
os << '{';
InsetMathGrid::write(os);
- os << "}\n";
+ os << "}";
+ if (open)
+ os.startOuterRow();
+ os << "\n";
}
// 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);
}
extractStrings(ar);
wi.firstitem() = true;
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it) {
+ // wi.startOuterRow();
(*it)->write(wi);
wi.firstitem() = false;
}
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());
}
-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),
{}
-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)
{}
}
+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);
#include "InsetMath.h"
// FIXME: Move to individual insets
#include "MetricsInfo.h"
+#include "texstream.h"
namespace lyx {
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();
///
///
OutputType output() const { return output_; }
///
- odocstream & os() { return os_; }
+ otexrowstream & os() { return os_; }
+ ///
+ TexRow & texrow() { return os_.texrow(); }
///
bool & firstitem() { return firstitem_; }
///
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?
int line_;
///
Encoding const * encoding_;
+ ///
+ std::vector<TexRow::RowEntry> outer_row_entries_;
};
///
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();
}
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();
}
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();
}