]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx_1_2.py
Unify the call to converters into LyX.py. (lyx2lyx)
[lyx.git] / lib / lyx2lyx / lyx_1_2.py
1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
4 # Copyright (C) 2004 José Matos <jamatos@lyx.org>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 import string
21 import re
22
23 from parser_tools import find_token, find_token_backwards, get_next_paragraph,\
24                          find_tokens, find_end_of_inset, find_re, \
25                          is_nonempty_line, get_paragraph, find_nonempty_line, \
26                          get_value, get_tabular_lines, check_token
27
28 floats = {
29     "footnote": ["\\begin_inset Foot",
30                  "collapsed true"],
31     "margin":   ["\\begin_inset Marginal",
32                  "collapsed true"],
33     "fig":      ["\\begin_inset Float figure",
34                  "wide false",
35                  "collapsed false"],
36     "tab":      ["\\begin_inset Float table",
37                  "wide false",
38                  "collapsed false"],
39     "alg":      ["\\begin_inset Float algorithm",
40                  "wide false",
41                  "collapsed false"],
42     "wide-fig": ["\\begin_inset Float figure",
43                  "wide true",
44                  "collapsed false"],
45     "wide-tab": ["\\begin_inset Float table",
46                  "wide true",
47                  "collapsed false"]
48 }
49
50 font_tokens = ["\\family", "\\series", "\\shape", "\\size", "\\emph",
51                "\\bar", "\\noun", "\\color", "\\lang", "\\latex"]
52
53 pextra_type3_rexp = re.compile(r".*\\pextra_type\s+3")
54 pextra_rexp = re.compile(r"\\pextra_type\s+(\S+)"+\
55                          r"(\s+\\pextra_alignment\s+(\S+))?"+\
56                          r"(\s+\\pextra_hfill\s+(\S+))?"+\
57                          r"(\s+\\pextra_start_minipage\s+(\S+))?"+\
58                          r"(\s+(\\pextra_widthp?)\s+(\S*))?")
59
60
61 def get_width(mo):
62     if mo.group(10):
63         if mo.group(9) == "\\pextra_widthp":
64             return mo.group(10)+"col%"
65         else:
66             return mo.group(10)
67     else:
68         return "100col%"
69
70
71 #
72 # Change \begin_float .. \end_float into \begin_inset Float .. \end_inset
73 #
74 def remove_oldfloat(file):
75     lines = file.body
76     i = 0
77     while 1:
78         i = find_token(lines, "\\begin_float", i)
79         if i == -1:
80             break
81         # There are no nested floats, so finding the end of the float is simple
82         j = find_token(lines, "\\end_float", i+1)
83
84         floattype = string.split(lines[i])[1]
85         if not floats.has_key(floattype):
86             file.warning("Error! Unknown float type " + floattype)
87             floattype = "fig"
88
89         # skip \end_deeper tokens
90         i2 = i+1
91         while check_token(lines[i2], "\\end_deeper"):
92             i2 = i2+1
93         if i2 > i+1:
94             j2 = get_next_paragraph(lines, j+1)
95             lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1))
96
97         new = floats[floattype]+[""]
98
99         # Check if the float is floatingfigure
100         k = find_re(lines, pextra_type3_rexp, i, j)
101         if k != -1:
102             mo = pextra_rexp.search(lines[k])
103             width = get_width(mo)
104             lines[k] = re.sub(pextra_rexp, "", lines[k])
105             new = ["\\begin_inset Wrap figure",
106                    'width "%s"' % width,
107                    "collapsed false",
108                    ""]
109
110         new = new+lines[i2:j]+["\\end_inset ", ""]
111
112         # After a float, all font attributes are reseted.
113         # We need to output '\foo default' for every attribute foo
114         # whose value is not default before the float.
115         # The check here is not accurate, but it doesn't matter
116         # as extra '\foo default' commands are ignored.
117         # In fact, it might be safer to output '\foo default' for all
118         # font attributes.
119         k = get_paragraph(lines, i)
120         flag = 0
121         for token in font_tokens:
122             if find_token(lines, token, k, i) != -1:
123                 if not flag:
124                     # This is not necessary, but we want the output to be
125                     # as similar as posible to the lyx format
126                     flag = 1
127                     new.append("")
128                 if token == "\\lang":
129                     new.append(token+" "+ file.language)
130                 else:
131                     new.append(token+" default ")
132
133         lines[i:j+1] = new
134         i = i+1
135
136
137 pextra_type2_rexp = re.compile(r".*\\pextra_type\s+[12]")
138 pextra_type2_rexp2 = re.compile(r".*(\\layout|\\pextra_type\s+2)")
139
140 def remove_pextra(file):
141     lines = file.body
142     i = 0
143     flag = 0
144     while 1:
145         i = find_re(lines, pextra_type2_rexp, i)
146         if i == -1:
147             break
148
149         mo = pextra_rexp.search(lines[i])
150         width = get_width(mo)
151
152         if mo.group(1) == "1":
153             # handle \pextra_type 1 (indented paragraph)
154             lines[i] = re.sub(pextra_rexp, "\\leftindent "+width+" ", lines[i])
155             i = i+1
156             continue
157
158         # handle \pextra_type 2 (minipage)
159         position = mo.group(3)
160         hfill = mo.group(5)
161         lines[i] = re.sub(pextra_rexp, "", lines[i])
162
163         start = ["\\begin_inset Minipage",
164                  "position " + position,
165                  "inner_position 0",
166                  'height "0pt"',
167                  'width "%s"' % width,
168                  "collapsed false"
169                  ]
170         if flag:
171             flag = 0
172             if hfill:
173                 start = ["","\hfill",""]+start
174         else:
175             start = ["\\layout Standard"] + start
176
177         j0 = find_token_backwards(lines,"\\layout", i-1)
178         j = get_next_paragraph(lines, i)
179
180         count = 0
181         while 1:
182             # collect more paragraphs to the minipage
183             count = count+1
184             if j == -1 or not check_token(lines[j], "\\layout"):
185                 break
186             i = find_re(lines, pextra_type2_rexp2, j+1)
187             if i == -1:
188                 break
189             mo = pextra_rexp.search(lines[i])
190             if not mo:
191                 break
192             if mo.group(7) == "1":
193                 flag = 1
194                 break
195             lines[i] = re.sub(pextra_rexp, "", lines[i])
196             j = find_tokens(lines, ["\\layout", "\\end_float"], i+1)
197
198         mid = lines[j0:j]
199         end = ["\\end_inset "]
200
201         lines[j0:j] = start+mid+end
202         i = i+1
203
204
205 def is_empty(lines):
206     return filter(is_nonempty_line, lines) == []
207
208
209 move_rexp =  re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun|end_deeper)")
210 ert_rexp = re.compile(r"\\begin_inset|\\hfill|.*\\SpecialChar")
211 spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)")
212 ert_begin = ["\\begin_inset ERT",
213              "status Collapsed",
214              "",
215              "\\layout Standard"]
216
217
218 def remove_oldert(file):
219     lines = file.body
220     i = 0
221     while 1:
222         i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i)
223         if i == -1:
224             break
225         j = i+1
226         while 1:
227             # \end_inset is for ert inside a tabular cell. The other tokens
228             # are obvious.
229             j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", "\\the_end"],
230                             j)
231             if check_token(lines[j], "\\begin_inset"):
232                 j = find_end_of_inset(lines, j)+1
233             else:
234                 break
235
236         if check_token(lines[j], "\\layout"):
237             while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"):
238                 j = j-1
239
240         # We need to remove insets, special chars & font commands from ERT text
241         new = []
242         new2 = []
243         if check_token(lines[i], "\\layout LaTeX"):
244             new = ["\layout Standard", "", ""]
245             # We have a problem with classes in which Standard is not the default layout!
246
247         k = i+1
248         while 1:
249             k2 = find_re(lines, ert_rexp, k, j)
250             inset = hfill = specialchar = 0
251             if k2 == -1:
252                 k2 = j
253             elif check_token(lines[k2], "\\begin_inset"):
254                 inset = 1
255             elif check_token(lines[k2], "\\hfill"):
256                 hfill = 1
257                 del lines[k2]
258                 j = j-1
259             else:
260                 specialchar = 1
261                 mo = spchar_rexp.match(lines[k2])
262                 lines[k2] = mo.group(1)
263                 specialchar_str = mo.group(2)
264                 k2 = k2+1
265
266             tmp = []
267             for line in lines[k:k2]:
268                 # Move some lines outside the ERT inset:
269                 if move_rexp.match(line):
270                     if new2 == []:
271                         # This is not necessary, but we want the output to be
272                         # as similar as posible to the lyx format
273                         new2 = [""]
274                     new2.append(line)
275                 elif not check_token(line, "\\latex"):
276                     tmp.append(line)
277
278             if is_empty(tmp):
279                 if filter(lambda x:x != "", tmp) != []:
280                     if new == []:
281                         # This is not necessary, but we want the output to be
282                         # as similar as posible to the lyx format
283                         lines[i-1] = lines[i-1]+" "
284                     else:
285                         new = new+[" "]
286             else:
287                 new = new+ert_begin+tmp+["\\end_inset ", ""]
288
289             if inset:
290                 k3 = find_end_of_inset(lines, k2)
291                 new = new+[""]+lines[k2:k3+1]+[""] # Put an empty line after \end_inset
292                 k = k3+1
293                 # Skip the empty line after \end_inset
294                 if not is_nonempty_line(lines[k]):
295                     k = k+1
296                     new.append("")
297             elif hfill:
298                 new = new + ["\\hfill", ""]
299                 k = k2
300             elif specialchar:
301                 if new == []:
302                     # This is not necessary, but we want the output to be
303                     # as similar as posible to the lyx format
304                     lines[i-1] = lines[i-1]+specialchar_str
305                     new = [""]
306                 else:
307                     new = new+[specialchar_str, ""]
308                 k = k2
309             else:
310                 break
311
312         new = new+new2
313         if not check_token(lines[j], "\\latex "):
314             new = new+[""]+[lines[j]]
315         lines[i:j+1] = new
316         i = i+1
317
318     # Delete remaining "\latex xxx" tokens
319     i = 0
320     while 1:
321         i = find_token(lines, "\\latex ", i)
322         if i == -1:
323             break
324         del lines[i]
325
326
327 # ERT insert are hidden feature of lyx 1.1.6. This might be removed in the future.
328 def remove_oldertinset(file):
329     lines = file.body
330     i = 0
331     while 1:
332         i = find_token(lines, "\\begin_inset ERT", i)
333         if i == -1:
334             break
335         j = find_end_of_inset(lines, i)
336         k = find_token(lines, "\\layout", i+1)
337         l = get_paragraph(lines, i)
338         if lines[k] == lines[l]: # same layout
339             k = k+1
340         new = lines[k:j]
341         lines[i:j+1] = new
342         i = i+1
343
344
345 def is_ert_paragraph(lines, i):
346     if not check_token(lines[i], "\\layout Standard"):
347         return 0
348
349     i = find_nonempty_line(lines, i+1)
350     if not check_token(lines[i], "\\begin_inset ERT"):
351         return 0
352
353     j = find_end_of_inset(lines, i)
354     k = find_nonempty_line(lines, j+1)
355     return check_token(lines[k], "\\layout")
356
357
358 def combine_ert(file):
359     lines = file.body
360     i = 0
361     while 1:
362         i = find_token(lines, "\\begin_inset ERT", i)
363         if i == -1:
364             break
365         j = get_paragraph(lines, i)
366         count = 0
367         text = []
368         while is_ert_paragraph(lines, j):
369
370             count = count+1
371             i2 = find_token(lines, "\\layout", j+1)
372             k = find_token(lines, "\\end_inset", i2+1)
373             text = text+lines[i2:k]
374             j = find_token(lines, "\\layout", k+1)
375             if j == -1:
376                 break
377
378         if count >= 2:
379             j = find_token(lines, "\\layout", i+1)
380             lines[j:k] = text
381
382         i = i+1
383
384
385 oldunits = ["pt", "cm", "in", "text%", "col%"]
386
387 def get_length(lines, name, start, end):
388     i = find_token(lines, name, start, end)
389     if i == -1:
390         return ""
391     x = string.split(lines[i])
392     return x[2]+oldunits[int(x[1])]
393
394
395 def write_attribute(x, token, value):
396     if value != "":
397         x.append("\t"+token+" "+value)
398
399
400 def remove_figinset(file):
401     lines = file.body
402     i = 0
403     while 1:
404         i = find_token(lines, "\\begin_inset Figure", i)
405         if i == -1:
406             break
407         j = find_end_of_inset(lines, i)
408
409         if ( len(string.split(lines[i])) > 2 ):
410             lyxwidth = string.split(lines[i])[3]+"pt"
411             lyxheight = string.split(lines[i])[4]+"pt"
412         else:
413             lyxwidth = ""
414             lyxheight = ""
415
416         filename = get_value(lines, "file", i+1, j)
417
418         width = get_length(lines, "width", i+1, j)
419         # what does width=5 mean ?
420         height = get_length(lines, "height", i+1, j)
421         rotateAngle = get_value(lines, "angle", i+1, j)
422         if width == "" and height == "":
423             size_type = "0"
424         else:
425             size_type = "1"
426
427         flags = get_value(lines, "flags", i+1, j)
428         x = int(flags)%4
429         if x == 1:
430             display = "monochrome"
431         elif x == 2:
432             display = "gray"
433         else:
434             display = "color"
435
436         subcaptionText = ""
437         subcaptionLine = find_token(lines, "subcaption", i+1, j)
438         if subcaptionLine != -1:
439             subcaptionText = lines[subcaptionLine][11:]
440             if subcaptionText != "":
441                 subcaptionText = '"'+subcaptionText+'"'
442
443         k = find_token(lines, "subfigure", i+1,j)
444         if k == -1:
445             subcaption = 0
446         else:
447             subcaption = 1
448
449         new = ["\\begin_inset Graphics FormatVersion 1"]
450         write_attribute(new, "filename", filename)
451         write_attribute(new, "display", display)
452         if subcaption:
453             new.append("\tsubcaption")
454         write_attribute(new, "subcaptionText", subcaptionText)
455         write_attribute(new, "size_type", size_type)
456         write_attribute(new, "width", width)
457         write_attribute(new, "height", height)
458         if rotateAngle != "":
459             new.append("\trotate")
460             write_attribute(new, "rotateAngle", rotateAngle)
461         write_attribute(new, "rotateOrigin", "leftBaseline")
462         write_attribute(new, "lyxsize_type", "1")
463         write_attribute(new, "lyxwidth", lyxwidth)
464         write_attribute(new, "lyxheight", lyxheight)
465         new = new + ["\\end_inset"]
466         lines[i:j+1] = new
467
468
469 ##
470 # Convert tabular format 2 to 3
471 #
472 attr_re = re.compile(r' \w*="(false|0|)"')
473 line_re = re.compile(r'<(features|column|row|cell)')
474
475 def update_tabular(file):
476     lines = file.body
477     i = 0
478     while 1:
479         i = find_token(lines, '\\begin_inset  Tabular', i)
480         if i == -1:
481             break
482
483         for k in get_tabular_lines(lines, i):
484             if check_token(lines[k], "<lyxtabular"):
485                 lines[k] = string.replace(lines[k], 'version="2"', 'version="3"')
486             elif check_token(lines[k], "<column"):
487                 lines[k] = string.replace(lines[k], 'width=""', 'width="0pt"')
488
489             if line_re.match(lines[k]):
490                 lines[k] = re.sub(attr_re, "", lines[k])
491
492         i = i+1
493
494
495 ##
496 # Convert tabular format 2 to 3
497 #
498 # compatibility read for old longtable options. Now we can make any
499 # row part of the header/footer type we want before it was strict
500 # sequential from the first row down (as LaTeX does it!). So now when
501 # we find a header/footer line we have to go up the rows and set it
502 # on all preceding rows till the first or one with already a h/f option
503 # set. If we find a firstheader on the same line as a header or a
504 # lastfooter on the same line as a footer then this should be set empty.
505 # (Jug 20011220)
506
507 # just for compatibility with old python versions
508 # python >= 2.3 has real booleans (False and True)
509 false = 0
510 true = 1
511
512 # simple data structure to deal with long table info
513 class row:
514     def __init__(self):
515         self.endhead = false            # header row
516         self.endfirsthead = false       # first header row
517         self.endfoot = false            # footer row
518         self.endlastfoot = false        # last footer row
519
520
521 def haveLTFoot(row_info):
522     for row_ in row_info:
523         if row_.endfoot:
524             return true
525     return false
526
527
528 def setHeaderFooterRows(hr, fhr, fr, lfr, rows_, row_info):
529     endfirsthead_empty = false
530     endlastfoot_empty = false
531     # set header info
532     while (hr > 0):
533         hr = hr - 1
534         row_info[hr].endhead = true
535
536     # set firstheader info
537     if fhr and fhr < rows_:
538         if row_info[fhr].endhead:
539             while fhr > 0:
540                 fhr = fhr - 1
541                 row_info[fhr].endfirsthead = true
542                 row_info[fhr].endhead = false
543         elif row_info[fhr - 1].endhead:
544             endfirsthead_empty = true
545         else:
546             while fhr > 0 and not row_info[fhr - 1].endhead:
547                 fhr = fhr - 1
548                 row_info[fhr].endfirsthead = true
549
550     # set footer info
551     if fr and fr < rows_:
552         if row_info[fr].endhead and row_info[fr - 1].endhead:
553             while fr > 0 and not row_info[fr - 1].endhead:
554                 fr = fr - 1
555                 row_info[fr].endfoot = true
556                 row_info[fr].endhead = false
557         elif row_info[fr].endfirsthead and row_info[fr - 1].endfirsthead:
558             while fr > 0 and not row_info[fr - 1].endfirsthead:
559                 fr = fr - 1
560                 row_info[fr].endfoot = true
561                 row_info[fr].endfirsthead = false
562         elif not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead:
563             while fr > 0 and not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead:
564                 fr = fr - 1
565                 row_info[fr].endfoot = true
566
567     # set lastfooter info
568     if lfr and lfr < rows_:
569         if row_info[lfr].endhead and row_info[lfr - 1].endhead:
570             while lfr > 0 and not row_info[lfr - 1].endhead:
571                 lfr = lfr - 1
572                 row_info[lfr].endlastfoot = true
573                 row_info[lfr].endhead = false
574         elif row_info[lfr].endfirsthead and row_info[lfr - 1].endfirsthead:
575             while lfr > 0 and not row_info[lfr - 1].endfirsthead:
576                 lfr = lfr - 1
577                 row_info[lfr].endlastfoot = true
578                 row_info[lfr].endfirsthead = false
579         elif row_info[lfr].endfoot and row_info[lfr - 1].endfoot:
580             while lfr > 0 and not row_info[lfr - 1].endfoot:
581                 lfr = lfr - 1
582                 row_info[lfr].endlastfoot = true
583                 row_info[lfr].endfoot = false
584         elif not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead and not row_info[fr - 1].endfoot:
585             while lfr > 0 and not row_info[lfr - 1].endhead and not row_info[lfr - 1].endfirsthead and not row_info[lfr - 1].endfoot:
586                 lfr = lfr - 1
587                 row_info[lfr].endlastfoot = true
588         elif haveLTFoot(row_info):
589             endlastfoot_empty = true
590
591     return endfirsthead_empty, endlastfoot_empty
592
593
594 def insert_attribute(lines, i, attribute):
595     last = string.find(lines[i],'>')
596     lines[i] = lines[i][:last] + ' ' + attribute + lines[i][last:]
597
598
599 rows_re = re.compile(r'rows="(\d*)"')
600 longtable_re = re.compile(r'islongtable="(\w)"')
601 ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"')
602 lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")')
603 def update_longtables(file):
604     body = file.body
605     i = 0
606     while 1:
607         i = find_token(body, '\\begin_inset  Tabular', i)
608         if i == -1:
609             break
610         i = i + 1
611         i = find_token(body, "<lyxtabular", i)
612         if i == -1:
613             break
614
615         # get number of rows in the table
616         rows = int(rows_re.search(body[i]).group(1))
617
618         i = i + 1
619         i = find_token(body, '<features', i)
620         if i == -1:
621             break
622     
623         # is this a longtable?
624         longtable = longtable_re.search(body[i])
625
626         if not longtable:
627             # islongtable is missing add it
628             body[i] = body[i][:10] + 'islongtable="false" ' + body[i][10:]
629
630         if not longtable or longtable.group(1) != "true":
631             # remove longtable elements from features
632             features = lt_features_re.search(body[i])
633             if features:
634                 body[i] = string.replace(body[i], features.group(1), "")
635             continue
636
637         row_info = row() * rows
638         res = ltvalues_re.search(body[i])
639         if not res:
640             continue
641
642         endfirsthead_empty, endlastfoot_empty = setHeaderFooterRows(res.group(1), res.group(2), res.group(3), res.group(4), rows, row_info)
643
644         if endfirsthead_empty:
645             insert_attribute(body, i, 'firstHeadEmpty="true"')
646
647         if endfirsthead_empty:
648             insert_attribute(body, i, 'lastFootEmpty="true"')
649
650         i = i + 1
651         for j in range(rows):
652             i = find_token(body, '<row', i)
653
654             self.endfoot = false                # footer row
655             self.endlastfoot = false    # last footer row
656             if row_info[j].endhead:
657                 insert_attribute(body, i, 'endhead="true"')
658
659             if row_info[j].endfirsthead:
660                 insert_attribute(body, i, 'endfirsthead="true"')
661
662             if row_info[j].endfoot:
663                 insert_attribute(body, i, 'endfoot="true"')
664
665             if row_info[j].endlastfoot:
666                 insert_attribute(body, i, 'endlastfoot="true"')
667
668             i = i + 1
669
670
671 # Figure insert are hidden feature of lyx 1.1.6. This might be removed in the future.
672 def fix_oldfloatinset(file):
673     lines = file.body
674     i = 0
675     while 1:
676         i = find_token(lines, "\\begin_inset Float ", i)
677         if i == -1:
678             break
679         j = find_token(lines, "collapsed", i)
680         if j != -1:
681             lines[j:j] = ["wide false"]
682         i = i+1
683
684
685 def change_listof(file):
686     lines = file.body
687     i = 0
688     while 1:
689         i = find_token(lines, "\\begin_inset LatexCommand \\listof", i)
690         if i == -1:
691             break
692         type = re.search(r"listof(\w*)", lines[i]).group(1)[:-1]
693         lines[i] = "\\begin_inset FloatList "+type
694         i = i+1
695
696
697 def change_infoinset(file):
698     lines = file.body
699     i = 0
700     while 1:
701         i = find_token(lines, "\\begin_inset Info", i)
702         if i == -1:
703             break
704         txt = string.lstrip(lines[i][18:])
705         new = ["\\begin_inset Note", "collapsed true", ""]
706         j = find_token(lines, "\\end_inset", i)
707         if j == -1:
708             break
709
710         note_lines = lines[i+1:j]
711         if len(txt) > 0:
712             note_lines = [txt]+note_lines
713
714         for line in note_lines:
715             new = new + ["\layout Standard", ""]
716             tmp = string.split(line, '\\')
717             new = new + [tmp[0]]
718             for x in tmp[1:]:
719                 new = new + ["\\backslash ", x]
720         lines[i:j] = new
721         i = i+5
722
723
724 def change_preamble(file):
725     lines = file.header
726     i = find_token(lines, "\\use_amsmath", 0)
727     if i == -1:
728         return
729     lines[i+1:i+1] = ["\\use_natbib 0",
730                       "\use_numerical_citations 0"]
731
732
733 convert = [[220, [change_preamble, change_listof, fix_oldfloatinset,
734                   update_tabular, update_longtables, remove_pextra,
735                   remove_oldfloat, remove_figinset, remove_oldertinset,
736                   remove_oldert, combine_ert, change_infoinset]]]
737 revert  = []
738
739
740 if __name__ == "__main__":
741     pass