]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_1_1_5.py
Don't use widest label for numerical citations.
[lyx.git] / lib / lyx2lyx / lyx_1_1_5.py
index bb924dd16758904b900696f8c8252deb5cc82e40..304ff7a48e644b3f49d67a8fbfe41006b0cd2a65 100644 (file)
@@ -1,6 +1,6 @@
-# This file is part of lyx2lyx
-# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
+# This document is part of lyx2lyx
+# -*- coding: utf-8 -*-
+# Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+""" Convert files to the file format generated by lyx 1.1.5"""
 
 import re
-import string
 from parser_tools import find_token, find_token_backwards, find_re
 
 ####################################################################
 # Private helper functions
 
 def get_layout(line, default_layout):
-    tokens = string.split(line)
+    " Get the line layout, beware of the empty layout."
+    tokens = line.split()
     if len(tokens) > 1:
         return tokens[1]
     return default_layout
@@ -34,8 +36,9 @@ def get_layout(line, default_layout):
 
 math_env = ["\\[","\\begin{eqnarray*}","\\begin{eqnarray}","\\begin{equation}"]
 
-def replace_protected_separator(file):
-    lines = file.body
+def replace_protected_separator(document):
+    " Replace protected separator. "
+    lines = document.body
     i=0
     while 1:
         i = find_token(lines, "\\protected_separator", i)
@@ -43,7 +46,7 @@ def replace_protected_separator(file):
             break
         j = find_token_backwards(lines, "\\layout", i)
         #if j == -1: print error
-        layout = get_layout(lines[j], file.default_layout)
+        layout = get_layout(lines[j], document.default_layout)
 
         if layout == "LyX-Code":
             result = ""
@@ -58,8 +61,9 @@ def replace_protected_separator(file):
         del lines[i]
 
 
-def merge_formula_inset(file):
-    lines = file.body
+def merge_formula_inset(document):
+    " Merge formula insets. "
+    lines = document.body
     i=0
     while 1:
         i = find_token(lines, "\\begin_inset Formula", i)
@@ -70,9 +74,9 @@ def merge_formula_inset(file):
         i = i + 1
 
 
-# Update from tabular format 4 to 5 if necessary
-def update_tabular(file):
-    lines = file.body
+def update_tabular(document):
+    " Update from tabular format 4 to 5 if necessary. "
+    lines = document.body
     lyxtable_re = re.compile(r".*\\LyXTable$")
     i=0
     while 1:
@@ -86,16 +90,16 @@ def update_tabular(file):
 
         lines[i]='multicol5'
         i = i + 1
-        rows = int(string.split(lines[i])[0])
-        columns = int(string.split(lines[i])[1])
+        rows = int(lines[i].split()[0])
+        columns = int(lines[i].split()[1])
 
         i = i + rows + 1
         for j in range(columns):
-            col_info = string.split(lines[i])
+            col_info = lines[i].split()
             if len(col_info) == 3:
                 lines[i] = lines[i] + '"" ""'
             else:
-                lines[i] = string.join(col_info[:3]) + ' "%s" ""' % col_info[3]
+                lines[i] = " ".join(col_info[:3]) + ' "%s" ""' % col_info[3]
             i = i + 1
 
         while lines[i]:
@@ -103,26 +107,30 @@ def update_tabular(file):
             i = i + 1
 
 
-def update_toc(file):
-    lines = file.body
+def update_toc(document):
+    " Update table of contents. "
+    lines = document.body
     i = 0
     while 1:
-        i = find_token(lines, '\\begin_inset LatexCommand \\tableofcontents', i)
+        i = find_token(lines,
+                       '\\begin_inset LatexCommand \\tableofcontents', i)
         if i == -1:
             break
         lines[i] = lines[i] + '{}'
         i = i + 1
 
 
-def remove_cursor(file):
-    lines = file.body
+def remove_cursor(document):
+    " Remove cursor. "
+    lines = document.body
     i = find_token(lines, '\\cursor', 0)
     if i != -1:
         del lines[i]
 
 
-def remove_vcid(file):
-    lines = file.header
+def remove_vcid(document):
+    " Remove \\lyxvcid and \\lyxrcsid. "
+    lines = document.header
     i = find_token(lines, '\\lyxvcid', 0)
     if i != -1:
         del lines[i]
@@ -131,16 +139,18 @@ def remove_vcid(file):
         del lines[i]
 
 
