1 # This file is part of lyx2lyx
2 # Copyright (C) 2002 Dekel Tsur <dekel@lyx.org>
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 from parser_tools import *
23 "footnote": ["\\begin_inset Foot\n",
25 "margin": ["\\begin_inset Marginal\n",
27 "fig": ["\\begin_inset Float figure\n",
31 "tab": ["\\begin_inset Float table\n",
35 "alg": ["\\begin_inset Float algorithm\n",
39 "wide-fig": ["\\begin_inset Float figure\n",
43 "wide-tab": ["\\begin_inset Float table\n",
49 def remove_oldfloat(lines):
52 i = find_token(lines, "\\begin_float", i)
55 j = find_token(lines, "\\end_float", i+1)
56 floattype = string.split(lines[i])[1]
58 start = floats[floattype]+["\n"]
60 lines[i:j+1]= start+mid+["\\end_inset \n"]
63 def remove_oldminipage(lines):
67 i = find_token(lines, "\\pextra_type 2", i)
71 line = string.split(lines[i])
72 if line[4] == "\\pextra_hfill":
75 if line[4] == "\\pextra_start_minipage":
78 if line[4] == "\\pextra_widthp":
79 width = line[5]+"col%"
81 start = ["\\begin_inset Minipage\n",
82 "position %s\n" % line[3],
85 'width "%s"\n' % width,
91 start = ["\n","\hfill\n","\n"]+start
93 start = ["\\layout Standard\n"] + start
95 j = find_token_backwards(lines,"\\layout", i-1)
99 j = find_token2(lines,"\\layout", "\\end_float", i+1)
100 mid = mid+lines[i+1:j]
103 i = find_token2(lines,"\\layout", "\\pextra_type", j+1)
104 if i == -1 or not check_token(lines, "\\pextra_type", i):
106 line = string.split(lines[i])
107 if line[4] == "\\pextra_hfill":
109 if line[4] == "\\pextra_start_minipage" and line[5] == "1":
112 j = find_token_backwards(lines,"\\layout", i-1)
114 j = find_token2(lines,"\\layout", "\\end_float", i+1)
115 mid = mid+lines[i+1:j]
117 end = ["\\end_inset \n"]
119 lines[j0:j] = start+mid+end
122 def convert(header,body):
123 remove_oldminipage(body)
124 remove_oldfloat(body)
126 if __name__ == "__main__":