]> 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 fe5c259a93786482c7f2c1f13e4868b276976233..9344dac497e85e6f37531b06984327ed65ed7ea2 100644 (file)
@@ -13,6 +13,8 @@
 #define MATH_MATHMLSTREAM_H
 
 #include "InsetMath.h"
+
+#include "TexRow.h"
 #include "texstream.h"
 
 #include "support/Changer.h"
@@ -26,7 +28,6 @@ class Encoding;
 class InsetMath;
 class MathAtom;
 class MathData;
-struct RowEntry;
 
 //
 // LaTeX/LyX
@@ -41,6 +42,12 @@ public:
                wsPreview
        };
        ///
+       enum UlemCmdType {
+               NONE,
+               UNDERLINE,
+               STRIKEOUT
+       };
+       ///
        explicit WriteStream(otexrowstream & os, bool fragile = false,
                             bool latex = false, OutputType output = wsDefault,
                             Encoding const * encoding = 0);
@@ -66,6 +73,14 @@ public:
        void canBreakLine(bool breakline) { canbreakline_ = breakline; }
        /// tell whether we can write an immediately following newline char
        bool canBreakLine() const { return canbreakline_; }
+       /// record whether we have to take care for striking out display math
+       void strikeoutMath(bool mathsout) { mathsout_ = mathsout; }
+       /// tell whether we have to take care for striking out display math
+       bool strikeoutMath() const { return mathsout_; }
+       /// record which ulem command type we are inside
+       void ulemCmd(UlemCmdType ulemcmd) { ulemcmd_ = ulemcmd; }
+       /// tell which ulem command type we are inside
+       UlemCmdType ulemCmd() const { return ulemcmd_; }
        /// writes space if next thing is isalpha()
        void pendingSpace(bool how);
        /// writes space if next thing is isalpha()
@@ -86,11 +101,15 @@ 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_; }
 
        /// Temporarily change the TexRow information about the outer row entry.
-       Changer changeRowEntry(RowEntry entry);
+       Changer changeRowEntry(TexRow::RowEntry entry);
        /// TexRow::starts the innermost outer math inset
        /// returns true if the outer row entry will appear at this line
        bool startOuterRow();
@@ -117,13 +136,18 @@ private:
        bool ascii_;
        /// are we allowed to output an immediately following newline?
        bool canbreakline_;
+       /// should we take care for striking out display math?
+       bool mathsout_;
+       /// what ulem command are we inside (none, underline, strikeout)?
+       UlemCmdType ulemcmd_;
        ///
        int line_;
        ///
        Encoding const * encoding_;
        /// Row entry we are in
-       /// (it is a pointer to allow forward-declaration)
-       unique_ptr<RowEntry> row_entry_;
+       TexRow::RowEntry row_entry_;
+       /// whether we are in a MathClass inset
+       bool mathclass_;
 };
 
 ///
@@ -154,7 +178,7 @@ int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked, bool as
  *
  * A local variable of this type can be used to either ensure math mode
  * or delay the writing of a pending brace when outputting LaTeX.
- * A LyX MathMacro is always assumed needing a math mode environment, while
+ * A LyX InsetMathMacro is always assumed needing a math mode environment, while
  * no assumption is made for macros defined through \newcommand or \def.
  *
  * Example 1:
@@ -184,7 +208,7 @@ int ensureMode(WriteStream & os, InsetMath::mode_type mode, bool locked, bool as
  * to be specified. Only the following 3 different cases are handled.
  *
  * When the needs_mathmode parameter is true the behavior is as in Example 1.
- * This is the case for a LyX MathMacro or a macro not tagged as textmode.
+ * This is the case for a LyX InsetMathMacro or a macro not tagged as textmode.
  *
  * When the needs_mathmode and textmode_macro parameters are both false the
  * macro is left in the same (text or math mode) environment it was entered.
@@ -275,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_;
@@ -286,12 +312,27 @@ 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_;
 };
 
 
@@ -304,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();
        ///
@@ -324,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; }
@@ -338,6 +385,10 @@ private:
        ///
        odocstringstream deferred_;
        ///
+       std::string xmlns_;
+       ///
+       bool xml_mode_;
+       ///
        friend class SetMode;
 };
 
@@ -357,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_;
 };
@@ -603,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