void InsetMathBox::mathmlize(MathStream & ms) const
-{
- SetMode textmode(ms, true, "class='mathbox'");
- ms << cell(0);
+{
+ SetMode textmode(ms, true);
+ ms << MTag("mstyle", "class='mathbox'")
+ << cell(0)
+ << ETag("mstyle");
}
void InsetMathBox::htmlize(HtmlStream & ms) const
{
SetHTMLMode textmode(ms, true);
- ms << cell(0);
+ ms << MTag("span", "class='mathbox'")
+ << cell(0)
+ << ETag("span");
}
void InsetMathBox::validate(LaTeXFeatures & features) const
{
+ // FIXME XHTML
+ // It'd be better to be able to get this from an InsetLayout, but at present
+ // InsetLayouts do not seem really to work for things that aren't InsetTexts.
+ if (features.runparams().math_flavor == OutputParams::MathAsMathML)
+ features.addPreambleSnippet("<style type=\"text/css\">\n"
+ "mstyle.mathbox { font-style: normal; }\n"
+ "</style>");
+ else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+ features.addPreambleSnippet("<style type=\"text/css\">\n"
+ "span.mathbox { font-style: normal; }\n"
+ "</style>");
+
if (name_ == "tag" || name_ == "tag*")
features.require("amsmath");
- cell(0).validate(features);
+ InsetMathNest::validate(features);
}
void InsetMathFBox::mathmlize(MathStream & ms) const
{
- SetMode textmode(ms, true, "class='fbox'");
- ms << cell(0);
+ SetMode textmode(ms, true);
+ ms << MTag("mstyle", "class='fbox'")
+ << cell(0)
+ << ETag("mstyle");
}
void InsetMathFBox::htmlize(HtmlStream & ms) const
{
- SetHTMLMode textmode(ms, true, "class='fbox'");
- ms << cell(0);
+ SetHTMLMode textmode(ms, true);
+ ms << MTag("span", "class='fbox'")
+ << cell(0)
+ << ETag("span");
}
// InsetLayouts do not seem really to work for things that aren't InsetTexts.
if (features.runparams().math_flavor == OutputParams::MathAsMathML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
- "mtext.fbox { border: 1px solid black; }\n"
+ "mstyle.fbox { border: 1px solid black; font-style: normal; padding: 0.5ex; }\n"
"</style>");
else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
- "span.fbox { border: 1px solid black; }\n"
+ "span.fbox { border: 1px solid black; font-style: normal; padding: 0.5ex; }\n"
"</style>");
+
+ cell(0).validate(features);
InsetMathNest::validate(features);
}
{
// FIXME We could do something with the other arguments.
std::string const cssclass = framebox_ ? "framebox" : "makebox";
- SetMode textmode(ms, true, "class='" + cssclass + "'");
- ms << cell(2);
+ SetMode textmode(ms, true);
+ ms << MTag("mstyle", "class='" + cssclass + "'")
+ << cell(2)
+ << ETag("mstyle");
}
void InsetMathMakebox::htmlize(HtmlStream & ms) const
{
// FIXME We could do something with the other arguments.
+ SetHTMLMode textmode(ms, true);
std::string const cssclass = framebox_ ? "framebox" : "makebox";
- SetHTMLMode textmode(ms, true, "class='" + cssclass + "'");
- ms << cell(2);
+ ms << MTag("span", "class='" + cssclass + "'")
+ << cell(2)
+ << ETag("span");
}
// InsetLayouts do not seem really to work for things that aren't InsetTexts.
if (features.runparams().math_flavor == OutputParams::MathAsMathML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
- "span.framebox { border: 1px solid black; }\n"
+ "mstyle.framebox { border: 1px solid black; }\n"
"</style>");
else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
void InsetMathBoxed::mathmlize(MathStream & ms) const
{
- SetMode mathmode(ms, false, "class='boxed'");
- ms << cell(0);
+ ms << MTag("mstyle", "class='boxed'")
+ << cell(0)
+ << ETag("mstyle");
}
void InsetMathBoxed::htmlize(HtmlStream & ms) const
{
- SetHTMLMode mathmode(ms, false, "class='boxed'");
- ms << cell(0);
+ ms << MTag("span", "class='boxed'")
+ << cell(0)
+ << ETag("span");
}
case '<': entity = "<"; break;
case '>': entity = ">"; break;
case '&': entity = "&"; break;
- case ' ':
- if (!ms.inText())
- break;
- entity = " ";
- break;
+ case ' ': {
+ ms << from_ascii("&nsbp;");
+ return;
+ }
default: break;
}
ms << from_ascii(entity);
return;
}
-
+
if (!entity.empty()) {
ms << "<mo>" << from_ascii(entity) << "</mo>";
return;
case '<': entity = "<"; break;
case '>': entity = ">"; break;
case '&': entity = "&"; break;
+ case ' ': entity = " "; break;
default: break;
}
}
if (have_entity) {
+ // an operator, so give some space
ms << ' ' << from_ascii(entity) << ' ';
return;
}
#include "InsetMathEnsureMath.h"
+#include "LaTeXFeatures.h"
#include "MathData.h"
#include "MathStream.h"
#include "MathSupport.h"
void InsetMathEnsureMath::mathmlize(MathStream & os) const
{
SetMode mathmode(os, false);
- os << cell(0);
+ os << MTag("mstyle", "class='math'")
+ << cell(0)
+ << ETag("mstyle");
}
void InsetMathEnsureMath::htmlize(HtmlStream & os) const
{
- os << "[EM]";
SetHTMLMode mathmode(os, false);
- os << cell(0);
- os << "[/EM]";
+ os << MTag("span", "class='math'")
+ << cell(0)
+ << ETag("span");
}
}
+void InsetMathEnsureMath::validate(LaTeXFeatures & features) const
+{
+ // FIXME XHTML
+ // It'd be better to be able to get this from an InsetLayout, but at present
+ // InsetLayouts do not seem really to work for things that aren't InsetTexts.
+ if (features.runparams().math_flavor == OutputParams::MathAsMathML)
+ features.addPreambleSnippet("<style type=\"text/css\">\n"
+ "mstyle.math { font-style: italic; }\n"
+ "</style>");
+ else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
+ features.addPreambleSnippet("<style type=\"text/css\">\n"
+ "span.mathbox { font-style: italic; }\n"
+ "</style>");
+
+ InsetMathNest::validate(features);
+}
+
} // namespace lyx
///
void infoize(odocstream & os) const;
///
+ void validate(LaTeXFeatures & features) const;
+ ///
InsetCode lyxCode() const { return MATH_ENSUREMATH_CODE; }
private:
virtual Inset * clone() const;
variant = "noun";
docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
- bool const textmode = (beg == "text");
if (!variant.empty()) {
- SetHTMLMode sm(os, textmode, "class='" + variant + "'");
- os << cell(0);
+ os << MTag("span", "class='" + variant + "'")
+ << cell(0)
+ << ETag("span");
} else
os << cell(0);
}
variant = "monospace";
// no support at present for textipa, textsc, noun
- docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
- bool const textmode = (beg == "text");
if (!variant.empty()) {
- std::string const attrs = "mathvariant='" + variant + "'";
- SetMode sm(os, textmode, attrs);
- os << cell(0);
+ os << MTag("mstyle", "mathvariant='" + variant + "'")
+ << cell(0)
+ << ETag("mstyle");
} else
os << cell(0);
}
void InsetMathMBox::mathmlize(MathStream & ms) const
{
- SetMode textmode(ms, true, "class='mbox'");
+ SetMode textmode(ms, true);
ms << cell(0);
}
void InsetMathMBox::htmlize(HtmlStream & ms) const
{
- SetHTMLMode textmode(ms, true, "class='mbox'");
+ SetHTMLMode textmode(ms, true);
ms << cell(0);
}
void InsetMathNumber::mathmlize(MathStream & os) const
{
- if (os.inText())
- os << str_;
- else
- os << "<mn>" << str_ << "</mn>";
+ os << "<mn>" << str_ << "</mn>";
}
{
MathData ar = dat;
extractStructure(ar, MATHML);
- if (ar.size() == 0) {
- if (!os.inText())
- os << "<mrow/>";
- } else if (ar.size() == 1)
+ if (ar.size() == 0)
+ os << "<mrow/>";
+ else if (ar.size() == 1)
os << ar.front();
else {
- if (!os.inText())
- os << MTag("mrow");
+ os << MTag("mrow");
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
(*it)->mathmlize(os);
- if (!os.inText())
- os << ETag("mrow");
+ os << ETag("mrow");
}
}
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_);
}
bool inText() const { return in_text_; }
private:
///
- void setTextMode() { in_text_ = true; }
- ///
- void setMathMode() { in_text_ = false; }
+ void setTextMode(bool t) { in_text_ = t; }
///
odocstream & os_;
///
/// A simpler version of ModeSpecifier, for MathML
-// FIXME There are still problems here with nesting, at least
-// potentially. The problem is that true nesting of text mode isn't
-// actually possible. I.e., we can't have:
-// <mtext><mtext></mtext></mtext>
-// So we have to have:
-// <mtext></mtext><mtext></mtext><mtext></mtext>
-// instead, where the last is really a continuation of the first.
-// We'll need some kind of stack to remember all that.
class SetMode {
public:
- ///
- explicit SetMode(MathStream & os, bool text, std::string const & attrs);
///
explicit SetMode(MathStream & os, bool text);
///
~SetMode();
private:
- ///
- void init(bool, std::string const &);
///
MathStream & os_;
///
- bool opened_;
- ///
bool was_text_;
};
bool inText() const { return in_text_; }
private:
///
- void setTextMode() { in_text_ = true; }
- ///
- void setMathMode() { in_text_ = false; }
+ void setTextMode(bool t) { in_text_ = t; }
///
odocstream & os_;
///
class SetHTMLMode {
public:
- ///
- explicit SetHTMLMode(HtmlStream & os, bool text, std::string attrs);
///
explicit SetHTMLMode(HtmlStream & os, bool text);
///
~SetHTMLMode();
private:
- ///
- void init(bool, std::string const &);
///
HtmlStream & os_;
///
- bool opened_;
- ///
bool was_text_;
};