+
+def remove_branches(file):
+ i = 0
+ while 1:
+ i = find_token(file.header, "\\branch", i)
+ if i == -1:
+ break
+ file.warning("Removing branch %s." % split(file.header[i])[1])
+ j = find_token(file.header, "\\end_branch", i)
+ if j == -1:
+ file.warning("Malformed LyX file: Missing '\\end_branch'.")
+ break
+ del file.header[i:j+1]
+
+ i = 0
+ while 1:
+ i = find_token(file.body, "\\begin_inset Branch", i)
+ if i == -1:
+ return
+ j = find_end_of_inset(file.body, i)
+ if j == -1:
+ file.warning("Malformed LyX file: Missing '\\end_inset'.")
+ i = i + 1
+ continue
+ del file.body[i]
+ del file.body[j - 1]
+ # Seach for a line starting 'collapsed'
+ # If, however, we find a line starting '\layout'
+ # (_always_ present) then break with a warning message
+ collapsed_found = 0
+ while 1:
+ if (file.body[i][:9] == "collapsed"):
+ del file.body[i]
+ collapsed_found = 1
+ continue
+ elif (file.body[i][:7] == "\\layout"):
+ if collapsed_found == 0:
+ file.warning("Malformed LyX file: Missing 'collapsed'.")
+ # Delete this new paragraph, since it would not appear in
+ # .tex output. This avoids also empty paragraphs.
+ del file.body[i]
+ break
+ i = i + 1
+
+