Todo: this routine can currently handle only one mandatory argument of environments
'''
+
+ end_layout = find_end_of_layout(document.body, line)
lineERT = line
endn = line
loop = 1
- while lineERT != -1 and n < nmax + 1:
- lineERT = find_token(document.body, "\\begin_inset ERT", lineERT)
- if environment == False and lineERT != -1:
- bracePair = -1
+ while n < nmax + 1:
+ lineERT = find_token(document.body, "\\begin_inset ERT", lineERT, end_layout)
+ if lineERT == -1:
+ break
+ if environment == False:
+ end_ERT = find_end_of_inset(document.body, lineERT)
+ if end_ERT == -1:
+ document.warning("Can't find end of ERT!!")
+ break
+ # Note that this only checks for ][ or }{ at the beginning of a line
if opt:
- bracePair = find_token(document.body, "][", lineERT)
+ bracePair = find_token(document.body, "][", lineERT, end_ERT)
else:
- bracePair = find_token(document.body, "}{", lineERT)
- # assure that the "}{" is in this ERT
- if bracePair == lineERT + 5:
+ bracePair = find_token(document.body, "}{", lineERT, end_ERT)
+ if bracePair != -1:
end = find_token(document.body, "\\end_inset", bracePair)
- document.body[lineERT : end + 1] = ["\\end_layout", "", "\\end_inset"]
+ document.body[lineERT : end_ERT + 1] = ["\\end_layout", "", "\\end_inset"]
if loop == 1:
# in the case that n > 1 we have optional arguments before
# therefore detect them if any
document.body[line + 1 : line + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
else:
document.body[line + 4 : line + 4] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
- else:
+ else: # if loop != 1
document.body[endn : endn] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
n += 1
endn = end
- loop = loop + 1
+ loop += 1
# now check the case that we have "}" + "{" in two ERTs
- else:
- endBrace = -1
+ else: # no brace pair found
if opt:
- endBrace = find_token(document.body, "]", lineERT)
+ endBrace = find_token(document.body, "]", lineERT, end_layout)
else:
- endBrace = find_token(document.body, "}", lineERT)
+ endBrace = find_token(document.body, "}", lineERT, end_layout)
if endBrace == lineERT + 5:
- beginBrace = -1
if opt:
- beginBrace = find_token(document.body, "[", endBrace)
+ beginBrace = find_token(document.body, "[", endBrace, end_layout)
else:
- beginBrace = find_token(document.body, "{", endBrace)
+ beginBrace = find_token(document.body, "{", endBrace, end_layout)
# 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)
lineERT += 1
else:
lineERT += 1
- if environment == True and lineERT != -1:
- opening = -1
+ if environment == True:
+ end_ERT = find_end_of_inset(document.body, lineERT)
+ if end_ERT == -1:
+ document.warning("Can't find end of ERT!!")
+ break
+ # Note that this only checks for [ or { at the beginning of a line
if opt:
- opening = find_token(document.body, "[", lineERT)
+ opening = find_token(document.body, "[", lineERT, end_ERT)
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"]
+ opening = find_token(document.body, "{", lineERT, end_ERT)
+ if opening != -1:
+ document.body[lineERT : end_ERT + 1] = ["\\begin_inset Argument " + str(n), "status open", "", "\\begin_layout Plain Layout"]
n += 1
- lineERT2 = find_token(document.body, "\\begin_inset ERT", lineERT)
- 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"]
- else:
- lineERT += 1
+ lineERT2 = find_token(document.body, "\\begin_inset ERT", end_ERT, end_layout)
+ if lineERT2 != -1:
+ end_ERT2 = find_end_of_inset(document.body, lineERT)
+ if end_ERT2 == -1:
+ document.warning("Can't find end of second ERT!!")
+ break
+ if opt:
+ closing = find_token(document.body, "]", lineERT2, end_ERT2)
+ else:
+ closing = find_token(document.body, "}", lineERT2, end_ERT2)
+ if closing != -1: # assure that the "}" is in this ERT
+ end2 = find_token(document.body, "\\end_inset", closing)
+ document.body[lineERT2 : end2 + 1] = ["\\end_layout", "", "\\end_inset"]
###############################################################################