commit 9a702f195d43c005a86143832aacee4dd4db0383
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun Aug 31 12:30:14 2014 +0200

    Add support for beamer lemma environment.
    
    File fomat change.

diff --git a/development/FORMAT b/development/FORMAT
index 15d6adb..627fbb5 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,10 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 
 -----------------------
 
+2014-08-31 Jürgen Spitzmüller <[email protected]>
+       * Format incremented to 479
+         Support for beamer lemma environment.
+
 2014-08-25 Uwe Stöhr <[email protected]>
        * Format incremented to 478: support for the LaTeX math commands
          \x***arrow
diff --git a/lib/layouts/beamer.layout b/lib/layouts/beamer.layout
index 14b0499..fbdbd76 100644
--- a/lib/layouts/beamer.layout
+++ b/lib/layouts/beamer.layout
@@ -1226,6 +1226,12 @@ Style Fact
   LabelString      "Fact."
 End
 
+Style Lemma
+  CopyStyle        Corollary
+  LatexName        lemma
+  LabelString      "Lemma."
+End
+
 Style Proof
   CopyStyle        Corollary
   LatexName        proof
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 5f23eaf..5c8c500 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -85,7 +85,7 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 
4)),
                    ("1_6", range(277,346), minor_versions("1.6" , 10)),
                    ("2_0", range(346,414), minor_versions("2.0", 8)),
                    ("2_1", range(414,475), minor_versions("2.1", 0)),
-                   ("2_2", range(475,479), minor_versions("2.2", 0))
+                   ("2_2", range(475,480), minor_versions("2.2", 0))
                   ]
 
 ####################################################################
diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py
index 59dbfbc..172cb23 100644
--- a/lib/lyx2lyx/lyx_2_2.py
+++ b/lib/lyx2lyx/lyx_2_2.py
@@ -30,8 +30,8 @@ import sys, os
 #  find_token_backwards, is_in_inset, get_value, get_quoted_value, \
 #  del_token, check_token, get_option_value
   
-from lyx2lyx_tools import add_to_preamble#, insert_to_preamble, \
-#  put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
+from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert#, \
+#  insert_to_preamble, lyx2latex, latex_length, revert_flex_inset, \
 #  revert_font_attrs, hex2ratio, str2bool
 
 from parser_tools import find_token, find_token_backwards, find_re, \
@@ -328,10 +328,89 @@ mathtools_commands = ["xhookrightarrow", 
"xhookleftarrow", "xRightarrow", \
                 "xLeftarrow", "xleftharpoondown", "xleftharpoonup", \
                 "xleftrightarrow", "xLeftrightarrow", "xleftrightharpoons", \
                 "xmapsto"]
+
 def revert_xarrow(document):
     "remove use_package mathtools"
     revert_use_package(document, "mathtools", mathtools_commands, False)
 
+
+def revert_beamer_lemma(document):
+    " Reverts beamer lemma layout to ERT "
+    
+    beamer_classes = ["beamer", "article-beamer", "scrarticle-beamer"]
+    if document.textclass not in beamer_classes:
+        return
+
+    consecutive = False
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_layout Lemma", i)
+        if i == -1:
+            return
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: Can't find end of Lemma 
layout")
+            i += 1
+            continue
+        arg1 = find_token(document.body, "\\begin_inset Argument 1", i, j)
+        endarg1 = find_end_of_inset(document.body, arg1)
+        arg2 = find_token(document.body, "\\begin_inset Argument 2", i, j)
+        endarg2 = find_end_of_inset(document.body, arg2)
+        subst1 = []
+        subst2 = []
+        if arg1 != -1:
+            beginPlain1 = find_token(document.body, "\\begin_layout Plain 
Layout", arg1, endarg1)
+            if beginPlain1 == -1:
+                document.warning("Malformed LyX document: Can't find arg1 
plain Layout")
+                i += 1
+                continue
+            endPlain1 = find_end_of_inset(document.body, beginPlain1)
+            content1 = document.body[beginPlain1 + 1 : endPlain1 - 2]
+            subst1 = put_cmd_in_ert("<") + content1 + put_cmd_in_ert(">")
+        if arg2 != -1:
+            beginPlain2 = find_token(document.body, "\\begin_layout Plain 
Layout", arg2, endarg2)
+            if beginPlain2 == -1:
+                document.warning("Malformed LyX document: Can't find arg2 
plain Layout")
+                i += 1
+                continue
+            endPlain2 = find_end_of_inset(document.body, beginPlain2)
+            content2 = document.body[beginPlain2 + 1 : endPlain2 - 2]
+            subst2 = put_cmd_in_ert("[") + content2 + put_cmd_in_ert("]")
+
+        # remove Arg insets
+        if arg1 < arg2:
+            del document.body[arg2 : endarg2 + 1]
+            if arg1 != -1:
+                del document.body[arg1 : endarg1 + 1]
+        if arg2 < arg1:
+            del document.body[arg1 : endarg1 + 1]
+            if arg2 != -1:
+                del document.body[arg2 : endarg2 + 1]
+
+        # index of end layout has probably changed
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: Can't find end of Lemma 
layout")
+            i += 1
+            continue
+
+        begcmd = []
+
+        # if this is not a consecutive env, add start command
+        if not consecutive:
+            begcmd = put_cmd_in_ert("\\begin{lemma}")
+
+        # has this a consecutive lemma?
+        consecutive = document.body[j + 2] == "\\begin_layout Lemma"
+
+        # if this is not followed by a consecutive env, add end command
+        if not consecutive:
+            document.body[j : j + 1] = put_cmd_in_ert("\\end{lemma}") + 
["\\end_layout"]
+
+        document.body[i : i + 1] = ["\\begin_layout Standard", ""] + begcmd + 
subst1 + subst2
+
+        i = j
+
   
 ##
 # Conversion hub
@@ -345,10 +424,12 @@ convert = [
            # want to hardcode amsmath off.
            [476, []],
            [477, []],
-           [478, []]
+           [478, []],
+           [479, []]
           ]
 
 revert =  [
+           [478, [revert_beamer_lemma]],
            [477, [revert_xarrow]],
            [476, [revert_swissgerman]],
            [475, [revert_smash]],
diff --git a/src/version.h b/src/version.h
index 30bb4e2..9293e4f 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 478 // uwestoehr: mathtools' x***arrow commands
-#define LYX_FORMAT_TEX2LYX 478
+#define LYX_FORMAT_LYX 479 // spitz: beamer Lemma layout
+#define LYX_FORMAT_TEX2LYX 479
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to