#include "MathStream.h"
+#include "MathFactory.h"
#include "MathData.h"
#include "MathExtern.h"
-#include "support/textutils.h"
+#include "TexRow.h"
+
#include "support/docstring.h"
+#include "support/RefChanger.h"
+#include "support/textutils.h"
#include <algorithm>
#include <cstring>
}
-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),
- line_(0), encoding_(encoding)
-{}
-
-
-WriteStream::WriteStream(odocstream & 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)
+ mathsout_(false), line_(0), encoding_(encoding),
+ row_entry_(make_unique<RowEntry>(TexRow::row_none))
{}
}
+Changer WriteStream::changeRowEntry(RowEntry entry)
+{
+ return make_change(*row_entry_, entry);
+}
+
+
+bool WriteStream::startOuterRow()
+{
+ if (TexRow::isNone(*row_entry_))
+ return false;
+ return texrow().start(*row_entry_);
+}
+
+
WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
{
at->write(ws);
SetMode::SetMode(MathStream & os, bool text)
- : os_(os), opened_(false)
-{
- init(text, "");
-}
-
-
-SetMode::SetMode(MathStream & os, bool text, string const & attrs)
- : os_(os), opened_(false)
-{
- init(text, attrs);
-}
-
-
-void SetMode::init(bool text, string const & attrs)
+ : os_(os)
{
was_text_ = os_.inText();
- if (was_text_)
- os_ << "</mtext>";
- if (text) {
- os_.setTextMode();
- os_ << "<mtext";
- if (!attrs.empty())
- os_ << " " << from_utf8(attrs);
- os_ << ">";
- opened_ = true;
- } else {
- if (!attrs.empty()) {
- os_ << "<mstyle " << from_utf8(attrs) << ">";
- opened_ = true;
- }
- os_.setMathMode();
- }
+ os_.setTextMode(text);
}
SetMode::~SetMode()
{
- if (opened_) {
- if (os_.inText())
- os_ << "</mtext>";
- else
- os_ << "</mstyle>";
- }
- if (was_text_) {
- os_.setTextMode();
- os_ << "<mtext>";
- } else {
- os_.setMathMode();
- }
+ os_.setTextMode(was_text_);
}
SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text)
- : os_(os), opened_(false)
-{
- init(text, "");
-}
-
-
-SetHTMLMode::SetHTMLMode(HtmlStream & os, bool text, string attrs)
- : os_(os), opened_(true)
-{
- init(text, attrs);
-}
-
-
-void SetHTMLMode::init(bool text, string const & attrs)
+ : os_(os)
{
was_text_ = os_.inText();
- if (text) {
- os_.setTextMode();
- if (attrs.empty())
- os_ << MTag("span");
- else
- os_ << MTag("span", attrs);
- opened_ = true;
- } else
- os_.setMathMode();
+ os_.setTextMode(text);
}
SetHTMLMode::~SetHTMLMode()
{
- if (opened_)
- os_ << ETag("span");
- if (was_text_)
- os_.setTextMode();
- else
- os_.setMathMode();
+ os_.setTextMode(was_text_);
}
}
+docstring convertDelimToXMLEscape(docstring const & name)
+{
+ if (name.size() == 1) {
+ char_type const c = name[0];
+ if (c == '<')
+ return from_ascii("<");
+ else if (c == '>')
+ return from_ascii(">");
+ else
+ return name;
+ }
+ MathWordList const & words = mathedWordList();
+ MathWordList::const_iterator it = words.find(name);
+ if (it != words.end()) {
+ docstring const escape = it->second.xmlname;
+ return escape;
+ }
+ LYXERR0("Unable to find `" << name <<"' in the mathWordList.");
+ return name;
+}
+
} // namespace lyx