]> git.lyx.org Git - features.git/commitdiff
Old beamer frames bite the dust
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 16 Mar 2013 11:52:00 +0000 (12:52 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 16 Mar 2013 11:52:00 +0000 (12:52 +0100)
With this commit, old beamer frames are converted to new ones. The old styles are removed (including the infamous \lyxframe).

This should be tested with as much beamer documents as possible (I have already done so), also, tex2lyx now probably produces invalid LyX files.

development/FORMAT
lib/layouts/article-beamer.layout
lib/layouts/beamer.layout
lib/layouts/scrarticle-beamer.layout
lib/lyx2lyx/lyx_2_1.py
src/tex2lyx/TODO.txt
src/version.h

index 055836227e6b9d857db41ed6abfe69d2683d37b4..ae42c5d851042a0f4a38d82f2d40246660d195b7 100644 (file)
@@ -11,9 +11,14 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2013-03-16 Jürgen Spitzmüller <spitz@lyx.org>
+         * Format incremented to 465: Convert old beamer frames to new ones.
+           The layouts BeginFrame, BeginPlainFrame and EndFrame are now not
+           valied anymore (use "Frame", "PlainFrame" instead, and nesting).
+
 2013-02-27 Kornel Benko <kornel@lyx.org>
-        * Format incremented to 464:
-         - Added "cancel" to the GUI handled list of LaTeX packages
+         * Format incremented to 464:
+          - Added "cancel" to the GUI handled list of LaTeX packages
 
 2013-02-18 Julien Rioux <jrioux@lyx.org>
        * Format incremented to 463:
index eff054cb662178d5c4351a0e0155f5a1b19a207a..31a4c7e3ea66c118d3d271cb26ba1771e5b03a8c 100644 (file)
@@ -24,35 +24,3 @@ Preamble
                \def\gobbletableofcontents#1{\origtableofcontents}
        }
 EndPreamble
