]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_0.py
A little cleanup of the layout files.
[lyx.git] / lib / lyx2lyx / lyx_2_0.py
index b1f5cd5d25381b0a401e95a33daf5b8f6f6cedf9..90f4d0e1e3f6d8c18ff79532b1eb14d50102d8f1 100644 (file)
@@ -435,6 +435,9 @@ def revert_backgroundcolor(document):
           return
       colorcode = get_value(document.header, '\\backgroundcolor', 0)
       del document.header[i]
+      # don't clutter the preamble if backgroundcolor is not set
+      if colorcode == "#ffffff":
+          continue
       # the color code is in the form #rrggbb where every character denotes a hex number
       # convert the string to an int
       red = string.atoi(colorcode[1:3],16)
@@ -554,6 +557,156 @@ def convert_splitindex(document):
         i = i + 1
 
 
+def revert_subindex(document):
+    " Reverts \\printsubindex CommandInset types "
+    i = find_token(document.header, '\\use_indices', 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Missing \\use_indices.")
+        return
+    indices = get_value(document.header, "\\use_indices", i)
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
+        if i == -1:
+            return
+        k = find_end_of_inset(document.body, i)
+        ctype = get_value(document.body, 'LatexCommand', i, k)
+        if ctype != "printsubindex":
+            i = i + 1
+            continue
+        ptype = get_value(document.body, 'type', i, k).strip('"')
+        if indices == "false":
+            del document.body[i:k+1]
+        else:
+            subst = [put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")]
+            document.body[i:k+1] = subst
+        i = i + 1
+
+
+def revert_printindexall(document):
+    " Reverts \\print[sub]index* CommandInset types "
+    i = find_token(document.header, '\\use_indices', 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Missing \\use_indices.")
+        return
+    indices = get_value(document.header, "\\use_indices", i)
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
+        if i == -1:
+            return
+        k = find_end_of_inset(document.body, i)
+        ctype = get_value(document.body, 'LatexCommand', i, k)
+        if ctype != "printindex*" and ctype != "printsubindex*":
+            i = i + 1
+            continue
+        if indices == "false":
+            del document.body[i:k+1]
+        else:
+            subst = [put_cmd_in_ert("\\" + ctype + "{}")]
+            document.body[i:k+1] = subst
+        i = i + 1
+
+
+def revert_strikeout(document):
+    " Reverts \\strikeout character style "
+    while True:
+        i = find_token(document.body, '\\strikeout', 0)
+        if i == -1:
+            return
+        del document.body[i]
+
+
+def revert_uulinewave(document):
+    " Reverts \\uuline, and \\uwave character styles "
+    while True:
+        i = find_token(document.body, '\\uuline', 0)
+        if i == -1:
+            break
+        del document.body[i]
+    while True:
+        i = find_token(document.body, '\\uwave', 0)
+        if i == -1:
+            return
+        del document.body[i]
+
+
+def revert_ulinelatex(document):
+    " Reverts \\uline character style "
+    i = find_token(document.body, '\\bar under', 0)
+    if i == -1:
+        return
+    insert_to_preamble(0, document,
+            '% Commands inserted by lyx2lyx for proper underlining\n'
+            + '\\PassOptionsToPackage{normalem}{ulem}\n'
+            + '\\usepackage{ulem}\n'
+            + '\\let\\cite@rig\\cite\n'
+            + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n'
+            + '  \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n'
+            + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n')
+
+
+def revert_custom_processors(document):
+    " Remove bibtex_command and index_command params "
+    i = find_token(document.header, '\\bibtex_command', 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Missing \\bibtex_command.")
+        return
+    del document.header[i]
+    i = find_token(document.header, '\\index_command', 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Missing \\index_command.")
+        return
+    del document.header[i]
+
+
+def convert_nomencl_width(document):
+    " Add set_width param to nomencl_print "
+    i = 0
+    while True:
+      i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+      if i == -1:
+        break
+      document.body.insert(i + 2, "set_width \"none\"")
+      i = i + 1
+
+
+def revert_nomencl_width(document):
+    " Remove set_width param from nomencl_print "
+    i = 0
+    while True:
+      i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+      if i == -1:
+        break
+      j = find_end_of_inset(document.body, i)
+      l = find_token(document.body, "set_width", i, j)
+      if l == -1:
+            document.warning("Can't find set_width option for nomencl_print!")
+            i = j
+            continue
+      del document.body[l]
+      i = i + 1
+
+
+def revert_nomencl_cwidth(document):
+    " Remove width param from nomencl_print "
+    i = 0
+    while True:
+      i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
+      if i == -1:
+        break
+      j = find_end_of_inset(document.body, i)
+      l = find_token(document.body, "width", i, j)
+      if l == -1:
+            document.warning("Can't find width option for nomencl_print!")
+            i = j
+            continue
+      width = get_value(document.body, "width", i, j).strip('"')
+      del document.body[l]
+      add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
+      i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -565,10 +718,28 @@ convert = [[346, []],
            [349, []],
            [350, []],
            [351, []],
-           [352, [convert_splitindex]]
+           [352, [convert_splitindex]],
+           [353, []],
+           [354, []],
+           [355, []],
+           [356, []],
+           [357, []],
+           [358, []],
+           [359, [convert_nomencl_width]],
+           [360, []],
+           [361, []]
           ]
 
-revert =  [[351, [revert_splitindex]],
+revert =  [[360, []],
+           [359, [revert_nomencl_cwidth]],
+           [358, [revert_nomencl_width]],
+           [357, [revert_custom_processors]],
+           [356, [revert_ulinelatex]],
+           [355, [revert_uulinewave]],
+           [354, [revert_strikeout]],
+           [353, [revert_printindexall]],
+           [352, [revert_subindex]],
+           [351, [revert_splitindex]],
            [350, [revert_backgroundcolor]],
            [349, [revert_outputformat]],
            [348, [revert_xetex]],