]> 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 c8060086b9ac3abf248d4d2d98c62cdcceba1b44..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.
  */
@@ -32,6 +32,7 @@
 #include "InsetMathRoot.h"
 #include "InsetMathSize.h"
 #include "InsetMathSpace.h"
+#include "InsetMathSpecialChar.h"
 #include "InsetMathSplit.h"
 #include "InsetMathSqrt.h"
 #include "InsetMathStackrel.h"
@@ -40,6 +41,7 @@
 #include "InsetMathTabular.h"
 #include "InsetMathUnderset.h"
 #include "InsetMathUnknown.h"
+#include "InsetMathHull.h"
 #include "InsetMathXArrow.h"
 #include "InsetMathXYMatrix.h"
 #include "MacroTable.h"
@@ -50,6 +52,7 @@
 #include "MathSupport.h"
 
 #include "insets/InsetCommand.h"
+#include "insets/InsetSpace.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -59,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;
@@ -218,6 +223,18 @@ void initSymbols()
 }
 
 
+bool isSpecialChar(docstring const & name)
+{
+       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 == ' ';
+}
+
+
 } // namespace anon
 
 MathWordList const & mathedWordList()
@@ -303,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")
@@ -430,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")
@@ -446,6 +465,11 @@ MathAtom createInsetMath(docstring const & s)
                return MathAtom(new InsetMathPhantom(InsetMathPhantom::vphantom));
        if (s == "ensuremath")
                return MathAtom(new InsetMathEnsureMath);
+       if (isSpecialChar(s))
+               return MathAtom(new InsetMathSpecialChar(s));
+
+       if (s == "regexp")
+               return MathAtom(new InsetMathHull(hullRegexp));
 
        return MathAtom(new MathMacro(s));
 }
@@ -458,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;