]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathMacro.cpp
de.po
[lyx.git] / src / mathed / InsetMathMacro.cpp
index 3abd751d9c2b73e29f8c823f100680dd0f395fe1..d1bb67d59652e2c5376474807230892b9768ca9e 100644 (file)
@@ -15,6 +15,7 @@
 #include "InsetMathMacro.h"
 
 #include "InsetMathChar.h"
+#include "InsetMathScript.h"
 #include "MathCompletionList.h"
 #include "MathExtern.h"
 #include "MathFactory.h"
@@ -800,11 +801,13 @@ bool InsetMathMacro::validName() const
                return false;*/
 
        // valid characters?
-       for (size_t i = 0; i<n.size(); ++i) {
-               if (!(n[i] >= 'a' && n[i] <= 'z')
-                   && !(n[i] >= 'A' && n[i] <= 'Z')
-                   && n[i] != '*')
-                       return false;
+       if (n.size() > 1) {
+               for (size_t i = 0; i<n.size(); ++i) {
+                       if (!(n[i] >= 'a' && n[i] <= 'z')
+                           && !(n[i] >= 'A' && n[i] <= 'Z')
+                           && n[i] != '*')
+                               return false;
+               }
        }
 
        return true;
@@ -1104,7 +1107,22 @@ void InsetMathMacro::write(WriteStream & os) const
        // print out optionals
        for (i=0; i < cells_.size() && i < emptyOptFrom; ++i) {
                first = false;
-               os << "[" << cell(i) << "]";
+               // For correctly parsing it when a document is reloaded, we
+               // need to enclose an optional argument in braces if it starts
+               // with a script inset with empty nucleus or ends with a
+               // delimiter-size-modifier macro (see #10497 and #11346)
+               bool braced = false;
+               size_type last = cell(i).size() - 1;
+               if (cell(i).size() && cell(i)[last].nucleus()->asUnknownInset()) {
+                       latexkeys const * l = in_word_set(cell(i)[last].nucleus()->name());
+                       braced = (l && l->inset == "big");
+               } else if (cell(i).size() && cell(i)[0].nucleus()->asScriptInset()) {
+                       braced = cell(i)[0].nucleus()->asScriptInset()->nuc().empty();
+               }
+               if (braced)
+                       os << "[{" << cell(i) << "}]";
+               else
+                       os << "[" << cell(i) << "]";
        }
 
        // skip the tailing empty optionals
@@ -1318,4 +1336,10 @@ void InsetMathMacro::completionPosAndDim(Cursor const & cur, int & x, int & y,
 }
 
 
+void InsetMathMacro::setBuffer(Buffer & buffer)
+{
+       d->definition_.setBuffer(buffer);
+       InsetMathNest::setBuffer(buffer);
+}
+
 } // namespace lyx