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
(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.
'''
import re
elif lines[i] == "\\end_layout":
while i + 1 < j and lines[i+1] == "":
i = i + 1
- elif lines[i] == "\\backslash" and not verbatim:
- ret = ret + "\\"
+ elif lines[i] == "\\backslash":
+ if verbatim:
+ ret = ret + "\n" + lines[i] + "\n"
+ else:
+ ret = ret + "\\"
else:
ret = ret + lines[i]
i = i + 1
"'true' goes to True, case-insensitively, and we strip whitespace."
s = s.strip().lower()
return s == "true"
+
+
+def convert_info_insets(document, type, func):
+ "Convert info insets matching type using func."
+ i = 0
+ type_re = re.compile(r'^type\s+"(%s)"$' % type)
+ arg_re = re.compile(r'^arg\s+"(.*)"$')
+ while True:
+ i = find_token(document.body, "\\begin_inset Info", i)
+ if i == -1:
+ return
+ t = type_re.match(document.body[i + 1])
+ if t:
+ arg = arg_re.match(document.body[i + 2])
+ if arg:
+ new_arg = func(arg.group(1))
+ document.body[i + 2] = 'arg "%s"' % new_arg
+ i += 3