]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathFactory.cpp
Fix bug 5802 (http://bugzilla.lyx.org/show_bug.cgi?id=5802)
[lyx.git] / src / mathed / MathFactory.cpp
index 8791b719a5478bac4a486ec6fde41825470c8471..16b6a2e28d7ca4fd7a37c12accae2ea816b93170 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author André Pönitz
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -41,6 +41,7 @@
 #include "InsetMathTabular.h"
 #include "InsetMathUnderset.h"
 #include "InsetMathUnknown.h"
+#include "InsetMathHull.h"
 #include "InsetMathXArrow.h"
 #include "InsetMathXYMatrix.h"
 #include "MacroTable.h"
@@ -51,6 +52,7 @@
 #include "MathSupport.h"
 
 #include "insets/InsetCommand.h"
+#include "insets/InsetSpace.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -60,7 +62,9 @@
 
 #include "frontends/FontLoader.h"
 
+#include "Encoding.h"
 #include "LyX.h" // use_gui
+#include "OutputParams.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -219,17 +223,15 @@ void initSymbols()
 }
 
 
-bool isSpecialChar(docstring name)
+bool isSpecialChar(docstring const & name)
 {
-       if (name.size() != 1) {
-               string const s = to_ascii(name);
-               return  s == "textasciicircum" || s == "mathcircumflex" ||
-                       s == "textasciitilde"  || s == "textbackslash";
-       } else {
-               char_type const c = name.at(0);
-               return  c == '{' || c == '}' || c == '&' || c == '$' ||
-                       c == '#' || c == '%' || c == '_';
-       }
+       if (name.size() != 1)
+               return  name == "textasciicircum" || name == "mathcircumflex" ||
+                       name == "textasciitilde"  || name == "textbackslash";
+
+       char_type const c = name.at(0);
+       return  c == '{' || c == '}' || c == '&' || c == '$' ||
+               c == '#' || c == '%' || c == '_' || c == ' ';
 }
 
 
@@ -318,7 +320,7 @@ MathAtom createInsetMath(docstring const & s)
                if (inset == "decoration")
                        return MathAtom(new InsetMathDecoration(l));
                if (inset == "space")
-                       return MathAtom(new InsetMathSpace(l->name));
+                       return MathAtom(new InsetMathSpace(to_ascii(l->name), ""));
                if (inset == "dots")
                        return MathAtom(new InsetMathDots(l));
                if (inset == "mbox")
@@ -445,6 +447,8 @@ MathAtom createInsetMath(docstring const & s)
                return MathAtom(new InsetMathColor(true));
        if (s == "textcolor")
                return MathAtom(new InsetMathColor(false));
+       if (s == "cfrac")
+               return MathAtom(new InsetMathCFrac);
        if (s == "dfrac")
                return MathAtom(new InsetMathDFrac);
        if (s == "tfrac")
@@ -464,6 +468,9 @@ MathAtom createInsetMath(docstring const & s)
        if (isSpecialChar(s))
                return MathAtom(new InsetMathSpecialChar(s));
 
+       if (s == "regexp")
+               return MathAtom(new InsetMathHull(hullRegexp));
+
        return MathAtom(new MathMacro(s));
 }
 
@@ -475,13 +482,28 @@ bool createInsetMath_fromDialogStr(docstring const & str, MathData & ar)
        docstring name;
        docstring body = split(str, name, ' ');
 
-       if (name != "ref" )
+       if (name == "ref") {
+               InsetCommandParams icp(REF_CODE);
+               // FIXME UNICODE
+               InsetCommand::string2params("ref", to_utf8(str), icp);
+               mathed_parse_cell(ar, icp.getCommand());
+       } else if (name == "mathspace") {
+               InsetSpaceParams isp(true);
+               InsetSpace::string2params(to_utf8(str), isp);
+               InsetSpace is(isp);
+               odocstringstream os;
+               Encoding const * const ascii = encodings.fromLyXName("ascii");
+               OutputParams op(ascii);
+               is.latex(os, op);
+               mathed_parse_cell(ar, os.str());
+               if (ar.size() == 2) {
+                       // remove "{}"
+                       if (ar[1].nucleus()->asBraceInset())
+                               ar.pop_back();
+               }
+       } else
                return false;
 
-       InsetCommandParams icp(REF_CODE);
-       // FIXME UNICODE
-       InsetCommand::string2params("ref", to_utf8(str), icp);
-       mathed_parse_cell(ar, icp.getCommand());
        if (ar.size() != 1)
                return false;