]> git.lyx.org Git - lyx.git/blob - lib/lyx2lyx/lyx_1_2.py
fix bug 2026 and bug 2088
[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, get_layout
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, file.format + 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, file.format + 1)
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 pextra_widthp = re.compile(r"\\pextra_widthp")
140
141 def remove_pextra(file):
142     lines = file.body
143     i = 0
144     flag = 0
145     while 1:
146         i = find_re(lines, pextra_type2_rexp, i)
147         if i == -1:
148             break
149
150         # Sometimes the \pextra_widthp argument comes in it own
151         # line. If that happens insert it back in this line.
152         if pextra_widthp.search(lines[i+1]):
153             lines[i] = lines[i] + ' ' + lines[i+1]
154             del lines[i+1]
155
156         mo = pextra_rexp.search(lines[i])
157         width = get_width(mo)
158
159         if mo.group(1) == "1":
160             # handle \pextra_type 1 (indented paragraph)
161             lines[i] = re.sub(pextra_rexp, "\\leftindent "+width+" ", lines[i])
162             i = i+1
163             continue
164
165         # handle \pextra_type 2 (minipage)
166         position = mo.group(3)
167         hfill = mo.group(5)
168         lines[i] = re.sub(pextra_rexp, "", lines[i])
169
170         start = ["\\begin_inset Minipage",
171                  "position " + position,
172                  "inner_position 0",
173                  'height "0pt"',
174                  'width "%s"' % width,
175                  "collapsed false"
176                  ]
177         if flag:
178             flag = 0
179             if hfill:
180                 start = ["","\hfill",""]+start
181         else:
182             start = ['\\layout %s' % file.default_layout,''] + start
183
184         j0 = find_token_backwards(lines,"\\layout", i-1)
185         j = get_next_paragraph(lines, i, file.format + 1)
186
187         count = 0
188         while 1:
189             # collect more paragraphs to the minipage
190             count = count+1
191             if j == -1 or not check_token(lines[j], "\\layout"):
192                 break
193             i = find_re(lines, pextra_type2_rexp2, j+1)
194             if i == -1:
195                 break
196             mo = pextra_rexp.search(lines[i])
197             if not mo:
198                 break
199             if mo.group(7) == "1":
200                 flag = 1
201                 break
202             lines[i] = re.sub(pextra_rexp, "", lines[i])
203             j = find_tokens(lines, ["\\layout", "\\end_float"], i+1)
204
205         mid = lines[j0:j]
206         end = ["\\end_inset "]
207
208         lines[j0:j] = start+mid+end
209         i = i+1
210
211
212 def is_empty(lines):
213     return filter(is_nonempty_line, lines) == []
214
215
216 move_rexp =  re.compile(r"\\(family|series|shape|size|emph|numeric|bar|noun|end_deeper)")
217 ert_rexp = re.compile(r"\\begin_inset|\\hfill|.*\\SpecialChar")
218 spchar_rexp = re.compile(r"(.*)(\\SpecialChar.*)")
219
220
221 def remove_oldert(file):
222     ert_begin = ["\\begin_inset ERT",
223                  "status Collapsed",
224                  "",
225                  '\\layout %s' % file.default_layout,
226                  ""]
227     lines = file.body
228     i = 0
229     while 1:
230         i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i)
231         if i == -1:
232             break
233         j = i+1
234         while 1:
235             # \end_inset is for ert inside a tabular cell. The other tokens
236             # are obvious.
237             j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", "\\the_end"],
238                             j)
239             if check_token(lines[j], "\\begin_inset"):
240                 j = find_end_of_inset(lines, j)+1
241             else:
242                 break
243
244         if check_token(lines[j], "\\layout"):
245             while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"):
246                 j = j-1
247
248         # We need to remove insets, special chars & font commands from ERT text
249         new = []
250         new2 = []
251         if check_token(lines[i], "\\layout LaTeX"):
252             new = ['\layout %s' % file.default_layout, "", ""]
253
254         k = i+1
255         while 1:
256             k2 = find_re(lines, ert_rexp, k, j)
257             inset = hfill = specialchar = 0
258             if k2 == -1:
259                 k2 = j
260             elif check_token(lines[k2], "\\begin_inset"):
261                 inset = 1
262             elif check_token(lines[k2], "\\hfill"):
263                 hfill = 1
264                 del lines[k2]
265                 j = j-1
266             else:
267                 specialchar = 1
268                 mo = spchar_rexp.match(lines[k2])
269                 lines[k2] = mo.group(1)
270                 specialchar_str = mo.group(2)
271                 k2 = k2+1
272
273             tmp = []
274             for line in lines[k:k2]:
275                 # Move some lines outside the ERT inset:
276                 if move_rexp.match(line):
277                     if new2 == []:
278                         # This is not necessary, but we want the output to be
279                         # as similar as posible to the lyx format
280                         new2 = [""]
281                     new2.append(line)
282                 elif not check_token(line, "\\latex"):
283                     tmp.append(line)
284
285             if is_empty(tmp):
286                 if filter(lambda x:x != "", tmp) != []:
287                     if new == []:
288                         # This is not necessary, but we want the output to be
289                         # as similar as posible to the lyx format
290                         lines[i-1] = lines[i-1]+" "
291                     else:
292                         new = new+[" "]
293             else:
294                 new = new+ert_begin+tmp+["\\end_inset ", ""]
295
296             if inset:
297                 k3 = find_end_of_inset(lines, k2)
298                 new = new+[""]+lines[k2:k3+1]+[""] # Put an empty line after \end_inset
299                 k = k3+1
300                 # Skip the empty line after \end_inset
301                 if not is_nonempty_line(lines[k]):
302                     k = k+1
303                     new.append("")
304             elif hfill:
305                 new = new + ["\\hfill", ""]
306                 k = k2
307             elif specialchar:
308                 if new == []:
309                     # This is not necessary, but we want the output to be
310                     # as similar as posible to the lyx format
311                     lines[i-1] = lines[i-1]+specialchar_str
312                     new = [""]
313                 else:
314                     new = new+[specialchar_str, ""]
315                 k = k2
316             else:
317                 break
318
319         new = new+new2
320         if not check_token(lines[j], "\\latex "):
321             new = new+[""]+[lines[j]]
322         lines[i:j+1] = new
323         i = i+1
324
325     # Delete remaining "\latex xxx" tokens
326     i = 0
327     while 1:
328         i = find_token(lines, "\\latex ", i)
329         if i == -1:
330             break
331         del lines[i]
332
333
334 # ERT insert are hidden feature of lyx 1.1.6. This might be removed in the future.
335 def remove_oldertinset(file):
336     lines = file.body
337     i = 0
338     while 1:
339         i = find_token(lines, "\\begin_inset ERT", i)
340         if i == -1:
341             break
342         j = find_end_of_inset(lines, i)
343         k = find_token(lines, "\\layout", i+1)
344         l = get_paragraph(lines, i, file.format + 1)
345         if lines[k] == lines[l]: # same layout
346             k = k+1
347         new = lines[k:j]
348         lines[i:j+1] = new
349         i = i+1
350
351
352 def is_ert_paragraph(file, i):
353     lines = file.body
354     if not check_token(lines[i], "\\layout"):
355         return 0
356     if not file.is_default_layout(get_layout(lines[i], file.default_layout)):
357         return 0
358
359     i = find_nonempty_line(lines, i+1)
360     if not check_token(lines[i], "\\begin_inset ERT"):
361         return 0
362
363     j = find_end_of_inset(lines, i)
364     k = find_nonempty_line(lines, j+1)
365     return check_token(lines[k], "\\layout")
366
367
368 def combine_ert(file):
369     lines = file.body
370     i = 0
371     while 1:
372         i = find_token(lines, "\\begin_inset ERT", i)
373         if i == -1:
374             break
375         j = get_paragraph(lines, i, file.format + 1)
376         count = 0
377         text = []
378         while is_ert_paragraph(file, j):
379
380             count = count+1
381             i2 = find_token(lines, "\\layout", j+1)
382             k = find_token(lines, "\\end_inset", i2+1)
383             text = text+lines[i2:k]
384             j = find_token(lines, "\\layout", k+1)
385             if j == -1:
386                 break
387
388         if count >= 2:
389             j = find_token(lines, "\\layout", i+1)
390             lines[j:k] = text
391
392         i = i+1
393
394
395 oldunits = ["pt", "cm", "in", "text%", "col%"]
396
397 def get_length(lines, name, start, end):
398     i = find_token(lines, name, start, end)
399     if i == -1:
400         return ""
401     x = string.split(lines[i])
402     return x[2]+oldunits[int(x[1])]
403
404
405 def write_attribute(x, token, value):
406     if value != "":
407         x.append("\t"+token+" "+value)
408
409
410 def remove_figinset(file):
411     lines = file.body
412     i = 0
413     while 1:
414         i = find_token(lines, "\\begin_inset Figure", i)
415         if i == -1:
416             break
417         j = find_end_of_inset(lines, i)
418
419         if ( len(string.split(lines[i])) > 2 ):
420             lyxwidth = string.split(lines[i])[3]+"pt"
421             lyxheight = string.split(lines[i])[4]+"pt"
422         else:
423             lyxwidth = ""
424             lyxheight = ""
425
426         filename = get_value(lines, "file", i+1, j)
427
428         width = get_length(lines, "width", i+1, j)
429         # what does width=5 mean ?
430         height = get_length(lines, "height", i+1, j)
431         rotateAngle = get_value(lines, "angle", i+1, j)
432         if width == "" and height == "":
433             size_type = "0"
434         else:
435             size_type = "1"
436
437         flags = get_value(lines, "flags", i+1, j)
438         x = int(flags)%4
439         if x == 1:
440             display = "monochrome"
441         elif x == 2:
442             display = "gray"
443         else:
444             display = "color"
445
446         subcaptionText = ""
447         subcaptionLine = find_token(lines, "subcaption", i+1, j)
448         if subcaptionLine != -1:
449             subcaptionText = lines[subcaptionLine][11:]
450             if subcaptionText != "":
451                 subcaptionText = '"'+subcaptionText+'"'
452
453         k = find_token(lines, "subfigure", i+1,j)
454         if k == -1:
455             subcaption = 0
456         else:
457             subcaption = 1
458
459         new = ["\\begin_inset Graphics FormatVersion 1"]
460         write_attribute(new, "filename", filename)
461         write_attribute(new, "display", display)
462         if subcaption:
463             new.append("\tsubcaption")
464         write_attribute(new, "subcaptionText", subcaptionText)
465         write_attribute(new, "size_type", size_type)
466         write_attribute(new, "width", width)
467         write_attribute(new, "height", height)
468         if rotateAngle != "":
469             new.append("\trotate")
470             write_attribute(new, "rotateAngle", rotateAngle)
471         write_attribute(new, "rotateOrigin", "leftBaseline")
472         write_attribute(new, "lyxsize_type", "1")
473         write_attribute(new, "lyxwidth", lyxwidth)
474         write_attribute(new, "lyxheight", lyxheight)
475         new = new + ["\\end_inset"]
476         lines[i:j+1] = new
477
478
479 ##
480 # Convert tabular format 2 to 3
481 #
482 attr_re = re.compile(r' \w*="(false|0|)"')
483 line_re = re.compile(r'<(features|column|row|cell)')
484
485 def update_tabular(file):
486     regexp = re.compile(r'^\\begin_inset\s+Tabular')
487     lines = file.body
488     i = 0
489     while 1:
490         i = find_re(lines, regexp, i)
491         if i == -1:
492             break
493
494         for k in get_tabular_lines(lines, i):
495             if check_token(lines[k], "<lyxtabular"):
496                 lines[k] = string.replace(lines[k], 'version="2"', 'version="3"')
497             elif check_token(lines[k], "<column"):
498                 lines[k] = string.replace(lines[k], 'width=""', 'width="0pt"')
499
500             if line_re.match(lines[k]):
501                 lines[k] = re.sub(attr_re, "", lines[k])
502
503         i = i+1
504
505
506 ##
507 # Convert tabular format 2 to 3
508 #
509 # compatibility read for old longtable options. Now we can make any
510 # row part of the header/footer type we want before it was strict
511 # sequential from the first row down (as LaTeX does it!). So now when
512 # we find a header/footer line we have to go up the rows and set it
513 # on all preceding rows till the first or one with already a h/f option
514 # set. If we find a firstheader on the same line as a header or a
515 # lastfooter on the same line as a footer then this should be set empty.
516 # (Jug 20011220)
517
518 # just for compatibility with old python versions
519 # python >= 2.3 has real booleans (False and True)
520 false = 0
521 true = 1
522
523 # simple data structure to deal with long table info
524 class row:
525     def __init__(self):
526         self.endhead = false            # header row
527         self.endfirsthead = false       # first header row
528         self.endfoot = false            # footer row
529         self.endlastfoot = false        # last footer row
530
531
532 def haveLTFoot(row_info):
533     for row_ in row_info:
534         if row_.endfoot:
535             return true
536     return false
537
538
539 def setHeaderFooterRows(hr, fhr, fr, lfr, rows_, row_info):
540     endfirsthead_empty = false
541     endlastfoot_empty = false
542     # set header info
543     while (hr > 0):
544         hr = hr - 1
545         row_info[hr].endhead = true
546
547     # set firstheader info
548     if fhr and fhr < rows_:
549         if row_info[fhr].endhead:
550             while fhr > 0:
551                 fhr = fhr - 1
552                 row_info[fhr].endfirsthead = true
553                 row_info[fhr].endhead = false
554         elif row_info[fhr - 1].endhead:
555             endfirsthead_empty = true
556         else:
557             while fhr > 0 and not row_info[fhr - 1].endhead:
558                 fhr = fhr - 1
559                 row_info[fhr].endfirsthead = true
560
561     # set footer info
562     if fr and fr < rows_:
563         if row_info[fr].endhead and row_info[fr - 1].endhead:
564             while fr > 0 and not row_info[fr - 1].endhead:
565                 fr = fr - 1
566                 row_info[fr].endfoot = true
567                 row_info[fr].endhead = false
568         elif row_info[fr].endfirsthead and row_info[fr - 1].endfirsthead:
569             while fr > 0 and not row_info[fr - 1].endfirsthead:
570                 fr = fr - 1
571                 row_info[fr].endfoot = true
572                 row_info[fr].endfirsthead = false
573         elif not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead:
574             while fr > 0 and not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead:
575                 fr = fr - 1
576                 row_info[fr].endfoot = true
577
578     # set lastfooter info
579     if lfr and lfr < rows_:
580         if row_info[lfr].endhead and row_info[lfr - 1].endhead:
581             while lfr > 0 and not row_info[lfr - 1].endhead:
582                 lfr = lfr - 1
583                 row_info[lfr].endlastfoot = true
584                 row_info[lfr].endhead = false
585         elif row_info[lfr].endfirsthead and row_info[lfr - 1].endfirsthead:
586             while lfr > 0 and not row_info[lfr - 1].endfirsthead:
587                 lfr = lfr - 1
588                 row_info[lfr].endlastfoot = true
589                 row_info[lfr].endfirsthead = false
590         elif row_info[lfr].endfoot and row_info[lfr - 1].endfoot:
591             while lfr > 0 and not row_info[lfr - 1].endfoot:
592                 lfr = lfr - 1
593                 row_info[lfr].endlastfoot = true
594                 row_info[lfr].endfoot = false
595         elif not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead and not row_info[fr - 1].endfoot:
596             while lfr > 0 and not row_info[lfr - 1].endhead and not row_info[lfr - 1].endfirsthead and not row_info[lfr - 1].endfoot:
597                 lfr = lfr - 1
598                 row_info[lfr].endlastfoot = true
599         elif haveLTFoot(row_info):
600             endlastfoot_empty = true
601
602     return endfirsthead_empty, endlastfoot_empty
603
604
605 def insert_attribute(lines, i, attribute):
606     last = string.find(lines[i],'>')
607     lines[i] = lines[i][:last] + ' ' + attribute + lines[i][last:]
608
609
610 rows_re = re.compile(r'rows="(\d*)"')
611 longtable_re = re.compile(r'islongtable="(\w)"')
612 ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"')
613 lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")')
614 def update_longtables(file):
615     regexp = re.compile(r'^\\begin_inset\s+Tabular')
616     body = file.body
617     i = 0
618     while 1:
619         i = find_re(body, regexp, i)
620         if i == -1:
621             break
622         i = i + 1
623         i = find_token(body, "<lyxtabular", i)
624         if i == -1:
625             break
626
627         # get number of rows in the table
628         rows = int(rows_re.search(body[i]).group(1))
629
630         i = i + 1
631         i = find_token(body, '<features', i)
632         if i == -1:
633             break
634
635         # is this a longtable?
636         longtable = longtable_re.search(body[i])
637
638         if not longtable:
639             # islongtable is missing add it
640             body[i] = body[i][:10] + 'islongtable="false" ' + body[i][10:]
641
642         if not longtable or longtable.group(1) != "true":
643             # remove longtable elements from features
644             features = lt_features_re.search(body[i])
645             if features:
646                 body[i] = string.replace(body[i], features.group(1), "")
647             continue
648
649         row_info = row() * rows
650         res = ltvalues_re.search(body[i])
651         if not res:
652             continue
653
654         endfirsthead_empty, endlastfoot_empty = setHeaderFooterRows(res.group(1), res.group(2), res.group(3), res.group(4), rows, row_info)
655
656         if endfirsthead_empty:
657             insert_attribute(body, i, 'firstHeadEmpty="true"')
658
659         if endfirsthead_empty:
660             insert_attribute(body, i, 'lastFootEmpty="true"')
661
662         i = i + 1
663         for j in range(rows):
664             i = find_token(body, '<row', i)
665
666             self.endfoot = false                # footer row
667             self.endlastfoot = false    # last footer row
668             if row_info[j].endhead:
669                 insert_attribute(body, i, 'endhead="true"')
670
671             if row_info[j].endfirsthead:
672                 insert_attribute(body, i, 'endfirsthead="true"')
673
674             if row_info[j].endfoot:
675                 insert_attribute(body, i, 'endfoot="true"')
676
677             if row_info[j].endlastfoot:
678                 insert_attribute(body, i, 'endlastfoot="true"')
679
680             i = i + 1
681
682
683 # Figure insert are hidden feature of lyx 1.1.6. This might be removed in the future.
684 def fix_oldfloatinset(file):
685     lines = file.body
686     i = 0
687     while 1:
688         i = find_token(lines, "\\begin_inset Float ", i)
689         if i == -1:
690             break
691         j = find_token(lines, "collapsed", i)
692         if j != -1:
693             lines[j:j] = ["wide false"]
694         i = i+1
695
696
697 def change_listof(file):
698     lines = file.body
699     i = 0
700     while 1:
701         i = find_token(lines, "\\begin_inset LatexCommand \\listof", i)
702         if i == -1:
703             break
704         type = re.search(r"listof(\w*)", lines[i]).group(1)[:-1]
705         lines[i] = "\\begin_inset FloatList "+type
706         i = i+1
707
708
709 def change_infoinset(file):
710     lines = file.body
711     i = 0
712     while 1:
713         i = find_token(lines, "\\begin_inset Info", i)
714         if i == -1:
715             break
716         txt = string.lstrip(lines[i][18:])
717         new = ["\\begin_inset Note", "collapsed true", ""]
718         j = find_token(lines, "\\end_inset", i)
719         if j == -1:
720             break
721
722         note_lines = lines[i+1:j]
723         if len(txt) > 0:
724             note_lines = [txt]+note_lines
725
726         for line in note_lines:
727             new = new + ['\layout %s' % file.default_layout, ""]
728             tmp = string.split(line, '\\')
729             new = new + [tmp[0]]
730             for x in tmp[1:]:
731                 new = new + ["\\backslash ", x]
732         lines[i:j] = new
733         i = i+5
734
735
736 def change_header(file):
737     lines = file.header
738     i = find_token(lines, "\\use_amsmath", 0)
739     if i == -1:
740         return
741     lines[i+1:i+1] = ["\\use_natbib 0",
742                       "\use_numerical_citations 0"]
743
744
745 convert = [[220, [change_header, change_listof, fix_oldfloatinset,
746                   update_tabular, update_longtables, remove_pextra,
747                   remove_oldfloat, remove_figinset, remove_oldertinset,
748                   remove_oldert, combine_ert, change_infoinset]]]
749 revert  = []
750
751
752 if __name__ == "__main__":
753     pass