-
-##########################################
-# OBSOLETE STUFF
-# Everything below should be removed
-# (but this is a file format change)
-#
-#  TODO:
-#   * conversion of old frame
-#     and plain frame to new layout
-##########################################
-
-#
-# Backwards compatible definitions
-#
-
-AddToPreamble
-\providecommand\lyxframeend{}
-EndPreamble
-
-# Frame control definition
-Style BeginFrame
-# This redefinition is needed to make beamerarticle work
-  Preamble
-    \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}%
-    \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}%
-    \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}}
-    \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}}
-    \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}}
-    \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{%
-      \frame<#1>[#3]{\frametitle{#4}#5}}
-  EndPreamble
-End
index e1fb28b98ab0078a691ef32f94e4ce1716f707d2..6e0be1b64cc08b73d7a3c020a831c58416fd984b 100644 (file)
@@ -1561,158 +1561,3 @@ End
 
 
 Input theorems-refprefix.inc
-
-
-##########################################
-# OBSOLETE STUFF
-# Everything below should be removed
-# (but this is a file format change)
-#
-#  TODO:
-#   * conversion of old frame
-#     and plain frame to new layout
-##########################################
-
-#
-# Backwards compatible definitions
-#
-
-AddToPreamble
-\providecommand\lyxframeend{}
-EndPreamble
-
-IfStyle Section
-  LatexName        lyxframeend{}\section
-End
-
-IfStyle Section*
-  LatexName        lyxframeend{}\section
-End
-
-IfStyle Subsection
-  LatexName        lyxframeend{}\subsection
-End
-
-IfStyle Subsection*
-  LatexName        lyxframeend{}\subsection
-End
-
-IfStyle Subsubsection
-  LatexName        lyxframeend{}\subsubsection
-End
-
-IfStyle Subsubsection*
-  LatexName        lyxframeend{}\subsubsection
-End
-
-IfStyle AgainFrame
-  LatexName        lyxframeend{}\againframe
-End
-
-
-#
-# Deprecated Styles
-#
-
-Style BeginFrame
-  Category         "Deprecated Styles"
-  TocLevel         4
-  KeepEmpty        1
-  LatexType        Command
-  LatexName        lyxframeend{}\lyxframe
-  Argument 1
-    LabelString    "Frame Options"
-    Tooltip        "Frame options (see beamer manual)"
-  EndArgument
-  Margin           First_Dynamic
-  NextNoIndent     1
-  ParSkip          0
-  TopSep           2.5
-  BottomSep        0.5
-  ParSep           0
-  Align            Center
-  LabelType        Static
-  LabelBottomSep   0
-  LeftMargin       M
-  LabelSep         xx
-  LabelString      "Frame"
-  Font
-    Series         Bold
-    Size           Largest
-    Color          Blue
-  EndFont
-  LabelFont 
-    Family         Roman
-    Color          latex
-  EndFont
-  Preamble
-    \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}%
-    \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}%
-    \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}}
-    \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}}
-    \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}}
-    \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{%
-      \frame<#1>[#2][#3]{\frametitle{#4}#5}}
-  EndPreamble
-End
-
-Style BeginPlainFrame
-  Category          "Deprecated Styles"
-  TocLevel          4
-  KeepEmpty         1
-  LatexType         Command
-  LatexName         lyxframeend{}\lyxplainframe
-  Margin            First_Dynamic
-  NextNoIndent      1
-  ParSkip           0
-  TopSep            2.5
-  BottomSep         0.5
-  ParSep            0
-  Align             Center
-  LabelType         Static
-  LabelBottomSep    0
-  LeftMargin        M
-  LabelSep          xx
-  LabelString       "Frame (no head/foot/sidebars)"
-  Font
-    Series          Bold
-    Size            Largest
-    Color           Blue
-  EndFont
-  LabelFont 
-    Family          Roman
-    Color           latex
-  EndFont
-  Preamble
-    \long\def\lyxplainframe#1{\@lyxplainframe#1\@lyxframestop}%
-    \def\@lyxplainframe{\@ifnextchar<{\@@lyxplainframe}{\@@lyxplainframe<*>}}%
-    \long\def\@@lyxplainframe<#1>#2\@lyxframestop#3\lyxframeend{%
-      \frame<#1>[plain]{\frametitle{#2}#3}}
-  EndPreamble
-End
-
-Style EndFrame
-  Category          "Deprecated Styles"
-  KeepEmpty         1
-  LatexType         Command
-  LatexName         lyxframeend
-  Margin            First_Dynamic
-  ParSkip           0
-  TopSep            0
-  BottomSep         3
-  ParSep            0
-  Align             Center
-  LabelType         Static
-  LabelBottomSep    0
-  LeftMargin        MMMMM
-  LabelString       "________________________________"
-  LabelFont 
-    Family          typewriter
-    Series          Medium
-    Size            Normal
-    Color           latex
-  EndFont
-  Preamble
-    \def\lyxframeend{} % In case there is a superfluous frame end
-  EndPreamble
-End
index 3e35b87062de9e8544be16bb7fee22fc6572de92..0359dc92ca4087cec833e8364972279820429b66 100644 (file)
@@ -24,35 +24,3 @@ Preamble
                \def\gobbletableofcontents#1{\origtableofcontents}
        }
 EndPreamble
-
-##########################################
-# OBSOLETE STUFF
-# Everything below should be removed
-# (but this is a file format change)
-#
-#  TODO:
-#   * conversion of old frame
-#     and plain frame to new layout
-##########################################
-
-#
-# Backwards compatible definitions
-#
-
-AddToPreamble
-\providecommand\lyxframeend{}
-EndPreamble
-
-# Frame control definition
-Style BeginFrame
-# This redefinition is needed to make beamerarticle work
-  Preamble
-    \long\def\lyxframe#1{\@lyxframe#1\@lyxframestop}%
-    \def\@lyxframe{\@ifnextchar<{\@@lyxframe}{\@@lyxframe<*>}}%
-    \def\@@lyxframe<#1>{\@ifnextchar[{\@@@lyxframe<#1>}{\@@@lyxframe<#1>[]}}
-    \def\@@@lyxframe<#1>[{\@ifnextchar<{\@@@@@lyxframe<#1>[}{\@@@@lyxframe<#1>[<*>][}}
-    \def\@@@@@lyxframe<#1>[#2]{\@ifnextchar[{\@@@@lyxframe<#1>[#2]}{\@@@@lyxframe<#1>[#2][]}}
-    \long\def\@@@@lyxframe<#1>[#2][#3]#4\@lyxframestop#5\lyxframeend{%
-      \frame<#1>[#3]{\frametitle{#4}#5}}
-  EndPreamble
-End
index ccb17eb40c126d706dec79953e840f2f1b10be3a..ba50eeab0d2aef05b10c5bce80ea70e389f8ce8a 100644 (file)
@@ -3672,6 +3672,150 @@ def revert_new_libertines(document):
         document.header[k] = "\\font_sans default"
 
 
