]> 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 c70d3b1f39c5c95339367b22b508daac6164409e..9344dac497e85e6f37531b06984327ed65ed7ea2 100644 (file)
@@ -81,10 +81,6 @@ public:
        void ulemCmd(UlemCmdType ulemcmd) { ulemcmd_ = ulemcmd; }
        /// tell which ulem command type we are inside
        UlemCmdType ulemCmd() const { return ulemcmd_; }
-       /// record whether we are in the optional argument of a math macro
-       void insideMacroOpt(bool inopt) { insidemacro_opt_ = inopt; }
-       /// tell whether we are in the optional argument of a math macro
-       bool insideMacroOpt() const { return insidemacro_opt_; }
        /// writes space if next thing is isalpha()
        void pendingSpace(bool how);
        /// writes space if next thing is isalpha()
@@ -105,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_; }
 
@@ -124,8 +124,6 @@ private:
        int latex_;
        /// output type (default, source preview, instant preview)?
        OutputType output_;
-       /// are we in the optional argument of a math macro?
-       bool insidemacro_opt_;
        /// do we have a space pending?
        bool pendingspace_;
        /// do we have a brace pending?
@@ -148,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_;
 };
 
 ///
@@ -299,10 +299,12 @@ private:
 //  MathML
 //
 
+
+/// Start tag.
 class MTag {
 public:
        ///
-       MTag(char const * const tag, std::string attr = "")
+       MTag(char const * const tag, std::string const & attr = std::string())
                : tag_(tag), attr_(attr) {}
        ///
        char const * const tag_;
@@ -310,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
@@ -328,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();
        ///
@@ -348,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; }
@@ -362,6 +385,10 @@ private:
        ///
        odocstringstream deferred_;
        ///
+       std::string xmlns_;
+       ///
+       bool xml_mode_;
+       ///
        friend class SetMode;
 };
 
@@ -381,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_;
 };
@@ -627,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