]> git.lyx.org Git - features.git/commitdiff
Add support for \mathbin and friends
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 4 Oct 2016 22:25:38 +0000 (00:25 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 16 Nov 2016 14:21:53 +0000 (15:21 +0100)
All they do is change the class of the elements that they contain.

src/Makefile.am
src/insets/InsetCode.h
src/mathed/InsetMathClass.cpp [new file with mode: 0644]
src/mathed/InsetMathClass.h [new file with mode: 0644]
src/mathed/MathFactory.cpp

index 5990df7683680a2be1877c638330b6f90371b1a4..f87d0290b3a6ac8cc65bfba97c78018edb731d51 100644 (file)
@@ -403,6 +403,7 @@ SOURCEFILESMATHED = \
        mathed/InsetMathCancelto.cpp \
        mathed/InsetMathCases.cpp \
        mathed/InsetMathChar.cpp \
+       mathed/InsetMathClass.cpp \
        mathed/InsetMathColor.cpp \
        mathed/InsetMathComment.cpp \
        mathed/InsetMathDecoration.cpp \
@@ -475,6 +476,7 @@ HEADERFILESMATHED = \
        mathed/InsetMathCancelto.h \
        mathed/InsetMathCases.h \
        mathed/InsetMathChar.h \
+       mathed/InsetMathClass.h \
        mathed/InsetMathColor.h \
        mathed/InsetMathComment.h \
        mathed/InsetMathDelim.h \
index 1df6800d2d8cdfec456494aa607e51aaa96bb7b8..7d4632cd1676f04f1046a12d3915a998cfecedf3 100644 (file)
@@ -235,6 +235,8 @@ enum InsetCode {
        ///
        IPADECO_CODE,
        ///
+       MATH_CLASS_CODE,
+       ///
        INSET_CODE_SIZE
 };
 
diff --git a/src/mathed/InsetMathClass.cpp b/src/mathed/InsetMathClass.cpp
new file mode 100644 (file)
index 0000000..931a68b
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * \file InsetMathClass.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetMathClass.h"
+
+#include "support/docstream.h"
+
+
+namespace lyx {
+
+InsetMathClass::InsetMathClass(Buffer * buf, MathClass mc)
+       : InsetMathNest(buf, 1), math_class_(mc)
+{}
+
+
+Inset * InsetMathClass::clone() const
+{
+       return new InsetMathClass(*this);
+}
+
+
+void InsetMathClass::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       cell(0).metrics(mi, dim);
+       metricsMarkers(dim);
+}
+
+
+void InsetMathClass::draw(PainterInfo & pi, int x, int y) const
+{
+       cell(0).draw(pi, x + 1, y);
+       drawMarkers(pi, x, y);
+}
+
+
+docstring InsetMathClass::name() const
+{
+       return class_to_string(math_class_);
+}
+
+
+void InsetMathClass::infoize(odocstream & os) const
+{
+       os << name() << " ";
+}
+
+
+} // namespace lyx
diff --git a/src/mathed/InsetMathClass.h b/src/mathed/InsetMathClass.h
new file mode 100644 (file)
index 0000000..f50040d
--- /dev/null
@@ -0,0 +1,50 @@
+// -*- C++ -*-
+/**
+ * \file InsetMathClass.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef MATH_CLASSINSET_H
+#define MATH_CLASSINSET_H
+
+#include "MathClass.h"
+
+#include "InsetMathNest.h"
+
+
+namespace lyx {
+
+
+/// Support for LaTeX's \\mathxxx class-changing commands
+
+class InsetMathClass : public InsetMathNest {
+public:
+       ///
+       InsetMathClass(Buffer * buf, MathClass);
+       ///
+       docstring name() const;
+       ///
+       MathClass mathClass() const { return math_class_; }
+       ///
+       void metrics(MetricsInfo & mi, Dimension & dim) const;
+       ///
+       void draw(PainterInfo & pi, int x, int y) const;
+       ///
+       void infoize(odocstream & os) const;
+       ///
+       InsetCode lyxCode() const { return MATH_CLASS_CODE; }
+
+private:
+       virtual Inset * clone() const;
+       ///
+       MathClass math_class_;
+};
+
+
+} // namespace lyx
+#endif
index bb7be8ba6ba25744d15bdf55c2d33f8bee729c54..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"
@@ -662,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));
 }