]> git.lyx.org Git - lyx.git/commitdiff
Improve lyx 0.10 file convertions.
authorJosé Matox <jamatos@lyx.org>
Wed, 4 Feb 2004 18:11:44 +0000 (18:11 +0000)
committerJosé Matox <jamatos@lyx.org>
Wed, 4 Feb 2004 18:11:44 +0000 (18:11 +0000)
The only remaings itens are whitespace and not significative.
I can now import all of the 0.10 test cases I have. :-)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8403 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/ChangeLog
lib/lyx2lyx/lyxconvert_210.py

index e02a505e281d3c4c1e1964528b364155ba6c8085..231029c529c19d2074336188d7b5a5f29774b5b0 100644 (file)
@@ -1,6 +1,11 @@
-2004-02-03  Jos& Matos  <jamatos@lyx.org>
+2004-02-04  José Matos  <jamatos@lyx.org>
+       * lyxconvert_210.py: add two new transforms:
+       remove_empty_insets and remove_formula_latex
+       little fix to existing transformations.
 
-        * lyxconvert216.py: one line fix for out of range error.
+2004-02-03  José Matos  <jamatos@lyx.org>
+
+       * lyxconvert216.py: one line fix for out of range error.
 
 2004-02-01  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
index 0f9787f1e34d3e3b6c24017356beaa047842ad8f..885050bf1a674b80794b198177e62f87ad9d01ee 100644 (file)
@@ -27,7 +27,7 @@ def space_before_layout(lines):
         if i == -1:
             break
 
-        if lines[i - 1] == '':
+        if lines[i - 1] == '' and string.find(lines[i-2],'\\protected_separator') == -1:
             del lines[i-1]
         i = i + 1
 
@@ -37,7 +37,7 @@ def formula_inset_space_eat(lines):
         i = find_token(lines, "\\begin_inset Formula", i)
         if i == -1: break
 
-        if len(lines[i]) > 22:
+        if len(lines[i]) > 22 and lines[i][21] == ' ':
             lines[i] = lines[i][:20] + lines[i][21:]
         i = i + 1
 
@@ -125,13 +125,39 @@ def update_inset_accent(lines):
 
 def remove_cursor(lines):
     i = 0
+    cursor_re = re.compile(r'.*(\\cursor \d*)')
     while 1:
-        i = find_token(lines, '\\cursor', i)
+        i = find_re(lines, cursor_re, i)
         if i == -1:
             break
-        lines[i] = ''
+        cursor = cursor_re.search(lines[i]).group(1)
+        lines[i]= string.replace(lines[i], cursor, '')
         i = i + 1
 
+def remove_empty_insets(lines):
+    i = 0
+    while 1:
+        i = find_token(lines, '\\begin_inset ',i)
+        if i == -1:
+            break
+        if lines[i] == '\\begin_inset ' and lines[i+1] == '\\end_inset ':
+            del lines[i]
+            del lines[i]
+        i = i + 1
+
+def remove_formula_latex(lines):
+    i = 0
+    while 1:
+        i = find_token(lines, '\\latex formula_latex ', i)
+        if i == -1:
+            break
+        del lines[i]
+
+        i = find_token(lines, '\\latex default', i)
+        if i == -1:
+            break
+        del lines[i]
+
 def add_end_document(lines):
     lines.append('\\the_end')
 
@@ -157,11 +183,27 @@ def header_update(lines):
 
         if check_token(lines[i], '\\papersize'):
             size = string.split(lines[i])[1]
+            new_size = size
+            paperpackage = ""
+
             if size == 'usletter':
-                lines[i] = '\\papersize letterpaper'
+                new_size = 'letterpaper'
+            if size == 'a4wide':
+                new_size = 'Default'
+                paperpackage = "widemarginsa4"
+
+            lines[i] = '\\papersize ' + new_size
             i = i + 1
+            if paperpackage:
+                lines.insert(i, '\\paperpackage ' + paperpackage)
+                i = i + 1
+
+            lines.insert(i,'\\use_geometry 0')
+            lines.insert(i + 1,'\\use_amsmath 0')
+            i = i + 2
             continue
 
+
         if check_token(lines[i], '\\baselinestretch'):
             size = string.split(lines[i])[1]
             if size == '1.00':
@@ -169,19 +211,15 @@ def header_update(lines):
             elif size == '1.50':
                 name = 'onehalf'
             elif size == '2.00':
-                name == 'double'
+                name = 'double'
+            else:
+                name = 'other ' + size
             lines[i] = '\\spacing %s ' % name
             i = i + 1
             continue
 
         i = i + 1
 
-    lines.append('\\paperpackage a4')
-    lines.append('\\use_geometry 0')
-    lines.append('\\use_amsmath 0')
-    lines.append('\\paperorientation portrait')
-
-
 def convert(header,body):
     header_update(header)
     add_end_document(body)
@@ -195,6 +233,8 @@ def convert(header,body):
     formula_inset_space_eat(body)
     update_tabular(body)
     update_vfill(body)
+    remove_empty_insets(body)
+    remove_formula_latex(body)
 
 if __name__ == "__main__":
     pass