+add_to_preamble(document, text):
+ Here, text can be either a single line or a list of lines. It
+ is bad practice to pass something with embedded newlines, but
+ we will handle that properly.
+ The routine checks to see whether the provided material is
+ already in the preamble. If not, it adds it.
+ Prepends a comment "% Added by lyx2lyx" to text.
+
+insert_to_preamble(document, text[, index]):
+ Here, text can be either a single line or a list of lines. It
+ is bad practice to pass something with embedded newlines, but
+ we will handle that properly.
+ The routine inserts text at document.preamble[index], where by
+ default index is 0, so the material is inserted at the beginning.
+ Prepends a comment "% Added by lyx2lyx" to text.
+
+put_cmd_in_ert(cmd):
+ Here cmd should be a list of strings (lines), which we want to
+ wrap in ERT. Returns a list of strings so wrapped.
+ A call to this routine will often go something like this:
+ i = find_token('\\begin_inset FunkyInset', ...)
+ j = find_end_of_inset(document.body, i)
+ content = lyx2latex(document[i:j + 1])
+ ert = put_cmd_in_ert(content)
+ document.body[i:j+1] = ert
+
+get_ert(lines, i[, verbatim]):
+ Here, lines is a list of lines of LyX material containing an ERT inset,
+ whose content we want to convert to LaTeX. The ERT starts at index i.
+ If the optional (by default: False) bool verbatim is True, the content
+ of the ERT is returned verbatim, that is in LyX syntax (not LaTeX syntax)
+ for the use in verbatim insets.
+
+lyx2latex(document, lines):
+ Here, lines is a list of lines of LyX material we want to convert
+ to LaTeX. We do the best we can and return a string containing
+ the translated material.
+
+lyx2verbatim(document, lines):
+ Here, lines is a list of lines of LyX material we want to convert
+ to verbatim material (used in ERT an the like). We do the best we
+ can and return a string containing the translated material.
+
+latex_length(slen):
+ Convert lengths (in LyX form) to their LaTeX representation. Returns
+ (bool, length), where the bool tells us if it was a percentage, and
+ the length is the LaTeX representation.
+
+convert_info_insets(document, type, func):
+ Applies func to the argument of all info insets matching certain types
+ type : the type to match. This can be a regular expression.
+ func : function from string to string to apply to the "arg" field of
+ the info insets.
+
+is_document_option(document, option):
+ Find if _option_ is a document option (\\options in the header).
+
+insert_document_option(document, option):
+ Insert _option_ as a document option.
+
+remove_document_option(document, option):
+ Remove _option_ as a document option.
+'''
+
+import re
+from parser_tools import find_token, find_end_of_inset