]> git.lyx.org Git - features.git/commitdiff
Add support for feyn package and Diagram inset.
authorPavel Sanda <sanda@lyx.org>
Sun, 19 Sep 2010 22:12:06 +0000 (22:12 +0000)
committerPavel Sanda <sanda@lyx.org>
Sun, 19 Sep 2010 22:12:06 +0000 (22:12 +0000)
Patch from Ronen Abravanel.
http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161952.html

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35455 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/lyx_2_0.py
src/Buffer.cpp
src/LaTeXFeatures.cpp
src/Makefile.am
src/insets/Inset.cpp
src/insets/InsetCode.h
src/mathed/InsetMathDiagram.cpp [new file with mode: 0644]
src/mathed/InsetMathDiagram.h [new file with mode: 0644]
src/mathed/InsetMathNest.cpp
src/mathed/MathFactory.cpp
src/mathed/MathParser.cpp

index 9c0d7497df57a8c6d26b0f34198953351000fb3a..ab1230804b814f04b42a8a8a7acf3b386540876e 100644 (file)
@@ -1568,7 +1568,6 @@ def revert_fontcolor(document):
                            + ', ' + str(blueout) + '}\n'
                            + '\\color{document_fontcolor}\n')
 
-
 def revert_shadedboxcolor(document):
     " Reverts shaded box color to preamble code "
     i = 0
@@ -2161,6 +2160,26 @@ def revert_rule(document):
       else:
         return
 
+def revert_diagram(document):
+  i = 0
+  re_diagram = re.compile(r'\\begin_inset Formula .*\\Diagram', re.DOTALL)
+  while True:
+    i = find_token(document.body, '\\begin_inset Formula', i)
+    if i == -1:
+      return
+    j = find_end_of_inset(document.body, i)
+    if j == -1:
+        document.warning("Malformed LyX document: Can't find end of line inset.")
+        return 
+    m = re_diagram.search("\n".join(document.body[i:j]))
+    if not m:
+      i += 1
+      continue
+    add_to_preamble(document, "\\use_package{feyn}")
+    # only need to do it once!
+    return
+
+
 
 ##
 # Conversion hub
@@ -2221,10 +2240,12 @@ convert = [[346, []],
            [397, [remove_Nameref]],
            [398, []],
            [399, [convert_mathdots]],
-           [400, [convert_rule]]
+           [400, [convert_rule]],
+           [401, []]
           ]
 
