]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_2.py
UserGuide.lyx: fix some typographic issues spotted by Mike
[lyx.git] / lib / lyx2lyx / lyx_2_2.py
index 35aedd8a431aadb3bd2d8be54fe799bc2989ff16..37a26be592b04ab9e8a08a01efc7246c0bbd4ead 100644 (file)
@@ -104,6 +104,36 @@ def revert_Argument_to_TeX_brace(document, line, endline, n, nmax, environment,
 ###
 ###############################################################################
 
+def convert_longtable_label_internal(document, forward):
+    """
+    Convert reference to "LongTableNoNumber" into "Unnumbered" if forward is True
+    else revert it.
+    """
+    old_reference = "\\begin_inset Caption LongTableNoNumber"
+    new_reference = "\\begin_inset Caption Unnumbered"
+
+    # if the purpose is to revert swap the strings roles
+    if not forward:
+        old_reference, new_reference = new_reference, old_reference
+
+    i = 0
+    while True:
+        i = find_token(document.body, old_reference, i)
+
+        if i == -1:
+            return
+
+        document.body[i] = new_reference
+
+
+def convert_longtable_label(document):
+    convert_longtable_label_internal(document, True)
+
+
+def revert_longtable_label(document):
+    convert_longtable_label_internal(document, False)
+
+
 def convert_separator(document):
     """
     Convert layout separators to separator insets and add (LaTeX) paragraph
@@ -304,6 +334,46 @@ def revert_separator(document):
         i = i + 1
 
 
+def convert_parbreak(document):
+    """
+    Convert parbreak separators not specifically used to separate
+    environments to latexpar separators.
+    """
+    parbreakinset = "\\begin_inset Separator parbreak"
+    i = 0
+    while 1:
+        i = find_token(document.body, parbreakinset, i)
+        if i == -1:
+            return
+        lay = get_containing_layout(document.body, i)
+        if lay == False:
+            document.warning("Malformed LyX document: Can't convert separator inset at line " + str(i))
+            i += 1
+            continue
+        if lay[0] == "Standard":
+            # Convert only if not alone in the paragraph
+            k1 = find_nonempty_line(document.body, lay[1] + 1, i + 1)
+            k2 = find_nonempty_line(document.body, i + 1, lay[2])
+            if (k1 < i) or (k2 > i + 1) or not check_token(document.body[i], parbreakinset):
+                document.body[i] = document.body[i].replace("parbreak", "latexpar")
+        else:
+            document.body[i] = document.body[i].replace("parbreak", "latexpar")
+        i += 1
+
+
+def revert_parbreak(document):
+    """
+    Revert latexpar separators to parbreak separators.
+    """
+    i = 0
+    while 1:
+        i = find_token(document.body, "\\begin_inset Separator latexpar", i)
+        if i == -1:
+            return
+        document.body[i] = document.body[i].replace("latexpar", "parbreak")
+        i += 1
+
+
 def revert_smash(document):
     " Set amsmath to on if smash commands are used "
 
@@ -2201,110 +2271,6 @@ def revert_save_props(document):
     del document.header[i]
 
 
-def delete_TOG_project_URL(document):
-    i = 0
-    j = 0
-    while True:
-        # delete the TOG project URL
-        i = find_token(document.body, "\\begin_layout TOG project URL", i)
-        if i != -1:
-            j = find_end_of_layout(document.body, i + 1)
-        else:
-            return
-        if j != -1:
-            del(document.body[i : j + 1])
-        else:
-            document.warning("Malformed LyX document: Can't find end of layout TOG project URL")
-            return
-        i += 1
-
-
-def delete_TOG_video_URL(document):
-    i = 0
-    j = 0
-    while True:
-        # delete the TOG video URL
-        i = find_token(document.body, "\\begin_layout TOG video URL", i)
-        if i != -1:
-            j = find_end_of_layout(document.body, i)
-        else:
-            return
-        if j != -1:
-            del(document.body[i : j + 1])
-        else:
-            document.warning("Malformed LyX document: Can't find end of layout TOG video URL")
-            return
-        i += 1
-
-
-def delete_TOG_data_URL(document):
-    i = 0
-    j = 0
-    while True:
-        # delete the TOG video URL
-        i = find_token(document.body, "\\begin_layout TOG data URL", i)
-        if i != -1:
-            j = find_end_of_layout(document.body, i)
-        else:
-            return
-        if j != -1:
-            del(document.body[i : j + 1])
-        else:
-            document.warning("Malformed LyX document: Can't find end of layout TOG data URL")
-            return
-        i += 1
-
-
-def delete_TOG_code_URL(document):
-    i = 0
-    j = 0
-    while True:
-        # delete the TOG video URL
-        i = find_token(document.body, "\\begin_layout TOG code URL", i)
-        if i != -1:
-            j = find_end_of_layout(document.body, i)
-        else:
-            return
-        if j != -1:
-            del(document.body[i : j + 1])
-        else:
-            document.warning("Malformed LyX document: Can't find end of layout TOG code URL")
-            return
-        i += 1
-
-
-def convert_ACM_siggraph(document):
-    " Convert to version 0.92 of acmsiggraph. "
-    if document.textclass != "acmsiggraph":
-        return
-    # at first delete the now nonexistent styles since their info is now
-    # not needed and even unwanted
-    delete_TOG_project_URL(document)
-    delete_TOG_video_URL(document)
-    delete_TOG_data_URL(document)
-    delete_TOG_code_URL(document)
-    # now add a note that the user knows that he still has work to do
-    note = ["\\begin_layout Standard", "\\begin_inset Note Note", "status open", "",
-              "\\begin_layout Plain Layout", "", "\\series bold",
-              "\\color red", "Important note:", "\series default",
-              " This file was converted by \\SpecialChar LyX  to the format of acmsigplan 0.92.",
-              " This conversion is incomplete because you must add new information about",
-              " your article.",
-              " To see what is required, open the \\SpecialChar LyX  template file ",
-              "\\family sans",
-              "ACM-siggraph.lyx",
-              "\\family default",
-              ".",
-              "\\end_layout",
-              "",
-              "\\end_inset",
-              "",
-              "",
-              "\\end_layout",
-              ""]
-    document.body[1:1] = note
-
-
 def convert_info_tabular_feature(document):
     def f(arg):
         return arg.replace("inset-modify tabular", "tabular-feature")
@@ -2356,11 +2322,15 @@ convert = [
            [502, []],
            [503, []],
            [504, [convert_save_props]],
-           [505, [convert_ACM_siggraph]],
-           [506, [convert_info_tabular_feature]]
+           [505, []],
+           [506, [convert_info_tabular_feature]],
+           [507, [convert_longtable_label]],
+           [508, [convert_parbreak]]
           ]
 
 revert =  [
+           [507, [revert_parbreak]],
+           [506, [revert_longtable_label]],
            [505, [revert_info_tabular_feature]],
            [504, []],
            [503, [revert_save_props]],