From: Jean-Marc Lasgouttes Date: Tue, 4 Oct 2016 22:25:38 +0000 (+0200) Subject: Add support for \mathbin and friends X-Git-Tag: 2.3.0alpha1~741^2~3 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0b5c2a85077330a59befa82dfa4d212f78cf8855;p=features.git Add support for \mathbin and friends All they do is change the class of the elements that they contain. --- diff --git a/src/Makefile.am b/src/Makefile.am index 5990df7683..f87d0290b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/insets/InsetCode.h b/src/insets/InsetCode.h index 1df6800d2d..7d4632cd16 100644 --- a/src/insets/InsetCode.h +++ b/src/insets/InsetCode.h @@ -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 index 0000000000..931a68b9a4 --- /dev/null +++ b/src/mathed/InsetMathClass.cpp @@ -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 + +#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 index 0000000000..f50040d3b4 --- /dev/null +++ b/src/mathed/InsetMathClass.h @@ -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 diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index bb7be8ba6b..f00093746f 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -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)); }