Thanks,

Richard -- The python code you sent me did not done the job. I fixed it.

Pavel -- Thanks. I removed big portion of the code that was not needed.
But now, both classes are little more different.

I can refactor both XYMatrix and Diagram class to have one common base
class, but it will take me a while. How urgent things should be ready for
2.0?

Patch and Example file attached, and anyway:

I hereby grant permission to license my contributions to LyX under the Gnu
General Public Licence, version 2 or later.

On Sat, Sep 18, 2010 at 6:33 PM, Richard Heck <rgh...@comcast.net> wrote:

> On 09/18/2010 04:48 PM, Pavel Sanda wrote:
>
>> also this is fileformat change - that is .lyx files generated with this
>> patch cannot
>> be correctly read by older version of lyx and we need to handle that. it
>> should be simple here -
>> either only bump file version or we just need that when file is converted
>> to lyx 1.6 "\use_package{feyn}"
>> is put into the preamble so its compilable even in 1.6. look on the
>> beginning of this commit:
>> http://www.lyx.org/trac/changeset/34748
>> to have idea how we handle bumping new fileformat versions.
>>
>> (the code of diagram math inset should be readable even in older version
>> of lyx because we store
>> all math insets as pure tex construct...)
>>
>>
>>
> I guess the point is that the math diagram stuff will simply be imported
> into 1.6.x as Math ERT, i.e., InsetMathUnknown, right? If so, then you are
> right that the only thing that needs doing is to add \use_package{feyn} when
> the math diagram stuff is encountered, not always.
>
> I don't know if you do python Ronen, so I've attached the lyx2lyx stuff.
> Bump the format in Buffer.cpp to 401 and you're done. Untested, though, so
> please check that export to 1.6.x works as it should (i.e., that
> \use_package{feyn} gets added to the preamble).
>
> One other thing: inheriting from InsetXYMatrix will pull in the htmlize()
> and mathmlize() functions, which you omitted. They should be the same here.
> So that's another reason to do it that way. Or maybe there should be some
> common virtual class from which they both inherit, since neither is really
> basic.
>
> And thanks for the contribution. Hope there will be more!
>
> Richard
>
>
diff -rupN lyx-2.0.0alpha6/lib/lyx2lyx/lyx_2_0.py lyx-2.0.0alpha6_feynFinal/lib/lyx2lyx/lyx_2_0.py
--- lyx-2.0.0alpha6/lib/lyx2lyx/lyx_2_0.py	2010-09-15 16:33:40.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/lib/lyx2lyx/lyx_2_0.py	2010-09-18 23:38:50.000000000 -0400
@@ -2161,6 +2160,27 @@ 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:
+      print "returning"
+      return
+    j = find_end_of_inset(document.body, i)
+    if j == -1:
+        print "Melformed document!"
+        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 +2241,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, []],
diff -rupN lyx-2.0.0alpha6/src/Buffer.cpp lyx-2.0.0alpha6_feynFinal/src/Buffer.cpp
--- lyx-2.0.0alpha6/src/Buffer.cpp	2010-09-15 16:33:41.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/Buffer.cpp	2010-09-18 22:33:25.000000000 -0400
@@ -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; // uwestoehr: support for \rule \\Ronen: support for \Diagrasr
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
diff -rupN lyx-2.0.0alpha6/src/insets/InsetCode.h lyx-2.0.0alpha6_feynFinal/src/insets/InsetCode.h
--- lyx-2.0.0alpha6/src/insets/InsetCode.h	2010-09-15 16:33:43.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/insets/InsetCode.h	2010-09-18 21:22:40.000000000 -0400
@@ -223,6 +223,8 @@ enum InsetCode {
 	///
 	PREVIEW_CODE,
 	///
+	MATH_DIAGRAM_CODE, 
+	///
 	INSET_CODE_SIZE,
 };
 
