]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathFactory.cpp
Simplify Changers interface
[lyx.git] / src / mathed / MathFactory.cpp
index f2e980a2db7b47b0e8164a75cddaa9954c384678..f00093746f8ca73f37b3ac80d9cc4cff473cb690 100644 (file)
@@ -19,6 +19,7 @@
 #include "InsetMathCancel.h"
 #include "InsetMathCancelto.h"
 #include "InsetMathCases.h"
+#include "InsetMathClass.h"
 #include "InsetMathColor.h"
 #include "InsetMathDecoration.h"
 #include "InsetMathDots.h"
@@ -73,6 +74,7 @@
 #include "LyX.h" // use_gui
 #include "OutputParams.h"
 
+
 using namespace std;
 using namespace lyx::support;
 
@@ -92,7 +94,7 @@ bool isMathFontAvailable(string & name)
                return false;
 
        FontInfo f;
-       augmentFont(f, from_ascii(name));
+       augmentFont(f, name);
 
        // Do we have the font proper?
        if (theFontLoader().available(f))
@@ -233,7 +235,7 @@ void initSymbols()
                docstring help;
                is >> tmp.name >> help;
                tmp.inset = to_ascii(help);
-               if (isFontName(help))
+               if (isFontName(tmp.inset))
                        is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
                else
                        is >> tmp.extra;
@@ -253,7 +255,7 @@ void initSymbols()
                        continue;
                }
 
-               if (isFontName(from_ascii(tmp.inset))) {
+               if (isFontName(tmp.inset)) {
                        // tmp.inset _is_ the fontname here.
                        // create fallbacks if necessary
 
@@ -359,23 +361,41 @@ void initMath()
 }
 
 
-bool ensureMath(WriteStream & os, bool needs_math_mode, bool macro)
+bool ensureMath(WriteStream & os, bool needs_mathmode, bool macro,
+                bool textmode_macro)
 {
        bool brace = os.pendingBrace();
        os.pendingBrace(false);
        if (!os.latex())
                return brace;
-       if (os.textMode() && needs_math_mode) {
-               os << "\\ensuremath{";
+       if (os.textMode() && needs_mathmode) {
+               if (brace) {
+                       // close \lyxmathsym
+                       os << '}';
+                       brace = false;
+               } else {
+                       os << "\\ensuremath{";
+                       brace = true;
+               }
                os.textMode(false);
-               brace = true;
-       } else if (macro && brace && !needs_math_mode) {
-               // This is a user defined macro, but not a MathMacro, so we
-               // cannot be sure what mode is needed. As it was entered in
-               // a text box, we restore the text mode.
-               os << '}';
+       } else if (macro && textmode_macro && !os.textMode()) {
+               if (brace) {
+                       // close \ensuremath
+                       os << '}';
+                       brace = false;
+               } else {
+                       os << "\\lyxmathsym{";
+                       brace = true;
+               }
                os.textMode(true);
+       } else if (macro && brace && !needs_mathmode && !textmode_macro) {
+               // This is a user defined macro, not a MathMacro, so we
+               // cannot be sure what mode is needed. We leave it in the
+               // same environment it was entered by closing either \lyxmathsym
+               // or \ensuremath, whichever was opened.
+               os << '}';
                brace = false;
+               os.textMode(!os.textMode());
        }
        return brace;
 }
@@ -643,10 +663,13 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
                return MathAtom(new InsetMathSpecialChar(s));
        if (s == " ")
                return MathAtom(new InsetMathSpace(" ", ""));
-
        if (s == "regexp")
                return MathAtom(new InsetMathHull(buf, hullRegexp));
 
+       MathClass const mc = string_to_class(s);
+       if (mc != MC_UNKNOWN)
+               return MathAtom(new InsetMathClass(buf, mc));
+
        return MathAtom(new MathMacro(buf, s));
 }
 
@@ -669,9 +692,8 @@ bool createInsetMath_fromDialogStr(docstring const & str, MathData & ar)
                InsetSpaceParams isp(true);
                InsetSpace::string2params(to_utf8(str), isp);
                InsetSpace is(isp);
-               TexRow texrow;
                odocstringstream ods;
-               otexstream os(ods, texrow);
+               otexstream os(ods);
                Encoding const * const ascii = encodings.fromLyXName("ascii");
                OutputParams op(ascii);
                is.latex(os, op);