From eb17e9c3623e941afd470f969b11820c73b021b5 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 31 Dec 2009 20:36:34 +0000 Subject: [PATCH] MathML for MathBox and such. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32712 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/HTML/HTML.notes | 3 +- src/mathed/InsetMathBox.cpp | 58 ++++++++++++++++++++++++++++++++++++- src/mathed/InsetMathBox.h | 10 +++++-- src/mathed/MathStream.cpp | 17 +++++++---- src/mathed/MathStream.h | 12 +++++++- 5 files changed, 89 insertions(+), 11 deletions(-) diff --git a/development/HTML/HTML.notes b/development/HTML/HTML.notes index 0f863b47bc..26447ae68e 100644 --- a/development/HTML/HTML.notes +++ b/development/HTML/HTML.notes @@ -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 . + - MBox: There is a general issue here with text mode nesting. See the FIXME attached + to the SetMode class. - Overset: Use . - Par? - Phantom: There is some support for this in MathML.... diff --git a/src/mathed/InsetMathBox.cpp b/src/mathed/InsetMathBox.cpp index 8aba8d80fc..17d2b13346 100644 --- a/src/mathed/InsetMathBox.cpp +++ b/src/mathed/InsetMathBox.cpp @@ -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(""); +} + + + ///////////////////////////////////////////////////////////////////// // // 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(""); +} + + + ///////////////////////////////////////////////////////////////////// // // 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(""); InsetMathNest::validate(features); } diff --git a/src/mathed/InsetMathBox.h b/src/mathed/InsetMathBox.h index 4ef299401d..5a958f4b78 100644 --- a/src/mathed/InsetMathBox.h +++ b/src/mathed/InsetMathBox.h @@ -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; /// diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index ffc91c4f42..c9f7ef54a5 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -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_ << ""; + opened_ = true; + } os_.setMathMode(); } } @@ -372,8 +375,12 @@ void SetMode::init(bool text, docstring attrs) SetMode::~SetMode() { - if (os_.inText()) - os_ << ""; + if (opened_) { + if (os_.inText()) + os_ << ""; + else + os_ << ""; + } if (was_text_) { os_.setTextMode(); os_ << ""; diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 51760a33dd..99900c3c11 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -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: +// +// So we have to have: +// +// 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_; };