+def convert_lyxframes(document):
+    " Converts old beamer frames to new style "
+    
+    beamer_classes = ["beamer", "article-beamer", "scrarticle-beamer"]
+    if document.textclass not in beamer_classes:
+        return
+   
+    framebeg = ["BeginFrame", "BeginPlainFrame"]
+    frameend = ["EndFrame", "BeginFrame", "BeginPlainFrame", "AgainFrame", "Section", "Section*", "Subsection", "Subsection*", "Subsubsection", "Subsubsection*"]
+    for lay in framebeg:
+        i = 0
+        while True:
+            i = find_token_exact(document.body, "\\begin_layout " + lay, i)
+            if i == -1:
+                break
+            parent = get_containing_layout(document.body, i)
+            if parent == False or parent[1] != i:
+                document.warning("Wrong parent layout!")
+                i += 1
+                continue
+            frametype = parent[0]
+            j = parent[2]
+            parbeg = parent[3]
+            if i != -1:
+                # Step I: Convert ERT arguments
+                # FIXME: This currently only works if the arguments are in one single ERT
+                if document.body[parbeg] == "\\begin_inset ERT":
+                    ertcont = parbeg + 5
+                    if document.body[ertcont].startswith("[<"):
+                        # This is a default overlay specification
+                        # strip off the [<
+                        document.body[ertcont] = document.body[ertcont][2:]
+                        if document.body[ertcont].endswith(">]"):
+                            # strip off the >]
+                            document.body[ertcont] = document.body[ertcont][:-2]
+                        elif document.body[ertcont].endswith("]"):
+                            # divide the args
+                            tok = document.body[ertcont].find('>][')
+                            if tok != -1:
+                                subst = [document.body[ertcont][:tok],
+                                         '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3',
+                                         'status collapsed', '', '\\begin_layout Plain Layout',
+                                         document.body[ertcont][tok + 3:-1]]
+                                document.body[ertcont : ertcont + 1] = subst
+                        # Convert to ArgInset
+                        document.body[parbeg] = "\\begin_inset Argument 2"
+                    elif document.body[ertcont].startswith("<"):
+                        # This is an overlay specification
+                        # strip off the <
+                        document.body[ertcont] = document.body[ertcont][1:]
+                        if document.body[ertcont].endswith(">"):
+                            # strip off the >
+                            document.body[ertcont] = document.body[ertcont][:-1]
+                            # Convert to ArgInset
+                            document.body[parbeg] = "\\begin_inset Argument 1"
+                        elif document.body[ertcont].endswith(">]"):
+                            # divide the args
+                            tok = document.body[ertcont].find('>[<')
+                            if tok != -1:
+                               document.body[ertcont : ertcont + 1] = [document.body[ertcont][:tok],
+                                                               '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2',
+                                                               'status collapsed', '', '\\begin_layout Plain Layout',
+                                                               document.body[ertcont][tok + 3:-2]]
+                            # Convert to ArgInset
+                            document.body[parbeg] = "\\begin_inset Argument 1"
+                        elif document.body[ertcont].endswith("]"):
+                            # divide the args
+                            tok = document.body[ertcont].find('>[<')
+                            if tok != -1:
+                               # divide the args
+                               tokk = document.body[ertcont].find('>][')
+                               if tokk != -1:
+                                   document.body[ertcont : ertcont + 1] = [document.body[ertcont][:tok],
+                                                                   '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 2',
+                                                                   'status collapsed', '', '\\begin_layout Plain Layout',
+                                                                   document.body[ertcont][tok + 3:tokk],
+                                                                   '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3',
+                                                                   'status collapsed', '', '\\begin_layout Plain Layout',
+                                                                   document.body[ertcont][tokk + 3:-1]]
+                            else:
+                                tokk = document.body[ertcont].find('>[')
+                                if tokk != -1:
+                                    document.body[ertcont : ertcont + 1] = [document.body[ertcont][:tokk],
+                                                                    '\\end_layout', '', '\\end_inset', '', '', '\\begin_inset Argument 3',
+                                                                    'status collapsed', '', '\\begin_layout Plain Layout',
+                                                                    document.body[ertcont][tokk + 2:-1]]
+                            # Convert to ArgInset
+                            document.body[parbeg] = "\\begin_inset Argument 1"
+                    elif document.body[ertcont].startswith("["):
+                        # This is an ERT option
+                        # strip off the [
+                        document.body[ertcont] = document.body[ertcont][1:]
+                        if document.body[ertcont].endswith("]"):
+                            # strip off the ]
+                            document.body[ertcont] = document.body[ertcont][:-1]
+                            # Convert to ArgInset
+                            document.body[parbeg] = "\\begin_inset Argument 3"
+                # End of argument conversion
+                # Step II: Now rename the layout
+                if lay == "BeginFrame":
+                    document.body[i] = "\\begin_layout Frame"
+                else:
+                    document.body[i] = "\\begin_layout PlainFrame"
+                # Step III: find real frame end
+                jj = j
+                while True:
+                    fend = find_token(document.body, "\\begin_layout", jj)
+                    if fend == -1:
+                        document.warning("Malformed LyX document: No real frame end!")
+                        return
+                    val = get_value(document.body, "\\begin_layout", fend)
+                    if val not in frameend:
+                        jj = fend + 1
+                        continue
+                    old = document.body[fend]
+                    if val == frametype:
+                        document.body[fend : fend] = ['\\end_deeper', '', '\\begin_layout Separator', '', '\\end_layout']
+                    else:
+                        document.body[fend : fend] = ['\\end_deeper']
+                    document.body[j + 1 : j + 1] = ['', '\\begin_deeper']
+                    break
+            i = j
+
+
+def remove_endframes(document):
+    " Remove deprecated beamer endframes "
+    
+    beamer_classes = ["beamer", "article-beamer", "scrarticle-beamer"]
+    if document.textclass not in beamer_classes:
+        return
+   
+    i = 0
+    while True:
+        i = find_token_exact(document.body, "\\begin_layout EndFrame", i)
+        if i == -1:
+            break
+        j = find_end_of_layout(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: Missing \\end_layout to EndFrame")
+            i = i + 1
+            continue
+        del document.body[i : j + 1]
+
+
 ##
 # Conversion hub
 #
@@ -3729,9 +3873,11 @@ convert = [
            [462, []],
            [463, [convert_encodings]],
            [464, [convert_use_cancel]],
+           [465, [convert_lyxframes, remove_endframes]]
           ]
 
 revert =  [
+           [464, []],
            [463, [revert_use_cancel]],
            [462, [revert_encodings]],
            [461, [revert_new_libertines]],
index 5c7ba2de021f1f169d798a379be06a6a69e15548..481a139a1ba995eabd474f256d49917f674069a9 100644 (file)
@@ -88,7 +88,7 @@ Format LaTeX feature                        LyX feature
                                             \font_sans
                                             \font_sf_scale
 463
-
+465
 
 General
 
index 94e5244f04a02a4a106ac461c6852d6417a45650..0c1e05110008599404390f4c4963843ca84383c8 100644 (file)
@@ -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 464 // kornel: use_package cancel
-#define LYX_FORMAT_TEX2LYX 464 // kornel: use_package cancel
+#define LYX_FORMAT_LYX 465 // spitz: new beamer frames
+#define LYX_FORMAT_TEX2LYX 465 // spitz: new beamer frames
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER