1 # This file is part of lyx2lyx
2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
4 # Copyright (C) 2002-2004 José Matos <jamatos@lyx.org>
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.
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.
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.
21 from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
22 get_paragraph, get_value, del_token, is_nonempty_line,\
23 find_tokens, find_end_of
24 from string import replace, split, find, strip, join
29 def add_end_header(header):
30 header.append("\\end_header");
33 def rm_end_header(lines):
34 i = find_token(lines, "\\end_header", 0)
41 # \SpecialChar ~ -> \InsetSpace ~
43 def convert_spaces(lines):
44 for i in range(len(lines)):
45 lines[i] = replace(lines[i],"\\SpecialChar ~","\\InsetSpace ~")
48 def revert_spaces(lines):
49 for i in range(len(lines)):
50 lines[i] = replace(lines[i],"\\InsetSpace ~", "\\SpecialChar ~")
56 def convert_bibtex(lines):
57 for i in range(len(lines)):
58 lines[i] = replace(lines[i],"\\begin_inset LatexCommand \\BibTeX",
59 "\\begin_inset LatexCommand \\bibtex")
62 def revert_bibtex(lines):
63 for i in range(len(lines)):
64 lines[i] = replace(lines[i], "\\begin_inset LatexCommand \\bibtex",
65 "\\begin_inset LatexCommand \\BibTeX")
71 def remove_insetparent(lines):
74 i = find_token(lines, "\\begin_inset LatexCommand \\lyxparent", i)
83 def convert_external(lines):
84 external_rexp = re.compile(r'\\begin_inset External ([^,]*),"([^"]*)",')
85 external_header = "\\begin_inset External"
88 i = find_token(lines, external_header, i)
91 look = external_rexp.search(lines[i])
94 args[0] = look.group(1)
95 args[1] = look.group(2)
96 #FIXME: if the previous search fails then warn
98 if args[0] == "RasterImage":
99 # Convert a RasterImage External Inset to a Graphics Inset.
100 top = "\\begin_inset Graphics"
102 filename = "\tfilename " + args[1]
103 lines[i:i+1] = [top, filename]
106 # Convert the old External Inset format to the new.
107 top = external_header
108 template = "\ttemplate " + args[0]
110 filename = "\tfilename " + args[1]
111 lines[i:i+1] = [top, template, filename]
114 lines[i:i+1] = [top, template]
118 def revert_external_1(lines):
119 external_header = "\\begin_inset External"
122 i = find_token(lines, external_header, i)
126 template = split(lines[i+1])
130 filename = split(lines[i+1])
134 params = split(lines[i+1])
136 if lines[i+1]: del lines[i+1]
138 lines[i] = lines[i] + " " + template[0]+ ', "' + filename[0] + '", " '+ join(params[1:]) + '"'
142 def revert_external_2(lines):
143 draft_token = '\tdraft'
146 i = find_token(lines, '\\begin_inset External', i)
149 j = find_end_of_inset(lines, i + 1)
151 #this should not happen
153 k = find_token(lines, draft_token, i+1, j-1)
154 if (k != -1 and len(draft_token) == len(lines[k])):
162 def convert_comment(lines):
164 comment = "\\layout Comment"
166 i = find_token(lines, comment, i)
170 lines[i:i+1] = ["\\layout Standard","","",
171 "\\begin_inset Comment",
178 i = find_token(lines, "\\layout", i)
181 lines[i:i] = ["\\end_inset ","",""]
184 j = find_token(lines, '\\begin_deeper', old_i, i)
185 if j == -1: j = i + 1
186 k = find_token(lines, '\\begin_inset', old_i, i)
187 if k == -1: k = i + 1
192 i = find_end_of( lines, i, "\\begin_deeper","\\end_deeper")
194 #This case should not happen
195 #but if this happens deal with it greacefully adding
196 #the missing \end_deeper.
198 lines[i:i] = ["\end_deeper","","","\\end_inset ","",""]
206 i = find_end_of( lines, i, "\\begin_inset","\\end_inset")
208 #This case should not happen
209 #but if this happens deal with it greacefully adding
210 #the missing \end_inset.
212 lines[i:i] = ["\\end_inset ","","","\\end_inset ","",""]
218 if find(lines[i], comment) == -1:
219 lines[i:i] = ["\\end_inset"]
222 lines[i:i+1] = ["\\layout Standard"]
226 def revert_comment(lines):
229 i = find_tokens(lines, ["\\begin_inset Comment", "\\begin_inset Greyedout"], i)
233 lines[i] = "\\begin_inset Note"
240 def add_end_layout(lines):
241 i = find_token(lines, '\\layout', 0)
247 struct_stack = ["\\layout"]
249 i = find_tokens(lines, ["\\begin_inset", "\\end_inset", "\\layout",
250 "\\begin_deeper", "\\end_deeper", "\\the_end"], i)
252 token = split(lines[i])[0]
254 if token == "\\begin_inset":
255 struct_stack.append(token)
259 if token == "\\end_inset":
260 tail = struct_stack.pop()
261 if tail == "\\layout":
262 lines.insert(i,"\\end_layout")
264 #Check if it is the correct tag
269 if token == "\\layout":
270 tail = struct_stack.pop()
272 lines.insert(i,"\\end_layout")
275 struct_stack.append(tail)
277 struct_stack.append(token)
280 if token == "\\begin_deeper" or token == "\\end_deeper":
281 lines.insert(i,"\\end_layout")
286 lines.insert(i, "\\end_layout")
290 def rm_end_layout(lines):
293 i = find_token(lines, '\\end_layout', i)
302 # Remove change tracking keywords
304 def rm_tracking_changes(lines):
305 i = find_token(lines, "\\author", 0)
309 i = find_token(lines, "\\tracking_changes", 0)
315 def rm_body_changes(lines):
318 i = find_token(lines, "\\change_", i)
326 # \layout -> \begin_layout
328 def layout2begin_layout(lines):
331 i = find_token(lines, '\\layout', i)
335 lines[i] = replace(lines[i], '\\layout', '\\begin_layout')
339 def begin_layout2layout(lines):
342 i = find_token(lines, '\\begin_layout', i)
346 lines[i] = replace(lines[i], '\\begin_layout', '\\layout')
351 # valignment="center" -> valignment="middle"
353 def convert_valignment_middle(lines, start, end):
354 for i in range(start, end):
355 if re.search('^<(column|cell) .*valignment="center".*>$', lines[i]):
356 lines[i] = replace(lines[i], 'valignment="center"', 'valignment="middle"')
359 def convert_table_valignment_middle(lines):
362 i = find_token(lines, '\\begin_inset Tabular', i)
365 j = find_end_of_inset(lines, i + 1)
367 #this should not happen
368 convert_valignment_middle(lines, i + 1, len(lines))
370 convert_valignment_middle(lines, i + 1, j)
374 def revert_table_valignment_middle(lines, start, end):
375 for i in range(start, end):
376 if re.search('^<(column|cell) .*valignment="middle".*>$', lines[i]):
377 lines[i] = replace(lines[i], 'valignment="middle"', 'valignment="center"')
380 def revert_valignment_middle(lines):
383 i = find_token(lines, '\\begin_inset Tabular', i)
386 j = find_end_of_inset(lines, i + 1)
388 #this should not happen
389 revert_table_valignment_middle(lines, i + 1, len(lines))
391 revert_table_valignment_middle(lines, i + 1, j)
396 # \the_end -> \end_document
398 def convert_end_document(lines):
399 i = find_token(lines, "\\the_end", 0)
401 lines.append("\\end_document")
403 lines[i] = "\\end_document"
406 def revert_end_document(lines):
407 i = find_token(lines, "\\end_document", 0)
409 lines.append("\\the_end")
411 lines[i] = "\\the_end"
415 # Convert line and page breaks
418 #\line_top \line_bottom \pagebreak_top \pagebreak_bottom \added_space_top xxx \added_space_bottom yyy
422 #\begin layout Standard
427 #\begin_inset VSpace xxx
431 #\begin_layout Standard
435 #\begin_layout Standard
437 #\begin_inset VSpace xxx
444 def convert_breaks(lines):
447 i = find_token(lines, "\\begin_layout", i)
451 line_top = find(lines[i],"\\line_top")
452 line_bot = find(lines[i],"\\line_bottom")
453 pb_top = find(lines[i],"\\pagebreak_top")
454 pb_bot = find(lines[i],"\\pagebreak_bottom")
455 vspace_top = find(lines[i],"\\added_space_top")
456 vspace_bot = find(lines[i],"\\added_space_bottom")
458 if line_top == -1 and line_bot == -1 and pb_bot == -1 and pb_top == -1 and vspace_top == -1 and vspace_bot == -1:
461 for tag in "\\line_top", "\\line_bottom", "\\pagebreak_top", "\\pagebreak_bottom":
462 lines[i] = replace(lines[i], tag, "")
465 # the position could be change because of the removal of other
466 # paragraph properties above
467 vspace_top = find(lines[i],"\\added_space_top")
468 tmp_list = split(lines[i][vspace_top:])
469 vspace_top_value = tmp_list[1]
470 lines[i] = lines[i][:vspace_top] + join(tmp_list[2:])
473 # the position could be change because of the removal of other
474 # paragraph properties above
475 vspace_bot = find(lines[i],"\\added_space_bottom")
476 tmp_list = split(lines[i][vspace_bot:])
477 vspace_bot_value = tmp_list[1]
478 lines[i] = lines[i][:vspace_bot] + join(tmp_list[2:])
480 lines[i] = strip(lines[i])
483 # Create an empty paragraph for line and page break that belong
484 # above the paragraph
485 if pb_top !=-1 or line_top != -1 or vspace_bot != -1:
487 paragraph_above = ['','\\begin_layout Standard','','']
490 paragraph_above.extend(['\\newpage ',''])
493 paragraph_above.extend(['\\begin_inset VSpace ' + vspace_top_value,'\\end_inset ','',''])
496 paragraph_above.extend(['\\lyxline ',''])
498 paragraph_above.extend(['\\end_layout',''])
500 #inset new paragraph above the current paragraph
501 lines[i-2:i-2] = paragraph_above
502 i = i + len(paragraph_above)
504 # Ensure that nested style are converted later.
505 k = find_end_of(lines, i, "\\begin_layout", "\\end_layout")
510 if pb_top !=-1 or line_top != -1 or vspace_bot != -1:
512 paragraph_bellow = ['','\\begin_layout Standard','','']
515 paragraph_bellow.extend(['\\lyxline ',''])
518 paragraph_bellow.extend(['\\begin_inset VSpace ' + vspace_bot_value,'\\end_inset ','',''])
521 paragraph_bellow.extend(['\\newpage ',''])
523 paragraph_bellow.extend(['\\end_layout',''])
525 #inset new paragraph above the current paragraph
526 lines[k + 1: k + 1] = paragraph_bellow
532 def convert_note(lines):
535 i = find_tokens(lines, ["\\begin_inset Note",
536 "\\begin_inset Comment",
537 "\\begin_inset Greyedout"], i)
541 lines[i] = lines[i][0:13] + 'Note ' + lines[i][13:]
545 def revert_note(lines):
546 note_header = "\\begin_inset Note "
549 i = find_token(lines, note_header, i)
553 lines[i] = "\\begin_inset " + lines[i][len(note_header):]
560 def convert_box(lines):
563 i = find_tokens(lines, ["\\begin_inset Boxed",
564 "\\begin_inset Doublebox",
565 "\\begin_inset Frameless",
566 "\\begin_inset ovalbox",
567 "\\begin_inset Ovalbox",
568 "\\begin_inset Shadowbox"], i)
572 lines[i] = lines[i][0:13] + 'Box ' + lines[i][13:]
576 def revert_box(lines):
577 box_header = "\\begin_inset Box "
580 i = find_token(lines, box_header, i)
584 lines[i] = "\\begin_inset " + lines[i][len(box_header):]
591 def convert_collapsable(lines, opt):
594 i = find_tokens(lines, ["\\begin_inset Box",
595 "\\begin_inset Branch",
596 "\\begin_inset CharStyle",
597 "\\begin_inset Float",
598 "\\begin_inset Foot",
599 "\\begin_inset Marginal",
600 "\\begin_inset Note",
601 "\\begin_inset OptArg",
602 "\\begin_inset Wrap"], i)
606 # Seach for a line starting 'collapsed'
607 # If, however, we find a line starting '\begin_layout'
608 # (_always_ present) then break with a warning message
611 if (lines[i] == "collapsed false"):
612 lines[i] = "status open"
614 elif (lines[i] == "collapsed true"):
615 lines[i] = "status collapsed"
617 elif (lines[i][:13] == "\\begin_layout"):
618 opt.warning("Malformed LyX file.")
625 def revert_collapsable(lines, opt):
628 i = find_tokens(lines, ["\\begin_inset Box",
629 "\\begin_inset Branch",
630 "\\begin_inset CharStyle",
631 "\\begin_inset Float",
632 "\\begin_inset Foot",
633 "\\begin_inset Marginal",
634 "\\begin_inset Note",
635 "\\begin_inset OptArg",
636 "\\begin_inset Wrap"], i)
640 # Seach for a line starting 'status'
641 # If, however, we find a line starting '\begin_layout'
642 # (_always_ present) then break with a warning message
645 if (lines[i] == "status open"):
646 lines[i] = "collapsed false"
648 elif (lines[i] == "status collapsed" or
649 lines[i] == "status inlined"):
650 lines[i] = "collapsed true"
652 elif (lines[i][:13] == "\\begin_layout"):
653 opt.warning("Malformed LyX file.")
663 def convert_ert(lines, opt):
666 i = find_token(lines, "\\begin_inset ERT", i)
670 # Seach for a line starting 'status'
671 # If, however, we find a line starting '\begin_layout'
672 # (_always_ present) then break with a warning message
675 if (lines[i] == "status Open"):
676 lines[i] = "status open"
678 elif (lines[i] == "status Collapsed"):
679 lines[i] = "status collapsed"
681 elif (lines[i] == "status Inlined"):
682 lines[i] = "status inlined"
684 elif (lines[i][:13] == "\\begin_layout"):
685 opt.warning("Malformed LyX file.")
692 def revert_ert(lines, opt):
695 i = find_token(lines, "\\begin_inset ERT", i)
699 # Seach for a line starting 'status'
700 # If, however, we find a line starting '\begin_layout'
701 # (_always_ present) then break with a warning message
704 if (lines[i] == "status open"):
705 lines[i] = "status Open"
707 elif (lines[i] == "status collapsed"):
708 lines[i] = "status Collapsed"
710 elif (lines[i] == "status inlined"):
711 lines[i] = "status Inlined"
713 elif (lines[i][:13] == "\\begin_layout"):
714 opt.warning("Malformed LyX file.")
724 def convert_minipage(lines):
725 """ Convert minipages to the box inset.
726 We try to use the same order of arguments as lyx does.
729 inner_pos = ["c","t","b","s"]
733 i = find_token(lines, "\\begin_inset Minipage", i)
737 lines[i] = "\\begin_inset Box Frameless"
740 # convert old to new position using the pos list
741 if lines[i][:8] == "position":
742 lines[i] = 'position "%s"' % pos[int(lines[i][9])]
744 lines.insert(i, 'position "%s"' % pos[0])
747 lines.insert(i, 'hor_pos "c"')
749 lines.insert(i, 'has_inner_box 1')
752 # convert the inner_position
753 if lines[i][:14] == "inner_position":
754 lines[i] = 'inner_pos "%s"' % inner_pos[int(lines[i][15])]
756 lines.insert('inner_pos "%s"' % inner_pos[0])
759 # We need this since the new file format has a height and width
760 # in a different order.
761 if lines[i][:6] == "height":
762 height = lines[i][6:]
763 # test for default value of 221 and convert it accordingly
764 if height == ' "0pt"':
770 if lines[i][:5] == "width":
776 if lines[i][:9] == "collapsed":
777 if lines[i][9:] == "true":
785 lines.insert(i, 'use_parbox 0')
787 lines.insert(i, 'width' + width)
789 lines.insert(i, 'special "none"')
791 lines.insert(i, 'height' + height)
793 lines.insert(i, 'height_special "totalheight"')
795 lines.insert(i, 'status ' + status)
799 # -------------------------------------------------------------------------------------------
800 # Convert backslashes into valid ERT code, append the converted text to
801 # lines[i] and return the (maybe incremented) line index i
802 def convert_ertbackslash(lines, i, ert):
805 lines[i] = lines[i] + '\\backslash '
809 lines[i] = lines[i] + c
813 def convert_vspace(header, lines, opt):
815 # Get default spaceamount
816 i = find_token(header, '\\defskip', 0)
818 defskipamount = 'medskip'
820 defskipamount = split(header[i])[1]
825 i = find_token(lines, '\\begin_inset VSpace', i)
828 spaceamount = split(lines[i])[2]
830 # Are we at the beginning or end of a paragraph?
832 start = get_paragraph(lines, i) + 1
833 for k in range(start, i):
834 if is_nonempty_line(lines[k]):
838 j = find_end_of_inset(lines, i)
840 opt.warning("Malformed LyX file: Missing '\\end_inset'.")
843 end = get_next_paragraph(lines, i)
844 for k in range(j + 1, end):
845 if is_nonempty_line(lines[k]):
849 # Convert to paragraph formatting if we are at the beginning or end
850 # of a paragraph and the resulting paragraph would not be empty
851 if ((paragraph_start and not paragraph_end) or
852 (paragraph_end and not paragraph_start)):
853 # The order is important: del and insert invalidate some indices
857 lines.insert(start, '\\added_space_top ' + spaceamount + ' ')
859 lines.insert(start, '\\added_space_bottom ' + spaceamount + ' ')
863 lines[i:i+1] = ['\\begin_inset ERT', 'status Collapsed', '',
864 '\\layout Standard', '', '\\backslash ']
866 if spaceamount[-1] == '*':
867 spaceamount = spaceamount[:-1]
872 # Replace defskip by the actual value
873 if spaceamount == 'defskip':
874 spaceamount = defskipamount
876 # LaTeX does not know \\smallskip* etc
878 if spaceamount == 'smallskip':
879 spaceamount = '\\smallskipamount'
880 elif spaceamount == 'medskip':
881 spaceamount = '\\medskipamount'
882 elif spaceamount == 'bigskip':
883 spaceamount = '\\bigskipamount'
884 elif spaceamount == 'vfill':
885 spaceamount = '\\fill'
887 # Finally output the LaTeX code
888 if (spaceamount == 'smallskip' or spaceamount == 'medskip' or
889 spaceamount == 'bigskip' or spaceamount == 'vfill'):
890 lines.insert(i, spaceamount)
893 lines.insert(i, 'vspace*{')
895 lines.insert(i, 'vspace{')
896 i = convert_ertbackslash(lines, i, spaceamount)
897 lines[i] = lines[i] + '}'
901 # Convert a LyX length into valid ERT code and append it to lines[i]
902 # Return the (maybe incremented) line index i
903 def convert_ertlen(lines, i, len, special):
904 units = {"text%":"\\textwidth", "col%":"\\columnwidth",
905 "page%":"\\pagewidth", "line%":"\\linewidth",
906 "theight%":"\\textheight", "pheight%":"\\pageheight"}
908 # Convert special lengths
909 if special != 'none':
910 len = '%f\\' % len2value(len) + special
912 # Convert LyX units to LaTeX units
913 for unit in units.keys():
914 if find(len, unit) != -1:
915 len = '%f' % (len2value(len) / 100) + units[unit]
918 # Convert backslashes and insert the converted length into lines
919 return convert_ertbackslash(lines, i, len)
922 # Return the value of len without the unit in numerical form
924 result = re.search('([+-]?[0-9.]+)', len)
926 return float(result.group(1))
927 # No number means 1.0
931 def convert_frameless_box(lines, opt):
932 pos = ['t', 'c', 'b']
933 inner_pos = ['c', 't', 'b', 's']
936 i = find_token(lines, '\\begin_inset Frameless', i)
939 j = find_end_of_inset(lines, i)
941 opt.warning("Malformed LyX file: Missing '\\end_inset'\n")
947 params = {'position':'0', 'hor_pos':'c', 'has_inner_box':'1',
948 'inner_pos':'1', 'use_parbox':'0', 'width':'100col%',
949 'special':'none', 'height':'1in',
950 'height_special':'totalheight', 'collapsed':'false'}
951 for key in params.keys():
952 value = replace(get_value(lines, key, i, j), '"', '')
954 if key == 'position':
955 # convert new to old position: 'position "t"' -> 0
956 value = find_token(pos, value, 0)
959 elif key == 'inner_pos':
960 # convert inner position
961 value = find_token(inner_pos, value, 0)
966 j = del_token(lines, key, i, j)
969 # Convert to minipage or ERT?
970 # Note that the inner_position and height parameters of a minipage
971 # inset are ignored and not accessible for the user, although they
972 # are present in the file format and correctly read in and written.
973 # Therefore we convert to ERT if they do not have their LaTeX
974 # defaults. These are:
975 # - the value of "position" for "inner_pos"
976 # - "\totalheight" for "height"
977 if (params['use_parbox'] != '0' or
978 params['has_inner_box'] != '1' or
979 params['special'] != 'none' or
980 inner_pos[params['inner_pos']] != pos[params['position']] or
981 params['height_special'] != 'totalheight' or
982 len2value(params['height']) != 1.0):
985 if params['collapsed'] == 'true':
986 params['collapsed'] = 'Collapsed'
988 params['collapsed'] = 'Open'
989 lines[i : i] = ['\\begin_inset ERT', 'status ' + params['collapsed'],
990 '', '\\layout Standard', '', '\\backslash ']
992 if params['use_parbox'] == '1':
993 lines.insert(i, 'parbox')
995 lines.insert(i, 'begin{minipage}')
996 lines[i] = lines[i] + '[' + pos[params['position']] + ']['
997 i = convert_ertlen(lines, i, params['height'], params['height_special'])
998 lines[i] = lines[i] + '][' + inner_pos[params['inner_pos']] + ']{'
999 i = convert_ertlen(lines, i, params['width'], params['special'])
1000 if params['use_parbox'] == '1':
1001 lines[i] = lines[i] + '}{'
1003 lines[i] = lines[i] + '}'
1005 lines[i:i] = ['', '\\end_inset ']
1007 j = find_end_of_inset(lines, i)
1009 opt.warning("Malformed LyX file: Missing '\\end_inset'.")
1011 lines[j-1:j-1] = ['\\begin_inset ERT', 'status ' + params['collapsed'],
1012 '', '\\layout Standard', '']
1014 if params['use_parbox'] == '1':
1015 lines.insert(j, '}')
1017 lines[j:j] = ['\\backslash ', 'end{minipage}']
1020 # Convert to minipage
1021 lines[i:i] = ['\\begin_inset Minipage',
1022 'position %d' % params['position'],
1023 'inner_position %d' % params['inner_pos'],
1024 'height "' + params['height'] + '"',
1025 'width "' + params['width'] + '"',
1026 'collapsed ' + params['collapsed']]
1033 def convert_jurabib(header, opt):
1034 i = find_token(header, '\\use_numerical_citations', 0)
1036 opt.warning("Malformed lyx file: Missing '\\use_numerical_citations'")
1038 header.insert(i + 1, '\\use_jurabib 0')
1041 def revert_jurabib(header, opt):
1042 i = find_token(header, '\\use_jurabib', 0)
1044 opt.warning("Malformed lyx file: Missing '\\use_jurabib'")
1046 if get_value(header, '\\use_jurabib', 0) != "0":
1047 opt.warning("Conversion of '\\use_jurabib = 1' not yet implemented.")
1048 # Don't remove '\\use_jurabib' so that people will get warnings by lyx
1056 def convert_bibtopic(header, opt):
1057 i = find_token(header, '\\use_jurabib', 0)
1059 opt.warning("Malformed lyx file: Missing '\\use_jurabib'")
1061 header.insert(i + 1, '\\use_bibtopic 0')
1064 def revert_bibtopic(header, opt):
1065 i = find_token(header, '\\use_bibtopic', 0)
1067 opt.warning("Malformed lyx file: Missing '\\use_bibtopic'")
1069 if get_value(header, '\\use_bibtopic', 0) != "0":
1070 opt.warning("Conversion of '\\use_bibtopic = 1' not yet implemented.")
1071 # Don't remove '\\use_jurabib' so that people will get warnings by lyx
1078 def convert_float(lines, opt):
1081 i = find_token(lines, '\\begin_inset Float', i)
1084 # Seach for a line starting 'wide'
1085 # If, however, we find a line starting '\begin_layout'
1086 # (_always_ present) then break with a warning message
1089 if (lines[i][:4] == "wide"):
1090 lines.insert(i + 1, 'sideways false')
1092 elif (lines[i][:13] == "\\begin_layout"):
1093 opt.warning("Malformed lyx file")
1099 def revert_float(lines, opt):
1102 i = find_token(lines, '\\begin_inset Float', i)
1105 j = find_end_of_inset(lines, i)
1107 opt.warning("Malformed lyx file: Missing '\\end_inset'")
1110 if get_value(lines, 'sideways', i, j) != "false":
1111 opt.warning("Conversion of 'sideways true' not yet implemented.")
1112 # Don't remove 'sideways' so that people will get warnings by lyx
1115 del_token(lines, 'sideways', i, j)
1122 def convert(header, body, opt):
1123 if opt.format < 223:
1124 add_end_header(header)
1125 convert_spaces(body)
1126 convert_bibtex(body)
1127 remove_insetparent(body)
1129 if opt.end == opt.format: return
1131 if opt.format < 224:
1132 convert_external(body)
1133 convert_comment(body)
1135 if opt.end == opt.format: return
1137 if opt.format < 225:
1138 add_end_layout(body)
1139 layout2begin_layout(body)
1140 convert_end_document(body)
1141 convert_table_valignment_middle(body)
1142 convert_breaks(body)
1144 if opt.end == opt.format: return
1146 if opt.format < 226:
1149 if opt.end == opt.format: return
1151 if opt.format < 227:
1154 if opt.end == opt.format: return
1156 if opt.format < 228:
1157 convert_collapsable(body, opt)
1158 convert_ert(body, opt)
1160 if opt.end == opt.format: return
1162 if opt.format < 229:
1163 convert_minipage(body)
1165 if opt.end == opt.format: return
1167 if opt.format < 230:
1168 convert_jurabib(header, opt)
1170 if opt.end == opt.format: return
1172 if opt.format < 231:
1173 convert_float(body, opt)
1175 if opt.end == opt.format: return
1177 if opt.format < 232:
1178 convert_bibtopic(header, opt)
1181 def revert(header, body, opt):
1182 if opt.format > 231:
1183 revert_bibtopic(header, opt)
1185 if opt.end == opt.format: return
1187 if opt.format > 230:
1188 revert_float(body, opt)
1190 if opt.end == opt.format: return
1192 if opt.format > 229:
1193 revert_jurabib(header, opt)
1195 if opt.end == opt.format: return
1197 if opt.format > 228:
1199 if opt.end == opt.format: return
1201 if opt.format > 227:
1202 revert_collapsable(body, opt)
1203 revert_ert(body, opt)
1205 if opt.end == opt.format: return
1207 if opt.format > 226:
1209 revert_external_2(body)
1211 if opt.end == opt.format: return
1213 if opt.format > 225:
1216 if opt.end == opt.format: return
1218 if opt.format > 224:
1220 begin_layout2layout(body)
1221 revert_end_document(body)
1222 revert_valignment_middle(body)
1223 convert_vspace(header, body, opt)
1224 convert_frameless_box(body, opt)
1225 if opt.end == opt.format: return
1227 if opt.format > 223:
1228 revert_external_2(body)
1229 revert_comment(body)
1231 if opt.end == opt.format: return
1233 if opt.format > 221:
1234 rm_end_header(header)
1237 rm_tracking_changes(header)
1238 rm_body_changes(body)
1242 if __name__ == "__main__":