diff -rupN lyx-2.0.0alpha6/src/insets/Inset.cpp lyx-2.0.0alpha6_feynFinal/src/insets/Inset.cpp
--- lyx-2.0.0alpha6/src/insets/Inset.cpp	2010-09-15 16:33:42.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/insets/Inset.cpp	2010-09-18 21:23:37.000000000 -0400
@@ -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;
diff -rupN lyx-2.0.0alpha6/src/LaTeXFeatures.cpp lyx-2.0.0alpha6_feynFinal/src/LaTeXFeatures.cpp
--- lyx-2.0.0alpha6/src/LaTeXFeatures.cpp	2010-09-15 16:33:41.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/LaTeXFeatures.cpp	2010-09-18 12:00:16.000000000 -0400
@@ -746,6 +746,9 @@ string const LaTeXFeatures::getPackages(
 	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";
diff -rupN lyx-2.0.0alpha6/src/Makefile.am lyx-2.0.0alpha6_feynFinal/src/Makefile.am
--- lyx-2.0.0alpha6/src/Makefile.am	2010-09-15 16:33:42.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/Makefile.am	2010-09-18 12:00:16.000000000 -0400
@@ -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 \
diff -rupN lyx-2.0.0alpha6/src/mathed/InsetMathDiagram.cpp lyx-2.0.0alpha6_feynFinal/src/mathed/InsetMathDiagram.cpp
--- lyx-2.0.0alpha6/src/mathed/InsetMathDiagram.cpp	1969-12-31 19:00:00.000000000 -0500
+++ lyx-2.0.0alpha6_feynFinal/src/mathed/InsetMathDiagram.cpp	2010-09-18 22:19:13.000000000 -0400
@@ -0,0 +1,96 @@
+/**
+ * \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, Length const & s, char c,
+	bool e) : 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 -rupN lyx-2.0.0alpha6/src/mathed/InsetMathDiagram.h lyx-2.0.0alpha6_feynFinal/src/mathed/InsetMathDiagram.h
--- lyx-2.0.0alpha6/src/mathed/InsetMathDiagram.h	1969-12-31 19:00:00.000000000 -0500
+++ lyx-2.0.0alpha6_feynFinal/src/mathed/InsetMathDiagram.h	2010-09-18 21:49:11.000000000 -0400
@@ -0,0 +1,61 @@
+// -*- 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, Length const & = Length(), char c = '\0',
+		bool equal_spacing = false);
+	///
+	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
diff -rupN lyx-2.0.0alpha6/src/mathed/InsetMathNest.cpp lyx-2.0.0alpha6_feynFinal/src/mathed/InsetMathNest.cpp
--- lyx-2.0.0alpha6/src/mathed/InsetMathNest.cpp	2010-09-15 16:33:43.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/mathed/InsetMathNest.cpp	2010-09-18 12:00:16.000000000 -0400
@@ -1994,6 +1994,7 @@ MathCompletionList::MathCompletionList(C
 	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"));
diff -rupN lyx-2.0.0alpha6/src/mathed/MathFactory.cpp lyx-2.0.0alpha6_feynFinal/src/mathed/MathFactory.cpp
--- lyx-2.0.0alpha6/src/mathed/MathFactory.cpp	2010-09-15 16:33:43.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/mathed/MathFactory.cpp	2010-09-18 22:17:23.000000000 -0400
@@ -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
 		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")
diff -rupN lyx-2.0.0alpha6/src/mathed/MathParser.cpp lyx-2.0.0alpha6_feynFinal/src/mathed/MathParser.cpp
--- lyx-2.0.0alpha6/src/mathed/MathParser.cpp	2010-09-15 16:33:43.000000000 -0400
+++ lyx-2.0.0alpha6_feynFinal/src/mathed/MathParser.cpp	2010-09-18 22:19:25.000000000 -0400
@@ -1727,6 +1727,14 @@ bool Parser::parse1(InsetMathGrid & grid
 				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);

Attachment: Diagram_test.lyx
Description: application/lyx

Reply via email to