- i = find_token(lines, "\\begin_float", i)
- if i == -1:
- break
- # There are no nested floats, so finding the end of the float is simple
- j = find_token(lines, "\\end_float", i+1)
-
- floattype = string.split(lines[i])[1]
- if not floats.has_key(floattype):
- file.warning("Error! Unknown float type " + floattype)
- floattype = "fig"
-
- # skip \end_deeper tokens
- i2 = i+1
- while check_token(lines[i2], "\\end_deeper"):
- i2 = i2+1
- if i2 > i+1:
- j2 = get_next_paragraph(lines, j + 1, file.format + 1)
- lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1))
-
- new = floats[floattype]+[""]
-
- # Check if the float is floatingfigure
- k = find_re(lines, pextra_type3_rexp, i, j)
- if k != -1:
- mo = pextra_rexp.search(lines[k])
- width = get_width(mo)
- lines[k] = re.sub(pextra_rexp, "", lines[k])
- new = ["\\begin_inset Wrap figure",
- 'width "%s"' % width,
- "collapsed false",
- ""]
-
- new = new+lines[i2:j]+["\\end_inset ", ""]
-
- # After a float, all font attributes are reseted.
- # We need to output '\foo default' for every attribute foo
- # whose value is not default before the float.
- # The check here is not accurate, but it doesn't matter
- # as extra '\foo default' commands are ignored.
- # In fact, it might be safer to output '\foo default' for all
- # font attributes.
- k = get_paragraph(lines, i, file.format + 1)
- flag = 0
- for token in font_tokens:
- if find_token(lines, token, k, i) != -1:
- if not flag:
- # This is not necessary, but we want the output to be
- # as similar as posible to the lyx format
- flag = 1
- new.append("")
- if token == "\\lang":
- new.append(token+" "+ file.language)
- else:
- new.append(token+" default ")
-
- lines[i:j+1] = new
- i = i+1
+ i = find_token(lines, "\\begin_float", i)
+ if i == -1:
+ break
+ # There are no nested floats, so finding the end of the float is simple
+ j = find_token(lines, "\\end_float", i+1)
+
+ floattype = string.split(lines[i])[1]
+ if not floats.has_key(floattype):
+ file.warning("Error! Unknown float type " + floattype)
+ floattype = "fig"
+
+ # skip \end_deeper tokens
+ i2 = i+1
+ while check_token(lines[i2], "\\end_deeper"):
+ i2 = i2+1
+ if i2 > i+1:
+ j2 = get_next_paragraph(lines, j + 1, file.format + 1)
+ lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1))
+
+ new = floats[floattype]+[""]
+
+ # Check if the float is floatingfigure
+ k = find_re(lines, pextra_type3_rexp, i, j)
+ if k != -1:
+ mo = pextra_rexp.search(lines[k])
+ width = get_width(mo)
+ lines[k] = re.sub(pextra_rexp, "", lines[k])
+ new = ["\\begin_inset Wrap figure",
+ 'width "%s"' % width,
+ "collapsed false",
+ ""]
+
+ new = new+lines[i2:j]+["\\end_inset ", ""]
+
+ # After a float, all font attributes are reseted.
+ # We need to output '\foo default' for every attribute foo
+ # whose value is not default before the float.
+ # The check here is not accurate, but it doesn't matter
+ # as extra '\foo default' commands are ignored.
+ # In fact, it might be safer to output '\foo default' for all
+ # font attributes.
+ k = get_paragraph(lines, i, file.format + 1)
+ flag = 0
+ for token in font_tokens:
+ if find_token(lines, token, k, i) != -1:
+ if not flag:
+ # This is not necessary, but we want the output to be
+ # as similar as posible to the lyx format
+ flag = 1
+ new.append("")
+ if token == "\\lang":
+ new.append(token+" "+ file.language)
+ else:
+ new.append(token+" default ")
+
+ lines[i:j+1] = new
+ i = i+1
- position = mo.group(3)
- hfill = mo.group(5)
- lines[i] = re.sub(pextra_rexp, "", lines[i])
-
- start = ["\\begin_inset Minipage",
- "position " + position,
- "inner_position 0",
- 'height "0pt"',
- 'width "%s"' % width,
- "collapsed false"
- ]
- if flag:
- flag = 0
- if hfill:
- start = ["","\hfill",""]+start
- else:
- start = ['\\layout %s' % file.default_layout,''] + start
-
- j0 = find_token_backwards(lines,"\\layout", i-1)
- j = get_next_paragraph(lines, i, file.format + 1)
-
- count = 0
- while 1:
- # collect more paragraphs to the minipage
- count = count+1
- if j == -1 or not check_token(lines[j], "\\layout"):
- break
- i = find_re(lines, pextra_type2_rexp2, j+1)
- if i == -1:
- break
- mo = pextra_rexp.search(lines[i])
- if not mo:
- break
- if mo.group(7) == "1":
- flag = 1
- break
- lines[i] = re.sub(pextra_rexp, "", lines[i])
- j = find_tokens(lines, ["\\layout", "\\end_float"], i+1)
-
- mid = lines[j0:j]
- end = ["\\end_inset "]
-
- lines[j0:j] = start+mid+end
- i = i+1
+ position = mo.group(3)
+ hfill = mo.group(5)
+ lines[i] = re.sub(pextra_rexp, "", lines[i])
+
+ start = ["\\begin_inset Minipage",
+ "position " + position,
+ "inner_position 0",
+ 'height "0pt"',
+ 'width "%s"' % width,
+ "collapsed false"
+ ]
+ if flag:
+ flag = 0
+ if hfill:
+ start = ["","\hfill",""]+start
+ else:
+ start = ['\\layout %s' % file.default_layout,''] + start
+
+ j0 = find_token_backwards(lines,"\\layout", i-1)
+ j = get_next_paragraph(lines, i, file.format + 1)
+
+ count = 0
+ while 1:
+ # collect more paragraphs to the minipage
+ count = count+1
+ if j == -1 or not check_token(lines[j], "\\layout"):
+ break
+ i = find_re(lines, pextra_type2_rexp2, j+1)
+ if i == -1:
+ break
+ mo = pextra_rexp.search(lines[i])
+ if not mo:
+ break
+ if mo.group(7) == "1":
+ flag = 1
+ break
+ lines[i] = re.sub(pextra_rexp, "", lines[i])
+ j = find_tokens(lines, ["\\layout", "\\end_float"], i+1)
+
+ mid = lines[j0:j]
+ end = ["\\end_inset "]
+
+ lines[j0:j] = start+mid+end
+ i = i+1
- j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", "\\the_end"],
- j)
- if check_token(lines[j], "\\begin_inset"):
- j = find_end_of_inset(lines, j)+1
- else:
- break
-
- if check_token(lines[j], "\\layout"):
- while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"):
- j = j-1
-
- # We need to remove insets, special chars & font commands from ERT text
- new = []
- new2 = []
- if check_token(lines[i], "\\layout LaTeX"):
- new = ['\layout %s' % file.default_layout, "", ""]
-
- k = i+1
- while 1:
- k2 = find_re(lines, ert_rexp, k, j)
- inset = hfill = specialchar = 0
- if k2 == -1:
- k2 = j
- elif check_token(lines[k2], "\\begin_inset"):
- inset = 1
+ j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", "\\the_end"],
+ j)
+ if check_token(lines[j], "\\begin_inset"):
+ j = find_end_of_inset(lines, j)+1
+ else:
+ break
+
+ if check_token(lines[j], "\\layout"):
+ while j-1 >= 0 and check_token(lines[j-1], "\\begin_deeper"):
+ j = j-1
+
+ # We need to remove insets, special chars & font commands from ERT text
+ new = []
+ new2 = []
+ if check_token(lines[i], "\\layout LaTeX"):
+ new = ['\layout %s' % file.default_layout, "", ""]
+
+ k = i+1
+ while 1:
+ k2 = find_re(lines, ert_rexp, k, j)
+ inset = hfill = specialchar = 0
+ if k2 == -1:
+ k2 = j
+ elif check_token(lines[k2], "\\begin_inset"):
+ inset = 1
- if move_rexp.match(line):
- if new2 == []:
- # This is not necessary, but we want the output to be
- # as similar as posible to the lyx format
- new2 = [""]
- new2.append(line)
- elif not check_token(line, "\\latex"):
- tmp.append(line)
-
- if is_empty(tmp):
- if filter(lambda x:x != "", tmp) != []:
- if new == []:
- # This is not necessary, but we want the output to be
- # as similar as posible to the lyx format
- lines[i-1] = lines[i-1]+" "
- else:
- new = new+[" "]
- else:
- new = new+ert_begin+tmp+["\\end_inset ", ""]
-
- if inset:
- k3 = find_end_of_inset(lines, k2)
- new = new+[""]+lines[k2:k3+1]+[""] # Put an empty line after \end_inset
- k = k3+1
- # Skip the empty line after \end_inset
- if not is_nonempty_line(lines[k]):
- k = k+1
- new.append("")
+ if move_rexp.match(line):
+ if new2 == []:
+ # This is not necessary, but we want the output to be
+ # as similar as posible to the lyx format
+ new2 = [""]
+ new2.append(line)
+ elif not check_token(line, "\\latex"):
+ tmp.append(line)
+
+ if is_empty(tmp):
+ if filter(lambda x:x != "", tmp) != []:
+ if new == []:
+ # This is not necessary, but we want the output to be
+ # as similar as posible to the lyx format
+ lines[i-1] = lines[i-1]+" "
+ else:
+ new = new+[" "]
+ else:
+ new = new+ert_begin+tmp+["\\end_inset ", ""]
+
+ if inset:
+ k3 = find_end_of_inset(lines, k2)
+ new = new+[""]+lines[k2:k3+1]+[""] # Put an empty line after \end_inset
+ k = k3+1
+ # Skip the empty line after \end_inset
+ if not is_nonempty_line(lines[k]):
+ k = k+1
+ new.append("")
- elif specialchar:
- if new == []:
- # This is not necessary, but we want the output to be
- # as similar as posible to the lyx format
- lines[i-1] = lines[i-1]+specialchar_str
- new = [""]
- else:
- new = new+[specialchar_str, ""]
- k = k2
- else:
- break
-
- new = new+new2
- if not check_token(lines[j], "\\latex "):
- new = new+[""]+[lines[j]]
- lines[i:j+1] = new
- i = i+1
+ elif specialchar:
+ if new == []:
+ # This is not necessary, but we want the output to be
+ # as similar as posible to the lyx format
+ lines[i-1] = lines[i-1]+specialchar_str
+ new = [""]
+ else:
+ new = new+[specialchar_str, ""]
+ k = k2
+ else:
+ break
+
+ new = new+new2
+ if not check_token(lines[j], "\\latex "):
+ new = new+[""]+[lines[j]]
+ lines[i:j+1] = new
+ i = i+1
- i = find_token(lines, "\\begin_inset ERT", i)
- if i == -1:
- break
- j = find_end_of_inset(lines, i)
- k = find_token(lines, "\\layout", i+1)
- l = get_paragraph(lines, i, file.format + 1)
- if lines[k] == lines[l]: # same layout
- k = k+1
- new = lines[k:j]
- lines[i:j+1] = new
- i = i+1
+ i = find_token(lines, "\\begin_inset ERT", i)
+ if i == -1:
+ break
+ j = find_end_of_inset(lines, i)
+ k = find_token(lines, "\\layout", i+1)
+ l = get_paragraph(lines, i, file.format + 1)
+ if lines[k] == lines[l]: # same layout
+ k = k+1
+ new = lines[k:j]
+ lines[i:j+1] = new
+ i = i+1
- i = find_token(lines, "\\begin_inset ERT", i)
- if i == -1:
- break
- j = get_paragraph(lines, i, file.format + 1)
- count = 0
- text = []
- while is_ert_paragraph(file, j):
-
- count = count+1
- i2 = find_token(lines, "\\layout", j+1)
- k = find_token(lines, "\\end_inset", i2+1)
- text = text+lines[i2:k]
- j = find_token(lines, "\\layout", k+1)
- if j == -1:
- break
-
- if count >= 2:
- j = find_token(lines, "\\layout", i+1)
- lines[j:k] = text
+ i = find_token(lines, "\\begin_inset ERT", i)
+ if i == -1:
+ break
+ j = get_paragraph(lines, i, file.format + 1)
+ count = 0
+ text = []
+ while is_ert_paragraph(file, j):
+
+ count = count+1
+ i2 = find_token(lines, "\\layout", j+1)
+ k = find_token(lines, "\\end_inset", i2+1)
+ text = text+lines[i2:k]
+ j = find_token(lines, "\\layout", k+1)
+ if j == -1:
+ break
+
+ if count >= 2:
+ j = find_token(lines, "\\layout", i+1)
+ lines[j:k] = text
- i = find_token(lines, "\\begin_inset Figure", i)
- if i == -1:
- break
- j = find_end_of_inset(lines, i)
-
- if ( len(string.split(lines[i])) > 2 ):
- lyxwidth = string.split(lines[i])[3]+"pt"
- lyxheight = string.split(lines[i])[4]+"pt"
- else:
- lyxwidth = ""
- lyxheight = ""
-
- filename = get_value(lines, "file", i+1, j)
-
- width = get_length(lines, "width", i+1, j)
- # what does width=5 mean ?
- height = get_length(lines, "height", i+1, j)
- rotateAngle = get_value(lines, "angle", i+1, j)
- if width == "" and height == "":
- size_type = "0"
- else:
- size_type = "1"
-
- flags = get_value(lines, "flags", i+1, j)
- x = int(flags)%4
- if x == 1:
- display = "monochrome"
- elif x == 2:
- display = "gray"
- else:
- display = "color"
-
- subcaptionText = ""
- subcaptionLine = find_token(lines, "subcaption", i+1, j)
- if subcaptionLine != -1:
+ i = find_token(lines, "\\begin_inset Figure", i)
+ if i == -1:
+ break
+ j = find_end_of_inset(lines, i)
+
+ if ( len(string.split(lines[i])) > 2 ):
+ lyxwidth = string.split(lines[i])[3]+"pt"
+ lyxheight = string.split(lines[i])[4]+"pt"
+ else:
+ lyxwidth = ""
+ lyxheight = ""
+
+ filename = get_value(lines, "file", i+1, j)
+
+ width = get_length(lines, "width", i+1, j)
+ # what does width=5 mean ?
+ height = get_length(lines, "height", i+1, j)
+ rotateAngle = get_value(lines, "angle", i+1, j)
+ if width == "" and height == "":
+ size_type = "0"
+ else:
+ size_type = "1"
+
+ flags = get_value(lines, "flags", i+1, j)
+ x = int(flags)%4
+ if x == 1:
+ display = "monochrome"
+ elif x == 2:
+ display = "gray"
+ else:
+ display = "color"
+
+ subcaptionText = ""
+ subcaptionLine = find_token(lines, "subcaption", i+1, j)
+ if subcaptionLine != -1:
- if subcaptionText != "":
- subcaptionText = '"'+subcaptionText+'"'
-
- k = find_token(lines, "subfigure", i+1,j)
- if k == -1:
- subcaption = 0
- else:
- subcaption = 1
-
- new = ["\\begin_inset Graphics FormatVersion 1"]
- write_attribute(new, "filename", filename)
- write_attribute(new, "display", display)
- if subcaption:
- new.append("\tsubcaption")
- write_attribute(new, "subcaptionText", subcaptionText)
- write_attribute(new, "size_type", size_type)
- write_attribute(new, "width", width)
- write_attribute(new, "height", height)
- if rotateAngle != "":
- new.append("\trotate")
- write_attribute(new, "rotateAngle", rotateAngle)
- write_attribute(new, "rotateOrigin", "leftBaseline")
- write_attribute(new, "lyxsize_type", "1")
- write_attribute(new, "lyxwidth", lyxwidth)
- write_attribute(new, "lyxheight", lyxheight)
- new = new + ["\\end_inset"]
- lines[i:j+1] = new
+ if subcaptionText != "":
+ subcaptionText = '"'+subcaptionText+'"'
+
+ k = find_token(lines, "subfigure", i+1,j)
+ if k == -1:
+ subcaption = 0
+ else:
+ subcaption = 1
+
+ new = ["\\begin_inset Graphics FormatVersion 1"]
+ write_attribute(new, "filename", filename)
+ write_attribute(new, "display", display)
+ if subcaption:
+ new.append("\tsubcaption")
+ write_attribute(new, "subcaptionText", subcaptionText)
+ write_attribute(new, "size_type", size_type)
+ write_attribute(new, "width", width)
+ write_attribute(new, "height", height)
+ if rotateAngle != "":
+ new.append("\trotate")
+ write_attribute(new, "rotateAngle", rotateAngle)
+ write_attribute(new, "rotateOrigin", "leftBaseline")
+ write_attribute(new, "lyxsize_type", "1")
+ write_attribute(new, "lyxwidth", lyxwidth)
+ write_attribute(new, "lyxheight", lyxheight)
+ new = new + ["\\end_inset"]
+ lines[i:j+1] = new
- for k in get_tabular_lines(lines, i):
- if check_token(lines[k], "<lyxtabular"):
- lines[k] = string.replace(lines[k], 'version="2"', 'version="3"')
- elif check_token(lines[k], "<column"):
- lines[k] = string.replace(lines[k], 'width=""', 'width="0pt"')
+ for k in get_tabular_lines(lines, i):
+ if check_token(lines[k], "<lyxtabular"):
+ lines[k] = string.replace(lines[k], 'version="2"', 'version="3"')
+ elif check_token(lines[k], "<column"):
+ lines[k] = string.replace(lines[k], 'width=""', 'width="0pt"')