]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathStream.cpp
We only support gcc >= 4.9.
[lyx.git] / src / mathed / MathStream.cpp
index 43e4a3e570a53e1b6fc6486959a3c0f807542a55..e14e850e1805fa7f8a85471f18ba283e7128871b 100644 (file)
@@ -88,7 +88,7 @@ NormalStream & operator<<(NormalStream & ns, int i)
 /////////////////////////////////////////////////////////////////
 
 
-WriteStream & operator<<(WriteStream & ws, docstring const & s)
+TeXMathStream & operator<<(TeXMathStream & ws, docstring const & s)
 {
        // Skip leading '\n' if we had already output a newline char
        size_t const first =
@@ -106,9 +106,15 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
        } else if (ws.pendingSpace()) {
                if (isAlphaASCII(s[first]))
                        ws.os() << ' ';
+               else if (s[first] == '[' && ws.useBraces())
+                       ws.os() << "{}";
                else if (s[first] == ' ' && ws.textMode())
                        ws.os() << '\\';
                ws.pendingSpace(false);
+       } else if (ws.useBraces()) {
+               if (s[first] == '\'')
+                       ws.os() << "{}";
+               ws.useBraces(false);
        }
        ws.os() << s.substr(first);
        int lf = 0;
@@ -126,14 +132,14 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
 }
 
 
-WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
-                                                OutputType output, Encoding const * encoding)
+TeXMathStream::TeXMathStream(otexrowstream & os, bool fragile, bool latex,
+                             OutputType output, Encoding const * encoding)
        : os_(os), fragile_(fragile), latex_(latex),
          output_(output), encoding_(encoding)
 {}
 
 
-WriteStream::~WriteStream()
+TeXMathStream::~TeXMathStream()
 {
        if (pendingbrace_)
                os_ << '}';
@@ -142,49 +148,57 @@ WriteStream::~WriteStream()
 }
 
 
-void WriteStream::addlines(unsigned int n)
+void TeXMathStream::addlines(unsigned int n)
 {
        line_ += n;
 }
 
 
-void WriteStream::pendingSpace(bool how)
+void TeXMathStream::pendingSpace(bool space)
 {
-       pendingspace_ = how;
+       pendingspace_ = space;
+       if (!space)
+               usebraces_ = false;
 }
 
 
-void WriteStream::pendingBrace(bool brace)
+void TeXMathStream::useBraces(bool braces)
+{
+       usebraces_ = braces;
+}
+
+
+void TeXMathStream::pendingBrace(bool brace)
 {
        pendingbrace_ = brace;
 }
 
 
-void WriteStream::textMode(bool textmode)
+void TeXMathStream::textMode(bool textmode)
 {
        textmode_ = textmode;
 }
 
 
-void WriteStream::lockedMode(bool locked)
+void TeXMathStream::lockedMode(bool locked)
 {
        locked_ = locked;
 }
 
 
-void WriteStream::asciiOnly(bool ascii)
+void TeXMathStream::asciiOnly(bool ascii)
 {
        ascii_ = ascii;
 }
 
 
-Changer WriteStream::changeRowEntry(TexRow::RowEntry entry)
+Changer TeXMathStream::changeRowEntry(TexRow::RowEntry entry)
 {
        return changeVar(row_entry_, entry);
 }
 
 
-bool WriteStream::startOuterRow()
+bool TeXMathStream::startOuterRow()
 {
        if (TexRow::isNone(row_entry_))
                return false;
@@ -192,28 +206,28 @@ bool WriteStream::startOuterRow()
 }
 
 
-WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
+TeXMathStream & operator<<(TeXMathStream & ws, MathAtom const & at)
 {
        at->write(ws);
        return ws;
 }
 
 
-WriteStream & operator<<(WriteStream & ws, MathData const & ar)
+TeXMathStream & operator<<(TeXMathStream & ws, MathData const & ar)
 {
        write(ar, ws);
        return ws;
 }
 
 
-WriteStream & operator<<(WriteStream & ws, char const * s)
+TeXMathStream & operator<<(TeXMathStream & ws, char const * s)
 {
        ws << from_utf8(s);
        return ws;
 }
 
 
-WriteStream & operator<<(WriteStream & ws, char c)
+TeXMathStream & operator<<(TeXMathStream & ws, char c)
 {
        if (c == '\n' && !ws.canBreakLine())
                return ws;
@@ -226,9 +240,15 @@ WriteStream & operator<<(WriteStream & ws, char c)
        } else if (ws.pendingSpace()) {
                if (isAlphaASCII(c))
                        ws.os() << ' ';
+               else if (c == '[' && ws.useBraces())
+                       ws.os() << "{}";
                else if (c == ' ' && ws.textMode())
                        ws.os() << '\\';
                ws.pendingSpace(false);
+       } else if (ws.useBraces()) {
+               if (c == '\'')
+                       ws.os() << "{}";
+               ws.useBraces(false);
        }
        ws.os() << c;
        if (c == '\n')
@@ -238,7 +258,7 @@ WriteStream & operator<<(WriteStream & ws, char c)
 }
 
 
-WriteStream & operator<<(WriteStream & ws, int i)
+TeXMathStream & operator<<(TeXMathStream & ws, int i)
 {
        if (ws.pendingBrace()) {
                ws.os() << '}';
@@ -251,7 +271,7 @@ WriteStream & operator<<(WriteStream & ws, int i)
 }
 
 
-WriteStream & operator<<(WriteStream & ws, unsigned int i)
+TeXMathStream & operator<<(TeXMathStream & ws, unsigned int i)
 {
        if (ws.pendingBrace()) {
                ws.os() << '}';