mathed/InsetMathDelim.cpp \
mathed/InsetMathDiff.cpp \
mathed/InsetMathDots.cpp \
+ mathed/InsetMathEnsureMath.cpp \
mathed/InsetMathEnv.cpp \
mathed/InsetMathExFunc.cpp \
mathed/InsetMathExInt.cpp \
mathed/InsetMathDelim.h \
mathed/InsetMathDiff.h \
mathed/InsetMathDots.h \
+ mathed/InsetMathEnsureMath.h \
mathed/InsetMathEnv.h \
mathed/InsetMathExFunc.h \
mathed/InsetMathExInt.h \
--- /dev/null
+/**
+ * \file InsetMathEnsureMath.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ * \author Enrico Forestieri
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetMathEnsureMath.h"
+
+#include "MathStream.h"
+#include "MathData.h"
+
+#include <ostream>
+
+
+namespace lyx {
+
+InsetMathEnsureMath::InsetMathEnsureMath()
+ : InsetMathNest(1)
+{}
+
+
+Inset * InsetMathEnsureMath::clone() const
+{
+ return new InsetMathEnsureMath(*this);
+}
+
+
+void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+ FontSetChanger dummy(mi.base, "mathnormal");
+ cell(0).metrics(mi, dim);
+ metricsMarkers(dim);
+}
+
+
+void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
+{
+ FontSetChanger dummy(pi.base, "mathnormal");
+ cell(0).draw(pi, x, y);
+ drawMarkers(pi, x, y);
+}
+
+
+void InsetMathEnsureMath::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
+{
+ cell(0).metricsT(mi, dim);
+}
+
+
+void InsetMathEnsureMath::drawT(TextPainter & pain, int x, int y) const
+{
+ cell(0).drawT(pain, x, y);
+}
+
+
+void InsetMathEnsureMath::write(WriteStream & os) const
+{
+ ModeSpecifier specifier(os, MATH_MODE);
+ os << "\\ensuremath{" << cell(0) << "}";
+}
+
+
+void InsetMathEnsureMath::infoize(odocstream & os) const
+{
+ os << "EnsureMath";
+}
+
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file InsetMathEnsureMath.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ * \author Enrico Forestieri
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef MATH_ENSUREMATHINSET_H
+#define MATH_ENSUREMATHINSET_H
+
+#include "InsetMathNest.h"
+
+
+namespace lyx {
+
+
+/// Inset for ensuring math mode
+class InsetMathEnsureMath : public InsetMathNest {
+public:
+ InsetMathEnsureMath();
+ ///
+ mode_type currentMode() const { return MATH_MODE; }
+ ///
+ void metrics(MetricsInfo & mi, Dimension & dim) const;
+ ///
+ void draw(PainterInfo & pi, int x, int y) const;
+ ///
+ void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
+ ///
+ void drawT(TextPainter & pi, int x, int y) const;
+ ///
+ void write(WriteStream & os) const;
+ ///
+ void infoize(odocstream & os) const;
+private:
+ virtual Inset * clone() const;
+};
+
+
+} // namespace lyx
+
+#endif
#include "InsetMathColor.h"
#include "InsetMathDecoration.h"
#include "InsetMathDots.h"
+#include "InsetMathEnsureMath.h"
#include "InsetMathFont.h"
#include "InsetMathFontOld.h"
#include "InsetMathFrac.h"
return MathAtom(new InsetMathPhantom(InsetMathPhantom::phantom));
if (s == "vphantom")
return MathAtom(new InsetMathPhantom(InsetMathPhantom::vphantom));
+ if (s == "ensuremath")
+ return MathAtom(new InsetMathEnsureMath);
return MathAtom(new MathMacro(s));
}
}
#endif
- else if (t.cs() == "lyxmathsym" || t.cs() == "ensuremath") {
+ else if (t.cs() == "lyxmathsym") {
skipSpaces();
if (getToken().cat() != catBegin) {
error("'{' expected in \\" + t.cs());
error("'}' expected in \\" + t.cs());
return;
}
- if (t.cs() == "ensuremath") {
+ docstring rem;
+ cmd = Encodings::fromLaTeXCommand(cmd, rem);
+ for (size_t i = 0; i < cmd.size(); ++i)
+ cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
+ if (rem.size()) {
+ MathAtom at = createInsetMath(t.cs());
+ cell->push_back(at);
MathData ar;
- mathed_parse_cell(ar, cmd);
+ mathed_parse_cell(ar, '{' + rem + '}');
cell->append(ar);
- } else {
- docstring rem;
- cmd = Encodings::fromLaTeXCommand(cmd, rem);
- for (size_t i = 0; i < cmd.size(); ++i)
- cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
- if (rem.size()) {
- MathAtom at = createInsetMath(t.cs());
- cell->push_back(at);
- MathData ar;
- mathed_parse_cell(ar, '{' + rem + '}');
- cell->append(ar);
- }
}
}