-revert =  [[399, [revert_rule]],
+revert =  [[400, [revert_diagram]],
+           [399, [revert_rule]],
            [398, [revert_mathdots]],
            [397, [revert_mathrsfs]],
            [396, []],
index a068ecfe3a9c9e502cac0801395b4aaf56f09a83..a679427fcd19d918295b6f87e5659d8f0e7ad343 100644 (file)
@@ -127,7 +127,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 400; // uwestoehr: support for \rule
+int const LYX_FORMAT = 401; // Ronen: support for \Diagram
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
index c2b0a85e46b33a3fb194402f1d12ec862cb1a26a..b21c6cc7a1933a018ba30e7dbf1f09f06ca4ae19 100644 (file)
@@ -746,6 +746,9 @@ string const LaTeXFeatures::getPackages() const
        if (mustProvide("xy"))
                packages << "\\usepackage[all]{xy}\n";
 
+       if (mustProvide("feyn"))
+               packages << "\\usepackage{feyn}\n"; //Diagram
+
        if (mustProvide("ulem"))
                packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
                            "\\usepackage{ulem}\n";
index 8ee4be23d250349605dd637680a028a1f1236889..87be7173578e5cf742d7f959c4f981b575369601 100644 (file)
@@ -409,6 +409,7 @@ SOURCEFILESMATHED = \
        mathed/InsetMathUnknown.cpp \
        mathed/InsetMathXArrow.cpp \
        mathed/InsetMathXYMatrix.cpp \
+       mathed/InsetMathDiagram.cpp \
        mathed/MathAtom.cpp \
        mathed/MathAutoCorrect.cpp \
        mathed/MathData.cpp \
@@ -474,6 +475,7 @@ HEADERFILESMATHED = \
        mathed/InsetMathUnknown.h \
        mathed/InsetMathXArrow.h \
        mathed/InsetMathXYMatrix.h \
+       mathed/InsetMathDiagram.h \
        mathed/MathAtom.h \
        mathed/MathAutoCorrect.h \
        mathed/MathData.h \
index 65687c89499d59d3d21b55767c025789c87b3642..fd1c4e5b7bc0686e1c8c8f6d31e2a54e7024e6f5 100644 (file)
@@ -168,6 +168,7 @@ static void build_translator()
        insetnames[MATH_XARROW_CODE] = InsetName("mathxarrow");
        insetnames[MATH_XYARROW_CODE] = InsetName("mathxyarrow");
        insetnames[MATH_XYMATRIX_CODE] = InsetName("mathxymatrix");
+       insetnames[MATH_DIAGRAM_CODE] = InsetName("mathdiagram");
        insetnames[MATH_MACRO_CODE] = InsetName("mathmacro");
 
        passed = true;
index c2cae77e0c39a20f359375256ebf01f5f76a8b91..33d3a4be0af02635a4047fa768805931e0e83c3b 100644 (file)
@@ -223,6 +223,8 @@ enum InsetCode {
        ///
        PREVIEW_CODE,
        ///
+       MATH_DIAGRAM_CODE, 
+       ///
        INSET_CODE_SIZE,
 };
 
diff --git a/src/mathed/InsetMathDiagram.cpp b/src/mathed/InsetMathDiagram.cpp
new file mode 100644 (file)
index 0000000..25ad63c
--- /dev/null
@@ -0,0 +1,95 @@
+/**
+ * \file InsetMathDiagram.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ * \author Ronen Abravanel
+*
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetMathDiagram.h"
+
+#include "LaTeXFeatures.h"
+#include "MathStream.h"
+
+#include <ostream>
+
+namespace lyx {
+
+
+InsetMathDiagram::InsetMathDiagram(Buffer * buf) : InsetMathGrid(buf, 1, 1)
+{
+}
+
+
+Inset * InsetMathDiagram::clone() const
+{
+       return new InsetMathDiagram(*this);
+}
+
+
+int InsetMathDiagram::colsep() const
+{
+       return 10;
+}
+
+
+int InsetMathDiagram::rowsep() const
+{
+       return 10;
+}
+
+
+void InsetMathDiagram::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       if (mi.base.style == LM_ST_DISPLAY)
+               mi.base.style = LM_ST_TEXT;
+       InsetMathGrid::metrics(mi, dim);
+}
+
+
+void InsetMathDiagram::write(WriteStream & os) const
+{
+       MathEnsurer ensurer(os);
+       os << "\\Diagram";
+       os << '{';
+       InsetMathGrid::write(os);
+       os << "}\n";
+}
+
+
+void InsetMathDiagram::infoize(odocstream & os) const
+{
+       os << "Diagram ";
+       InsetMathGrid::infoize(os);
+}
+
+
+void InsetMathDiagram::normalize(NormalStream & os) const
+{
+       os << "[Diagram ";
+       InsetMathGrid::normalize(os);
+       os << ']';
+}
+
+
+void InsetMathDiagram::maple(MapleStream & os) const
+{
+       os << "Diagram(";
+       InsetMathGrid::maple(os);
+       os << ')';
+}
+
+
+void InsetMathDiagram::validate(LaTeXFeatures & features) const
+{
+       features.require("feyn");
+       InsetMathGrid::validate(features);
+}
+
+
+} // namespace lyx
diff --git a/src/mathed/InsetMathDiagram.h b/src/mathed/InsetMathDiagram.h
new file mode 100644 (file)
index 0000000..7ab099c
--- /dev/null
@@ -0,0 +1,60 @@
+// -*- C++ -*-
+/**
+ * \file InsetMathDiagram.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+*  \author Ronen Abravanel
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef MATH_DIAGRAM_H
+#define MATH_DIAGRAM_H
+
+#include "Length.h"
+#include "InsetMathGrid.h"
+
+
+namespace lyx {
+
+
+class InsetMathDiagram : public InsetMathGrid {
+public:
+       ///
+       InsetMathDiagram(Buffer * buf);
+       ///
+       void metrics(MetricsInfo &, Dimension &) const;
+       ///
+       InsetMathDiagram const * asDiagramInset() const { return this; }
+       ///
+       virtual int colsep() const;
+       ///
+       virtual int rowsep() const;
+
+       ///
+       void normalize();
+       ///
+       void write(WriteStream & os) const;
+       ///
+       void infoize(odocstream & os) const;
+       ///
+       void normalize(NormalStream &) const;
+       ///
+       void maple(MapleStream &) const;
+       ///
+       void validate(LaTeXFeatures & features) const;
+       ///
+       InsetCode lyxCode() const { return MATH_DIAGRAM_CODE; }
+
+private:
+       ///
+       virtual Inset * clone() const;
+
+};
+
+
+
+} // namespace lyx
+#endif
index d023a5f415f3d5a8da60949feb7a2dfa3ccaaa58..7748da2f5c49a34a103d7da7bc34c9198fdadffb 100644 (file)
@@ -1994,6 +1994,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
        globals.push_back(from_ascii("\\cases"));
        globals.push_back(from_ascii("\\substack"));
        globals.push_back(from_ascii("\\xymatrix"));
+       globals.push_back(from_ascii("\\Diagram"));
        globals.push_back(from_ascii("\\subarray"));
        globals.push_back(from_ascii("\\array"));
        globals.push_back(from_ascii("\\sqrt"));
index 6a5112925c690ed7938c67a281646dfa742ab2cc..ee2841a2080b467928fdf186b9b97f116ab5cd63 100644 (file)
@@ -44,6 +44,7 @@
 #include "InsetMathHull.h"
 #include "InsetMathXArrow.h"
 #include "InsetMathXYMatrix.h"
+#include "InsetMathDiagram.h"
 #include "MacroTable.h"
 #include "MathMacro.h"
 #include "MathMacroArgument.h"
@@ -417,6 +418,9 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
                return MathAtom(new InsetMathXYMatrix(buf, spacing, spacing_code,
                        equal_spacing));
        }
+
+       if (s == "Diagram")
+               return MathAtom(new InsetMathDiagram(buf));
        if (s == "xrightarrow" || s == "xleftarrow")
                return MathAtom(new InsetMathXArrow(buf, s));
        if (s == "split" || s == "alignedat")
index 1803da7f3a217917912e1989bf0b2bfb2e37eea4..c4fad04b46838467b835e8eb9a2be11d58d526d0 100644 (file)
@@ -1727,6 +1727,14 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                delEmptyLastRow(subgrid);
                }
 
+               else if (t.cs() == "Diagram") {
+                       odocstringstream os;
+                       while (good() && nextToken().cat() != catBegin)
+                               os << getToken().asInput();
+                       cell->push_back(createInsetMath(t.cs() + os.str(), buf));
+                       parse2(cell->back(), FLAG_ITEM, mode, false);
+               }
+
                else if (t.cs() == "framebox" || t.cs() == "makebox") {
                        cell->push_back(createInsetMath(t.cs(), buf));
                        parse(cell->back().nucleus()->cell(0), FLAG_OPTION, InsetMath::TEXT_MODE);