return wasOpt
-def convert_TeX_brace_to_Argument(document, line, n, nmax, inset, environment):
+def convert_TeX_brace_to_Argument(document, line, n, nmax, inset, environment, opt):
'''
Converts TeX code for mandatory arguments to an InsetArgument
The conversion of TeX code for optional arguments must be done with another routine
- "}" + " " + "{" separates mandatory arguments of commands
- { and } surround a mandatory argument of an environment
usage:
- convert_TeX_brace_to_Argument(document, LineOfBeginLayout/Inset, StartArgument, EndArgument, isInset, isEnvironment)
+ convert_TeX_brace_to_Argument(document, LineOfBeginLayout/Inset, StartArgument, EndArgument, isInset, isEnvironment, isOpt)
LineOfBeginLayout/Inset is the line of the \begin_layout or \begin_inset statement
StartArgument is the number of the first ERT that needs to be converted
EndArgument is the number of the last ERT that needs to be converted
isInset must be true, if braces inside an InsetLayout needs to be converted
isEnvironment must be true, if the layout is for a LaTeX environment
+ isOpt must be true, if the argument is an optional one
Todo: this routine can currently handle only one mandatory argument of environments
'''
while lineERT != -1 and n < nmax + 1:
lineERT = find_token(document.body, "\\begin_inset ERT", lineERT)
if environment == False and lineERT != -1:
- bracePair = find_token(document.body, "}{", lineERT)
+ bracePair = -1
+ if opt:
+ bracePair = find_token(document.body, "][", lineERT)
+ else:
+ bracePair = find_token(document.body, "}{", lineERT)
# assure that the "}{" is in this ERT
if bracePair == lineERT + 5:
end = find_token(document.body, "\\end_inset", bracePair)
loop = loop + 1
# now check the case that we have "}" + "{" in two ERTs
else:
- endBrace = find_token(document.body, "}", lineERT)
+ endBrace = -1
+ if opt:
+ endBrace = find_token(document.body, "]", lineERT)
+ else:
+ endBrace = find_token(document.body, "}", lineERT)
if endBrace == lineERT + 5:
- beginBrace = find_token(document.body, "{", endBrace)
+ beginBrace = -1
+ if opt:
+ beginBrace = find_token(document.body, "[", endBrace)
+ else:
+ beginBrace = find_token(document.body, "{", endBrace)
# assure that the ERTs are consecutive (11 or 12 depending if there is a space between the ERTs or not)
if beginBrace == endBrace + 11 or beginBrace == endBrace + 12:
end = find_token(document.body, "\\end_inset", beginBrace)
else:
lineERT += 1
if environment == True and lineERT != -1:
- opening = find_token(document.body, "{", lineERT)
+ opening = -1
+ if opt:
+ opening = find_token(document.body, "[", lineERT)
+ else:
+ opening = find_token(document.body, "{", lineERT)
if opening == lineERT + 5: # assure that the "{" is in this ERT
end = find_token(document.body, "\\end_inset", opening)
document.body[lineERT : end + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
n += 1
lineERT2 = find_token(document.body, "\\begin_inset ERT", lineERT)
- closing = find_token(document.body, "}", lineERT2)
+ closing = -1
+ if opt:
+ closing = find_token(document.body, "]", lineERT)
+ else:
+ closing = find_token(document.body, "}", lineERT2)
if closing == lineERT2 + 5: # assure that the "}" is in this ERT
end2 = find_token(document.body, "\\end_inset", closing)
document.body[lineERT2 : end2 + 1] = ["\\end_layout", "", "\\end_inset"]
if i != -1:
i = find_token(document.body, "\\begin_layout Page headings", i)
if i != -1:
- convert_TeX_brace_to_Argument(document, i, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 1, False, False, False)
i += 1
if j != -1:
j = find_token(document.body, "\\begin_layout Biography without photo", j)
if j != -1:
- convert_TeX_brace_to_Argument(document, j, 1, 1, False, True)
+ convert_TeX_brace_to_Argument(document, j, 1, 1, False, True, False)
j += 1
if k != -1:
# assure that we don't handle Biography Biography without photo
continue
if k != -1:
# the argument we want to convert is the second one
- convert_TeX_brace_to_Argument(document, k, 2, 2, False, True)
+ convert_TeX_brace_to_Argument(document, k, 2, 2, False, True, False)
k += 1
if i == -1 and j == -1 and k == -1:
return
i = find_token(document.body, "\\begin_layout Altaffilation", i)
if i == -1:
return
- convert_TeX_brace_to_Argument(document, i, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 1, False, False, False)
i += 1
i = find_token(document.body, "\\begin_layout Author affiliation", i)
if i == -1:
return
- convert_TeX_brace_to_Argument(document, i, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 1, False, False, False)
i += 1
i = find_token(document.body, "\\begin_layout MarkBoth", i)
if i == -1:
return
- convert_TeX_brace_to_Argument(document, i, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 1, False, False, False)
i += 1
if i != -1:
i = find_token(document.body, "\\begin_layout Conference", i)
if i != -1:
- convert_TeX_brace_to_Argument(document, i, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 1, False, False, False)
i += 1
if j != -1:
j = find_token(document.body, "\\begin_layout Author", j)
if j != -1:
- convert_TeX_brace_to_Argument(document, j, 1, 2, False, False)
+ convert_TeX_brace_to_Argument(document, j, 1, 2, False, False, False)
j += 1
if i == -1 and j == -1:
return
i = find_token(document.body, "\\begin_inset Flex CRcat", i)
if i == -1:
return
- convert_TeX_brace_to_Argument(document, i, 1, 3, True, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 3, True, False, False)
i += 1
if i != -1:
i = find_token(document.body, "\\begin_layout Item", i)
if i != -1:
- convert_TeX_brace_to_Argument(document, i, 2, 2, False, False)
+ convert_TeX_brace_to_Argument(document, i, 2, 2, False, False, False)
i += 1
if j != -1:
j = find_token(document.body, "\\begin_layout BulletedItem", j)
if j != -1:
- convert_TeX_brace_to_Argument(document, j, 2, 2, False, False)
+ convert_TeX_brace_to_Argument(document, j, 2, 2, False, False, False)
j += 1
if k != -1:
k = find_token(document.body, "\\begin_layout Language", k)
if k != -1:
- convert_TeX_brace_to_Argument(document, k, 2, 6, False, False)
+ convert_TeX_brace_to_Argument(document, k, 2, 6, False, False, False)
k += 1
if m != -1:
m = find_token(document.body, "\\begin_layout LastLanguage", m)
if m != -1:
- convert_TeX_brace_to_Argument(document, m, 2, 6, False, False)
+ convert_TeX_brace_to_Argument(document, m, 2, 6, False, False, False)
m += 1
if i == -1 and j == -1 and k == -1 and m == -1:
return
if i != -1:
i = find_token(document.body, "\\begin_layout DoubleItem", i)
if i != -1:
- convert_TeX_brace_to_Argument(document, i, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, i, 1, 1, False, False, False)
document.body[o] = document.body[o].replace("\\begin_layout DoubleItem", "\\begin_layout DoubleListItem")
i += 1
if j != -1:
j = find_token(document.body, "\\begin_layout Entry", j)
if j != -1:
- convert_TeX_brace_to_Argument(document, j, 1, 5, False, False)
+ convert_TeX_brace_to_Argument(document, j, 1, 5, False, False, False)
j += 1
if k != -1:
k = find_token(document.body, "\\begin_layout Item", k)
if k != -1:
- convert_TeX_brace_to_Argument(document, k, 1, 1, False, False)
+ convert_TeX_brace_to_Argument(document, k, 1, 1, False, False, False)
k += 1
if m != -1:
m = find_token(document.body, "\\begin_layout Language", m)
if m != -1:
- convert_TeX_brace_to_Argument(document, m, 1, 2, False, False)
+ convert_TeX_brace_to_Argument(document, m, 1, 2, False, False, False)
m += 1
if i == -1 and j == -1 and k == -1 and m == -1:
return
i = find_token(document.body, "\\begin_layout Initial", i)
if i == -1:
return
- convert_TeX_brace_to_Argument(document, i, 3, 3, False, False)
+ convert_TeX_brace_to_Argument(document, i, 3, 3, False, False, False)
i += 1
i = j
continue
elif document.body[ertcont].startswith("["):
- # This is an ERT option
- # strip off the [
- document.body[ertcont] = document.body[ertcont][1:]
if document.body[ertcont].endswith("]"):
+ # This is an ERT option
+ # strip off the [
+ document.body[ertcont] = document.body[ertcont][1:]
# strip off the ]
document.body[ertcont] = document.body[ertcont][:-1]
- # Convert to ArgInset
- document.body[parbeg] = "\\begin_inset Argument 2"
- i = j
+ # Convert to ArgInset
+ document.body[parbeg] = "\\begin_inset Argument 2"
+ else:
+ convert_TeX_brace_to_Argument(document, i, 2, 2, False, True, True)
+ i += 1
continue
i = j
# Multipar ERT. Skip this.
break
else:
- convert_TeX_brace_to_Argument(document, i, 2, 2, False, True)
+ convert_TeX_brace_to_Argument(document, i, 2, 2, False, True, False)
else:
break
j = find_end_of_layout(document.body, i)