+####################################################################
+# Private helper functions
+
+def get_layout(line, default_layout):
+ " Get layout, if empty return the default layout."
+ tokens = line.split()
+ if len(tokens) > 1:
+ return tokens[1]
+ return default_layout
+
+
+def get_paragraph(lines, i, format):
+ "Finds the paragraph that contains line i."
+
+ if format < 225:
+ begin_layout = "\\layout"
+ else:
+ begin_layout = "\\begin_layout"
+ while i != -1:
+ i = find_tokens_backwards(lines, ["\\end_inset", begin_layout], i)
+ if i == -1: return -1
+ if check_token(lines[i], begin_layout):
+ return i
+ i = find_beginning_of_inset(lines, i)
+ return -1
+
+
+def find_beginning_of_inset(lines, i):
+ " Find beginning of inset, where lines[i] is included."
+ return find_beginning_of(lines, i, "\\begin_inset", "\\end_inset")
+
+
+def get_next_paragraph(lines, i, format):
+ "Finds the paragraph after the paragraph that contains line i."
+
+ if format < 225:
+ tokens = ["\\begin_inset", "\\layout", "\\end_float", "\\the_end"]
+ elif format < 236:
+ tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_document"]
+ else:
+ tokens = ["\\begin_inset", "\\begin_layout", "\\end_float", "\\end_body", "\\end_document"]
+ while i != -1:
+ i = find_tokens(lines, tokens, i)
+ if not check_token(lines[i], "\\begin_inset"):
+ return i
+ i = find_end_of_inset(lines, i)
+ return -1
+
+
+def find_end_of_inset(lines, i):
+ "Finds the matching \end_inset"
+ return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
+
+def del_token(lines, token, start, end):
+ """ del_token(lines, token, start, end) -> int
+
+ Find the lower line in lines where token is the first element and
+ delete that line.
+
+ Returns the number of lines remaining."""
+
+ k = find_token_exact(lines, token, start, end)
+ if k == -1:
+ return end
+ else:
+ del lines[k]
+ return end - 1
+
+# End of helper functions
+####################################################################
+
+def remove_color_default(document):
+ " Remove \color default"