]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_0.py
More elses after returns.
[lyx.git] / lib / lyx2lyx / lyx_2_0.py
index 6c1d1bda5b9b50494d146974106fe4da15a4c6d0..f99f28617fca022ab2967068d073844e1cc09744 100644 (file)
@@ -350,25 +350,24 @@ def revert_layout_command(document, name, LaTeXname, position):
     i = find_token(document.body, '\\begin_layout ' + name, i)
     if i == -1:
       return
-    else:
-      k = -1
-      # find the next layout
-      j = i + 1
-      while k == -1:
-        j = find_token(document.body, '\\begin_layout', j)
-        l = len(document.body)
-        # if nothing was found it was the last layout of the document
-        if j == -1:
-          document.body[l - 4:l - 4] = put_cmd_in_ert("}")
-          k = 0
-        # exclude plain layout because this can be TeX code or another inset
-        elif document.body[j] != '\\begin_layout Plain Layout':
-          document.body[j - 2:j - 2] = put_cmd_in_ert("}")
-          k = 0
-        else:
-          j += 1
-      document.body[i] = '\\begin_layout Standard'
-      document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{")
+    k = -1
+    # find the next layout
+    j = i + 1
+    while k == -1:
+      j = find_token(document.body, '\\begin_layout', j)
+      l = len(document.body)
+      # if nothing was found it was the last layout of the document
+      if j == -1:
+        document.body[l - 4:l - 4] = put_cmd_in_ert("}")
+        k = 0
+      # exclude plain layout because this can be TeX code or another inset
+      elif document.body[j] != '\\begin_layout Plain Layout':
+        document.body[j - 2:j - 2] = put_cmd_in_ert("}")
+        k = 0
+      else:
+        j += 1
+    document.body[i] = '\\begin_layout Standard'
+    document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{")
     i += 1
 
 
@@ -1818,36 +1817,37 @@ def revert_makebox(document):
     i = find_token(document.body, '\\begin_inset Box Frameless', i)
     if i == -1:
       return
-    else:
-      z = find_end_of_inset(document.body, i)
-      if z == -1:
-        document.warning("Malformed LyX document: Can't find end of box inset.")
-        return
-      j = find_token(document.body, 'use_makebox 1', i)
-      # assure we found the makebox of the current box
-      if j > i + 7 or j == -1:
-       return
-      else:
-        # remove the \end_inset
-        document.body[z - 2:z + 1] = put_cmd_in_ert("}")
-        # determine the alignment
-        k = find_token(document.body, 'hor_pos', j - 4)
-        align = document.body[k][9]
-        # determine the width
-        l = find_token(document.body, 'width "', j + 1)
-        length = document.body[l][7:]
-        # remove trailing '"'
-        length = length[:-1]
-        # latex_length returns "bool,length"
-        length = latex_length(length).split(",")[1]
-        subst = "\\makebox[" + length + "][" \
-         + align + "]{"
-        document.body[i:i + 13] = put_cmd_in_ert(subst)
+    z = find_end_of_inset(document.body, i)
+    if z == -1:
+      document.warning("Malformed LyX document: Can't find end of box inset.")
+      return
+    j = find_token(document.body, 'use_makebox 1', i)
+    # assure we found the makebox of the current box
+    if j > i + 7 or j == -1:
+      return
+    # remove the \end_inset
+    document.body[z - 2:z + 1] = put_cmd_in_ert("}")
+    # determine the alignment
+    k = find_token(document.body, 'hor_pos', j - 4)
+    align = document.body[k][9]
+    # determine the width
+    l = find_token(document.body, 'width "', j + 1)
+    length = document.body[l][7:]
+    # remove trailing '"'
+    length = length[:-1]
+    # latex_length returns "bool,length"
+    length = latex_length(length).split(",")[1]
+    subst = "\\makebox[" + length + "][" \
+      + align + "]{"
+    document.body[i:i + 13] = put_cmd_in_ert(subst)
     i += 1
 
 
 def revert_IEEEtran(document):
   " Convert IEEEtran layouts and styles to TeX code "
+  if document.textclass != "IEEEtran":
+    return
+
   revert_flex_inset(document, "IEEE membership", "\\IEEEmembership", 0)
   revert_flex_inset(document, "Lowercase", "\\MakeLowercase", 0)
   revert_layout_command(document, "Special Paper Notice", "\\IEEEspecialpapernotice", 0)
@@ -1870,34 +1870,33 @@ def revert_IEEEtran(document):
          + '\\end_layout\n\n' \
          + '\\end_inset\n\n\n' \
          + '\\end_layout\n\n'
-  if document.textclass == "IEEEtran":
-    # insert a note that title and author must be given in TeX code
-    document.body.insert(0, note)
-    # we need to revert title and author to TeX code to set \maketitle correctly
-    revert_layout_command(document, "Title", "\\title", 0)
-    revert_layout_command(document, "Author", "\\author", 0)
-    # write \markboth code to the preamble
-    insert_to_preamble(0, document,
-                          '% Commands inserted by lyx2lyx\n'
-                          + '% protect \\markboth against an old bug reintroduced in babel >= 3.8g\n'
-                          + '\\let\\oldforeign@language\\foreign@language\n'
-                          + '\\DeclareRobustCommand{\\foreign@language}[1]{%\n'
-                          + '  \\lowercase{\\oldforeign@language{#1}}}\n')
-    # set maketitle
-    y = find_token(document.body, '\\begin_layout Abstract', 0)
-    if y == -1:
-      document.warning("Malformed LyX document: Can't find abstract of IEEEtran paper.")
-    else:
-      maketitle = ['\\begin_layout Standard\n', \
-                  '\\begin_inset ERT\n', \
-                  'status collapsed\n', \
-                  '\\begin_layout Plain Layout\n', \
-                  '\\backslash\n', \
-                  'maketitle \n', \
-                  '\\end_layout\n', \
-                  '\\end_inset\n', \
-                  '\\end_layout\n']
-      document.body[y:y] = maketitle
+  # insert a note that title and author must be given in TeX code
+  document.body.insert(0, note)
+  # we need to revert title and author to TeX code to set \maketitle correctly
+  revert_layout_command(document, "Title", "\\title", 0)
+  revert_layout_command(document, "Author", "\\author", 0)
+  # write \markboth code to the preamble
+  insert_to_preamble(0, document,
+                        '% Commands inserted by lyx2lyx\n'
+                        + '% protect \\markboth against an old bug reintroduced in babel >= 3.8g\n'
+                        + '\\let\\oldforeign@language\\foreign@language\n'
+                        + '\\DeclareRobustCommand{\\foreign@language}[1]{%\n'
+                        + '  \\lowercase{\\oldforeign@language{#1}}}\n')
+  # set maketitle
+  y = find_token(document.body, '\\begin_layout Abstract', 0)
+  if y == -1:
+    document.warning("Malformed LyX document: Can't find abstract of IEEEtran paper.")
+    return
+  maketitle = ['\\begin_layout Standard\n', \
+              '\\begin_inset ERT\n', \
+              'status collapsed\n', \
+              '\\begin_layout Plain Layout\n', \
+              '\\backslash\n', \
+              'maketitle \n', \
+              '\\end_layout\n', \
+              '\\end_inset\n', \
+              '\\end_layout\n']
+  document.body[y:y] = maketitle
 
 
 ##