]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_0.py
fix a few compiler warnings
[lyx.git] / lib / lyx2lyx / lyx_2_0.py
index d1ab30f635f18a84db70905fde3ef0de4ab55a16..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)
@@ -604,6 +607,7 @@ def revert_printindexall(document):
             document.body[i:k+1] = subst
         i = i + 1
 
+
 def revert_strikeout(document):
     " Reverts \\strikeout character style "
     while True:
@@ -613,6 +617,96 @@ def revert_strikeout(document):
         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
 #
@@ -627,10 +721,22 @@ convert = [[346, []],
            [352, [convert_splitindex]],
            [353, []],
            [354, []],
-           [355, []]
+           [355, []],
+           [356, []],
+           [357, []],
+           [358, []],
+           [359, [convert_nomencl_width]],
+           [360, []],
+           [361, []]
           ]
 
-revert =  [[354, [revert_strikeout]],
+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]],