]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_1.py
Don't use widest label for numerical citations.
[lyx.git] / lib / lyx2lyx / lyx_2_1.py
index f42af73c818f0e41a73d3f131afcdb1738bd5222..4143dda06cddb77660ddbb8db16847542f37a7a4 100644 (file)
@@ -17,7 +17,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-""" Convert files to the file format generated by lyx 2.1"""
+""" Convert files to the file format generated by LyX 2.1"""
 
 import re, string
 import unicodedata
@@ -544,7 +544,7 @@ def revert_verbatim(document):
             return
         j = find_end_of_layout(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of Verbatim layout")
+            document.warning("Malformed LyX document: Can't find end of Verbatim layout")
             i += 1
             continue
         # delete all line breaks insets (there are no other insets)
@@ -594,18 +594,18 @@ def revert_tipa(document):
             return
         j = find_end_of_inset(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of IPA inset")
+            document.warning("Malformed LyX document: Can't find end of IPA inset")
             i += 1
             continue
         Multipar = False
         n = find_token(document.body, "\\begin_layout", i, j)
         if n == -1:
-            document.warning("Malformed lyx document: IPA inset has no embedded layout")
+            document.warning("Malformed LyX document: IPA inset has no embedded layout")
             i += 1
             continue
         m = find_end_of_layout(document.body, n)
         if m == -1:
-            document.warning("Malformed lyx document: Can't find end of embedded layout")
+            document.warning("Malformed LyX document: Can't find end of embedded layout")
             i += 1
             continue
         content = document.body[n+1:m]
@@ -750,7 +750,7 @@ def convert_listoflistings(document):
             return
         j = find_end_of_inset(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of ERT inset")
+            document.warning("Malformed LyX document: Can't find end of ERT inset")
             i += 1
             continue
         ert = get_ert(document.body, i)
@@ -771,7 +771,7 @@ def revert_listoflistings(document):
         if document.body[i+1] == "LatexCommand lstlistoflistings":
             j = find_end_of_inset(document.body, i)
             if j == -1:
-                document.warning("Malformed lyx document: Can't find end of TOC inset")
+                document.warning("Malformed LyX document: Can't find end of TOC inset")
                 i += 1
                 continue
             subst = put_cmd_in_ert("\\lstlistoflistings{}")
@@ -1276,7 +1276,7 @@ def convert_latexargs(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -1329,7 +1329,7 @@ def revert_latexargs(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -1345,7 +1345,7 @@ def revert_latexargs(document):
                 # Revert to old syntax
                 document.body[p] = "\\begin_inset Argument"
                 if j == -1:
-                    document.warning("Malformed lyx document: Can't find end of Argument inset")
+                    document.warning("Malformed LyX document: Can't find end of Argument inset")
                     continue
                 if val > 0:
                     args[val] = document.body[p : j + 1]
@@ -2025,7 +2025,7 @@ def revert_itemargs(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[3]
@@ -2088,7 +2088,7 @@ def convert_beamerargs(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -2345,7 +2345,7 @@ def revert_beamerargs(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -2525,7 +2525,7 @@ def revert_beamerargs2(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -2607,7 +2607,7 @@ def revert_beamerargs3(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -2761,7 +2761,7 @@ def revert_beamerblocks(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -2892,7 +2892,7 @@ def convert_overprint(document):
         # Find end of sequence
         j = find_end_of_sequence(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document. Cannot find end of Overprint sequence!")
+            document.warning("Malformed LyX document. Cannot find end of Overprint sequence!")
             i = i + 1
             continue
         endseq = j
@@ -2908,7 +2908,7 @@ def convert_overprint(document):
         if argbeg != -1:
             argend = find_end_of_layout(document.body, argbeg)
             if argend == -1:
-                document.warning("Malformed lyx document. Cannot find end of Overprint argument!")
+                document.warning("Malformed LyX document. Cannot find end of Overprint argument!")
                 i = i + 1
                 continue
             beginPlain = find_token(document.body, "\\begin_layout Plain Layout", argbeg)
@@ -2946,7 +2946,7 @@ def revert_overprint(document):
         # Find end of sequence
         j = find_end_of_sequence(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document. Cannot find end of Overprint sequence!")
+            document.warning("Malformed LyX document. Cannot find end of Overprint sequence!")
             i = i + 1
             continue
         endseq = j
@@ -2971,7 +2971,7 @@ def revert_overprint(document):
         if argbeg != -1:
             argend = find_end_of_inset(document.body, argbeg)
             if argend == -1:
-                document.warning("Malformed lyx document. Cannot find end of Overprint argument!")
+                document.warning("Malformed LyX document. Cannot find end of Overprint argument!")
                 i = i + 1
                 continue
             beginPlain = find_token(document.body, "\\begin_layout Plain Layout", argbeg)
@@ -2994,7 +2994,7 @@ def revert_overprint(document):
             if document.body[p] == "\\begin_layout Overprint":
                 q = find_end_of_layout(document.body, p)
                 if q == -1:
-                    document.warning("Malformed lyx document. Cannot find end of Overprint layout!")
+                    document.warning("Malformed LyX document. Cannot find end of Overprint layout!")
                     p += 1
                     continue
                 subst = ["\\begin_layout Standard"] + put_cmd_in_ert("\\onslide")
@@ -3002,7 +3002,7 @@ def revert_overprint(document):
                 if argbeg != -1:
                     argend = find_end_of_inset(document.body, argbeg)
                     if argend == -1:
-                        document.warning("Malformed lyx document. Cannot find end of Overprint item argument!")
+                        document.warning("Malformed LyX document. Cannot find end of Overprint item argument!")
                         p += 1
                         continue
                     beginPlain = find_token(document.body, "\\begin_layout Plain Layout", argbeg)
@@ -3035,7 +3035,7 @@ def revert_frametitle(document):
             return
         j = find_end_of_layout(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of FrameTitle layout")
+            document.warning("Malformed LyX document: Can't find end of FrameTitle layout")
             i = i + 1
             continue
         endlay = j
@@ -3087,7 +3087,7 @@ def convert_epigraph(document):
             return
         j = find_end_of_layout(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of Epigraph layout")
+            document.warning("Malformed LyX document: Can't find end of Epigraph layout")
             i = i + 1
             continue
         endlay = j
@@ -3128,7 +3128,7 @@ def revert_epigraph(document):
             return
         j = find_end_of_layout(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of Epigraph layout")
+            document.warning("Malformed LyX document: Can't find end of Epigraph layout")
             i = i + 1
             continue
         endlay = j
@@ -3161,7 +3161,6 @@ def convert_captioninsets(document):
           return
       document.body[i] = "\\begin_inset Caption Standard"
       i = i + 1
-        
 
 
 def revert_captioninsets(document):
@@ -3178,7 +3177,7 @@ def revert_captioninsets(document):
 
 def convert_captionlayouts(document):
     " Convert caption layouts to caption insets. "
-    
+
     caption_dict = {
         "Captionabove":  "Above",
         "Captionbelow":  "Below",
@@ -3187,7 +3186,7 @@ def convert_captionlayouts(document):
         "CenteredCaption" : "Centered",
         "Bicaption" : "Bicaption",
         }
-    
+
     i = 0
     while True:
         i = find_token(document.body, "\\begin_layout", i)
@@ -3314,7 +3313,7 @@ def revert_fragileframe(document):
         # Find end of sequence
         j = find_end_of_sequence(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document. Cannot find end of FragileFrame sequence!")
+            document.warning("Malformed LyX document. Cannot find end of FragileFrame sequence!")
             i = i + 1
             continue
         endseq = j
@@ -3417,7 +3416,7 @@ def revert_newframes(document):
         # Find end of sequence
         j = find_end_of_sequence(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document. Cannot find end of Frame sequence!")
+            document.warning("Malformed LyX document. Cannot find end of Frame sequence!")
             i = i + 1
             continue
         endseq = j
@@ -3920,7 +3919,7 @@ def revert_powerdot_pause(document):
             return
         j = find_end_of_layout(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of Pause layout")
+            document.warning("Malformed LyX document: Can't find end of Pause layout")
             i = i + 1
             continue
         endlay = j
@@ -3961,7 +3960,7 @@ def revert_powerdot_itemargs(document):
         # Find containing paragraph layout
         parent = get_containing_layout(document.body, i)
         if parent == False:
-            document.warning("Malformed lyx document: Can't find parent paragraph layout")
+            document.warning("Malformed LyX document: Can't find parent paragraph layout")
             i = i + 1
             continue
         parbeg = parent[1]
@@ -4012,7 +4011,7 @@ def revert_powerdot_columns(document):
             return
         j = find_end_of_layout(document.body, i)
         if j == -1:
-            document.warning("Malformed lyx document: Can't find end of Twocolumn layout")
+            document.warning("Malformed LyX document: Can't find end of Twocolumn layout")
             i = i + 1
             continue
         endlay = j
@@ -4051,6 +4050,83 @@ def revert_powerdot_columns(document):
         i = endlay
 
 
+def revert_mbox_fbox(document):
+    'Convert revert mbox/fbox boxes to TeX-code'
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset Box", i)
+        if i == -1:
+            return
+        j = find_token(document.body, "width", i)
+        if j != i + 7:
+            document.warning("Malformed LyX document: Can't find box width")
+            return
+        width = get_value(document.body, "width", j)
+        k = find_end_of_inset(document.body, j)
+        if k == -1:
+            document.warning("Malformed LyX document: Can't find end of box inset")
+            i += 1
+            continue
+        BeginLayout = find_token(document.body, "\\begin_layout Plain Layout", j)
+        EndLayout = find_token(document.body, "\\end_layout", BeginLayout)
+        # replace if width is "-999col%"
+        if (width == '"-999col%"'):
+            document.body[EndLayout:k + 1] = put_cmd_in_ert("}")
+            if document.body[i] == "\\begin_inset Box Frameless":
+                document.body[i:BeginLayout + 1] = put_cmd_in_ert("\\mbox{")
+            if document.body[i] == "\\begin_inset Box Boxed":
+                document.body[i:BeginLayout + 1] = put_cmd_in_ert("\\fbox{")
+        i = i + 1
+
+
+def revert_starred_caption(document):
+    " Reverts unnumbered longtable caption insets "
+    
+    i = 0
+    while True:
+      i = find_token(document.body, "\\begin_inset Caption LongTableNoNumber", i)
+      if i == -1:
+          return
+      # This is not equivalent, but since the caption inset is a full blown
+      # text inset a true conversion to ERT is too difficult.
+      document.body[i] = "\\begin_inset Caption Standard"
+      i = i + 1
+
+
+def revert_forced_local_layout(document):
+    i = 0
+    while True:
+        i = find_token(document.header, "\\begin_forced_local_layout", i)
+        if i == -1:
+            return
+        j = find_end_of(document.header, i, "\\begin_forced_local_layout", "\\end_forced_local_layout")
+        if j == -1:
+            # this should not happen
+            break
+        regexp = re.compile(r'\s*forcelocal', re.IGNORECASE)
+        k = find_re(document.header, regexp, i, j)
+        while k != -1:
+            del document.header[k]
+            j = j - 1
+            k = find_re(document.header, regexp, i, j)
+        k = find_token(document.header, "\\begin_local_layout", 0)
+        if k == -1:
+            document.header[i] = "\\begin_local_layout"
+            document.header[j] = "\\end_local_layout"
+        else:
+            l = find_end_of(document.header, k, "\\begin_local_layout", "\\end_local_layout")
+            if j == -1:
+                # this should not happen
+                break
+            lines = document.header[i+1 : j]
+            if k > i:
+                document.header[k+1 : k+1] = lines
+                document.header[i   : j  ] = []
+            else:
+                document.header[i   : j  ] = []
+                document.header[k+1 : k+1] = lines
+
+
 ##
 # Conversion hub
 #
@@ -4110,10 +4186,16 @@ convert = [
            [464, [convert_use_cancel]],
            [465, [convert_lyxframes, remove_endframes]],
            [466, []],
-           [467, []]
+           [467, []],
+           [468, []],
+           [469, []],
+           [470, []] 
           ]
 
 revert =  [
+           [469, [revert_forced_local_layout]],
+           [468, [revert_starred_caption]],
+           [467, [revert_mbox_fbox]],
            [466, [revert_iwona_fonts]],
            [465, [revert_powerdot_flexes, revert_powerdot_pause, revert_powerdot_itemargs, revert_powerdot_columns]],
            [464, []],