MathML for MathBox and such.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32712 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2009-12-31 20:36:34 +00:00
parent 19cd5f0e82
commit eb17e9c362
5 changed files with 89 additions and 11 deletions

View File

@ -59,7 +59,8 @@ Math
- Binom (in Frac): None of these tags exist in MathML 2.0. We'll
just output a fraction with delimiters.
- Lefteqn
- MBox: Use <mtext>.
- MBox: There is a general issue here with text mode nesting. See the FIXME attached
to the SetMode class.
- Overset: Use <mover>.
- Par?
- Phantom: There is some support for this in MathML....

View File

@ -54,7 +54,7 @@ void InsetMathBox::normalize(NormalStream & os) const
void InsetMathBox::mathmlize(MathStream & ms) const
{
SetMode textmode(ms, true);
SetMode textmode(ms, true, from_ascii("class='mathbox'"));
ms << cell(0);
}
@ -134,12 +134,32 @@ void InsetMathFBox::normalize(NormalStream & os) const
}
void InsetMathFBox::mathmlize(MathStream & ms) const
{
SetMode textmode(ms, true, from_ascii("class='fbox'"));
ms << cell(0);
}
void InsetMathFBox::infoize(odocstream & os) const
{
os << "FBox: ";
}
void InsetMathFBox::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().flavor == OutputParams::HTML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
"mtext.fbox { border: 1px solid black; }\n"
"</style>");
}
/////////////////////////////////////////////////////////////////////
//
// InsetMathMakebox
@ -246,6 +266,28 @@ void InsetMathMakebox::infoize(odocstream & os) const
}
void InsetMathMakebox::mathmlize(MathStream & ms) const
{
// FIXME We could do something with the other arguments.
std::string const cssclass = framebox_ ? "framebox" : "makebox";
SetMode textmode(ms, true, from_ascii("class='" + cssclass + "'"));
ms << cell(2);
}
void InsetMathMakebox::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().flavor == OutputParams::HTML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
"mtext.framebox { border: 1px solid black; }\n"
"</style>");
}
/////////////////////////////////////////////////////////////////////
//
// InsetMathBoxed
@ -293,9 +335,23 @@ void InsetMathBoxed::infoize(odocstream & os) const
}
void InsetMathBoxed::mathmlize(MathStream & ms) const
{
SetMode mathmode(ms, false, from_ascii("class='boxed'"));
ms << cell(0);
}
void InsetMathBoxed::validate(LaTeXFeatures & features) const
{
features.require("amsmath");
// 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().flavor == OutputParams::HTML)
features.addPreambleSnippet("<style type=\"text/css\">\n"
"mstyle.boxed { border: 1px solid black; }\n"
"</style>");
InsetMathNest::validate(features);
}

View File

@ -66,9 +66,11 @@ public:
/// write normalized content
void normalize(NormalStream & ns) const;
///
//void mathmlize(MathStream & ms) const;
void mathmlize(MathStream & ms) const;
///
void infoize(odocstream & os) const;
///
void validate(LaTeXFeatures & features) const;
private:
///
Inset * clone() const { return new InsetMathFBox(*this); }
@ -89,11 +91,13 @@ public:
/// write normalized content
void normalize(NormalStream & ns) const;
///
//void mathmlize(MathStream & ms) const;
void mathmlize(MathStream & ms) const;
///
mode_type currentMode() const { return TEXT_MODE; }
///
void infoize(odocstream & os) const;
///
void validate(LaTeXFeatures & features) const;
private:
Inset * clone() const { return new InsetMathMakebox(*this); }
///
@ -116,7 +120,7 @@ public:
///
void write(WriteStream & os) const;
///
//void mathmlize(MathStream & ms) const;
void mathmlize(MathStream & ms) const;
/// write normalized content
void normalize(NormalStream & ns) const;
///

View File

@ -338,14 +338,14 @@ MathStream & operator<<(MathStream & ms, docstring const & s)
SetMode::SetMode(MathStream & os, bool text)
: os_(os)
: os_(os), opened_(false)
{
init(text, from_ascii(""));
}
SetMode::SetMode(MathStream & os, bool text, docstring attrs)
: os_(os)
: os_(os), opened_(false)
{
init(text, attrs);
}
@ -362,9 +362,12 @@ void SetMode::init(bool text, docstring attrs)
if (!attrs.empty())
os_ << " " << attrs;
os_ << ">";
opened_ = true;
} else {
if (!attrs.empty())
if (!attrs.empty()) {
os_ << "<mstyle " << attrs << ">";
opened_ = true;
}
os_.setMathMode();
}
}
@ -372,8 +375,12 @@ void SetMode::init(bool text, docstring attrs)
SetMode::~SetMode()
{
if (opened_) {
if (os_.inText())
os_ << "</mtext>";
else
os_ << "</mstyle>";
}
if (was_text_) {
os_.setTextMode();
os_ << "<mtext>";

View File

@ -304,7 +304,15 @@ MathStream & operator<<(MathStream &, MTag const &);
MathStream & operator<<(MathStream &, ETag const &);
// A simpler version of ModeSpecifier, for MathML
/// 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:
///
@ -319,6 +327,8 @@ private:
///
MathStream & os_;
///
bool opened_;
///
bool was_text_;
};