-def first_layout(file):
-    lines = file.body
+def first_layout(document):
+    " Fix first layout, if empty use the default layout."
+    lines = document.body
     while (lines[0] == ""):
         del lines[0]
     if lines[0][:7] != "\\layout":
-        lines[:0] = ['\\layout %s' % file.default_layout, '']
+        lines[:0] = ['\\layout %s' % document.default_layout, '']
 
 
-def remove_space_in_units(file):
-    lines = file.header
+def remove_space_in_units(document):
+    " Remove space in units. "
+    lines = document.header
     margins = ["\\topmargin","\\rightmargin",
                "\\leftmargin","\\bottommargin"]
 
@@ -159,8 +169,9 @@ def remove_space_in_units(file):
             i = i + 1
 
 
-def latexdel_getargs(file, i):
-    lines = file.body
+def latexdel_getargs(document, i):
+    " Get arguments from latexdel insets. "
+    lines = document.body
 
     # play safe, clean empty lines
     while 1:
@@ -173,10 +184,10 @@ def latexdel_getargs(file, i):
     if i == j:
         del lines[i]
     else:
-        file.warning("Unexpected end of inset.")
+        document.warning("Unexpected end of inset.")
     j = find_token(lines, '\\begin_inset LatexDel }{', i)
 
-    ref = string.join(lines[i:j])
+    ref = " ".join(lines[i:j])
     del lines[i:j + 1]
 
     # play safe, clean empty lines
@@ -189,57 +200,64 @@ def latexdel_getargs(file, i):
     if i == j:
         del lines[i]
     else:
-        file.warning("Unexpected end of inset.")
+        document.warning("Unexpected end of inset.")
     j = find_token(lines, '\\begin_inset LatexDel }', i)
-    label = string.join(lines[i:j])
+    label = " ".join(lines[i:j])
     del lines[i:j + 1]
 
     return ref, label
 
 
-def update_ref(file):
-    lines = file.body
+def update_ref(document):
+    " Update reference inset. "
+    lines = document.body
     i = 0
     while 1:
         i = find_token(lines, '\\begin_inset LatexCommand', i)
         if i == -1:
             return
 
-        if string.split(lines[i])[-1] == "\\ref{":
+        if lines[i].split()[-1] == "\\ref{":
             i = i + 1
-            ref, label = latexdel_getargs(file, i)
+            ref, label = latexdel_getargs(document, i)
             lines[i - 1] = "%s[%s]{%s}" % (lines[i - 1][:-1], ref, label)
 
         i = i + 1
 
 
-def update_latexdel(file):
-    lines = file.body
+def update_latexdel(document):
+    " Remove latexdel insets. "
+    lines = document.body
     i = 0
     latexdel_re = re.compile(r".*\\begin_inset LatexDel")
     while 1:
         i = find_re(lines, latexdel_re, i)
         if i == -1:
             return
-        lines[i] = string.replace(lines[i],'\\begin_inset LatexDel', '\\begin_inset LatexCommand')
+        lines[i] = lines[i].replace('\\begin_inset LatexDel',
+                                    '\\begin_inset LatexCommand')
 
-        j = string.find(lines[i],'\\begin_inset')
+        j = lines[i].find('\\begin_inset')
         lines.insert(i+1, lines[i][j:])
-        lines[i] = string.strip(lines[i][:j])
+        lines[i] = lines[i][:j].strip()
         i = i + 1
 
-        if string.split(lines[i])[-1] in ("\\url{", "\\htmlurl{"):
+        if lines[i].split()[-1] in ("\\url{", "\\htmlurl{"):
             i = i + 1
 
-            ref, label = latexdel_getargs(file, i)
+            ref, label = latexdel_getargs(document, i)
             lines[i -1] = "%s[%s]{%s}" % (lines[i-1][:-1], label, ref)
 
         i = i + 1
 
 
-convert = [[216, [first_layout, remove_vcid, remove_cursor, update_toc,
-                  replace_protected_separator, merge_formula_inset,
-                  update_tabular, remove_space_in_units, update_ref, update_latexdel]]]
+supported_versions = ["1.1.5","1.1.5fix1","1.1.5fix2","1.1"]
+convert = [[216, [first_layout, remove_vcid, remove_cursor,
+                  update_toc, replace_protected_separator,
+                  merge_formula_inset, update_tabular,
+                  remove_space_in_units, update_ref,
+                  update_latexdel]]]
+
 revert  = []
 
 if __name__ == "__main__":