]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathStream.h
Assure correct spacing of colored items in mathed
[lyx.git] / src / mathed / MathStream.h
index 777992157744e92f644fca02ece5604a270e467c..9344dac497e85e6f37531b06984327ed65ed7ea2 100644 (file)
@@ -101,6 +101,10 @@ public:
        void asciiOnly(bool ascii);
        /// tell whether to use only ascii chars when producing latex code
        bool asciiOnly() const { return ascii_; }
+       /// tell whether we are in a MathClass inset
+       void inMathClass(bool mathclass) { mathclass_ = mathclass; };
+       /// tell whether we are in a MathClass inset
+       bool inMathClass() const { return mathclass_; }
        /// LaTeX encoding
        Encoding const * encoding() const { return encoding_; }
 
@@ -142,6 +146,8 @@ private:
        Encoding const * encoding_;
        /// Row entry we are in
        TexRow::RowEntry row_entry_;
+       /// whether we are in a MathClass inset
+       bool mathclass_;
 };
 
 ///
@@ -293,6 +299,8 @@ private:
 //  MathML
 //
 
+
+/// Start tag.
 class MTag {
 public:
        ///
@@ -304,15 +312,30 @@ public:
        std::string attr_;
 };
 
+
+/// End tag.
 class ETag {
 public:
        ///
-       ETag(char const * const tag) : tag_(tag) {}
+       explicit ETag(char const * const tag) : tag_(tag) {}
        ///
        char const * const tag_;
 };
 
 
+/// Compound tag (no content, directly closed).
+class CTag {
+public:
+       ///
+       CTag(char const * const tag, std::string attr = "")
+            : tag_(tag), attr_(attr) {}
+       ///
+       char const * const tag_;
+    ///
+    std::string attr_;
+};
+
+
 /// Throw MathExportException to signal that the attempt to export
 /// some math in the current format did not succeed. E.g., we can't
 /// export xymatrix as MathML, so that will throw, and we'll fall back
@@ -322,8 +345,8 @@ class MathExportException : public std::exception {};
 
 class MathStream {
 public:
-       ///
-       explicit MathStream(odocstream & os);
+       /// Builds a stream proxy for os; the MathML namespace is given by xmlns (supposed to be already defined elsewhere in the document).
+       explicit MathStream(odocstream & os, std::string xmlns="", bool xmlMode=false);
        ///
        void cr();
        ///
@@ -342,6 +365,12 @@ public:
        docstring deferred() const;
        ///
        bool inText() const { return in_text_; }
+       ///
+       std::string xmlns() const { return xmlns_; }
+       ///
+       bool xmlMode() const { return xml_mode_; }
+       /// Returns the tag name prefixed by the name space if needed.
+       std::string namespacedTag(std::string tag) const { return ((xmlns().empty()) ? "" : xmlns() + ":") + tag; }
 private:
        ///
        void setTextMode(bool t) { in_text_ = t; }
@@ -356,6 +385,10 @@ private:
        ///
        odocstringstream deferred_;
        ///
+       std::string xmlns_;
+       ///
+       bool xml_mode_;
+       ///
        friend class SetMode;
 };
 
@@ -375,18 +408,20 @@ MathStream & operator<<(MathStream &, char_type);
 MathStream & operator<<(MathStream &, MTag const &);
 ///
 MathStream & operator<<(MathStream &, ETag const &);
+///
+MathStream & operator<<(MathStream &, CTag const &);
 
 
 /// A simpler version of ModeSpecifier, for MathML
 class SetMode {
 public:
        ///
-       explicit SetMode(MathStream & os, bool text);
+       explicit SetMode(MathStream & ms, bool text);
        ///
        ~SetMode();
 private:
        ///
-       MathStream & os_;
+       MathStream & ms_;
        ///
        bool was_text_;
 };
@@ -621,7 +656,7 @@ OctaveStream & operator<<(OctaveStream &, char);
 OctaveStream & operator<<(OctaveStream &, int);
 
 
-docstring convertDelimToXMLEscape(docstring const & name);
+docstring convertDelimToXMLEscape(docstring const & name, bool xmlmode);
 
 } // namespace lyx