]> git.lyx.org Git - lyx.git/commitdiff
MathML for MathBox and such.
authorRichard Heck <rgheck@comcast.net>
Thu, 31 Dec 2009 20:36:34 +0000 (20:36 +0000)
committerRichard Heck <rgheck@comcast.net>
Thu, 31 Dec 2009 20:36:34 +0000 (20:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32712 a592a061-630c-0410-9148-cb99ea01b6c8

development/HTML/HTML.notes
src/mathed/InsetMathBox.cpp
src/mathed/InsetMathBox.h
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index 0f863b47bc762f800b1976ed939f60126fc7c809..26447ae68eabd5c15950943f88ff5fa5675057c2 100644 (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....
index 8aba8d80fcbc6323336d8cbc0756176a62d858ee..17d2b13346d78f187f7d565db3211d54b7aee2e6 100644 (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);
 }
 
index 4ef299401d9b6df2dd4931e6ab8384b8f0cc71fc..5a958f4b7845eedcc561b16145aa4b9c236785bf 100644 (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;
        ///
index ffc91c4f42667cd611d2fc749cda76f4b9af7630..c9f7ef54a50df772ff4164f936c548ed8a04d765 100644 (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 (os_.inText())
-               os_ << "</mtext>";
+       if (opened_) {
+               if (os_.inText())
+                       os_ << "</mtext>";
+               else
+                       os_ << "</mstyle>";
+       }
        if (was_text_) {
                os_.setTextMode();
                os_ << "<mtext>";
index 51760a33dde485c22fdf4e041d503d77b024c88b..99900c3c112918fd94c654d276feb7d5e8ac7129 100644 (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_;
 };