Clean up Solution and Solution* reversion code a bit.

This commit is contained in:
Richard Heck 2015-11-28 23:42:09 -05:00
parent 727c845808
commit acf3e3a139

View File

@ -2121,9 +2121,10 @@ def revert_solution(document):
if mod == "theorems-std" or mod == "theorems-bytype" \ if mod == "theorems-std" or mod == "theorems-bytype" \
or mod == "theorems-ams" or mod == "theorems-ams-bytype": or mod == "theorems-ams" or mod == "theorems-ams-bytype":
have_mod = True have_mod = True
continue break
if not have_mod: if not have_mod:
return return
consecutive = False consecutive = False
is_starred = False is_starred = False
i = 0 i = 0
@ -2131,6 +2132,7 @@ def revert_solution(document):
i = find_token(document.body, "\\begin_layout Solution", i) i = find_token(document.body, "\\begin_layout Solution", i)
if i == -1: if i == -1:
return return
is_starred = document.body[i].startswith("\\begin_layout Solution*") is_starred = document.body[i].startswith("\\begin_layout Solution*")
if is_starred == True: if is_starred == True:
LaTeXName = "sol*" LaTeXName = "sol*"
@ -2140,31 +2142,35 @@ def revert_solution(document):
LaTeXName = "sol" LaTeXName = "sol"
LyXName = "Solution" LyXName = "Solution"
theoremName = "newtheorem" theoremName = "newtheorem"
j = find_end_of_layout(document.body, i) j = find_end_of_layout(document.body, i)
if j == -1: if j == -1:
document.warning("Malformed LyX document: Can't find end of " + LyXName + " layout") document.warning("Malformed LyX document: Can't find end of " + LyXName + " layout")
i += 1 i += 1
continue continue
# if this is not a consecutive env, add start command # if this is not a consecutive env, add start command
begcmd = [] begcmd = []
if not consecutive: if not consecutive:
begcmd = put_cmd_in_ert("\\begin{" + LaTeXName + "}" ) begcmd = put_cmd_in_ert("\\begin{%s}" % (LaTeXName))
# has this a consecutive theorem of same type? # has this a consecutive theorem of same type?
consecutive = False
consecutive = document.body[j + 2] == "\\begin_layout " + LyXName consecutive = document.body[j + 2] == "\\begin_layout " + LyXName
# if this is not followed by a consecutive env, add end command # if this is not followed by a consecutive env, add end command
if not consecutive: if not consecutive:
document.body[j : j + 1] = put_cmd_in_ert("\\end{" + LaTeXName + "}") + ["\\end_layout"] document.body[j : j + 1] = put_cmd_in_ert("\\end{%s}" % (LaTeXName)) + ["\\end_layout"]
document.body[i : i + 1] = ["\\begin_layout Standard", ""] + begcmd document.body[i : i + 1] = ["\\begin_layout Standard", ""] + begcmd
add_to_preamble(document, "\\theoremstyle{definition}") add_to_preamble(document, "\\theoremstyle{definition}")
if mod == "theorems-std" or mod == "theorems-ams": if is_starred or mod == "theorems-bytype" or mod == "theorems-ams-bytype":
if is_starred: add_to_preamble(document, "\\%s{%s}{\\protect\\solutionname}" % \
add_to_preamble(document, "\\" + theoremName + "{" + LaTeXName + "}{\\protect\\solutionname}") (theoremName, LaTeXName))
else: else: # mod == "theorems-std" or mod == "theorems-ams" and not is_starred
add_to_preamble(document, "\\" + theoremName + "{" + LaTeXName + "}[thm]{\\protect\\solutionname}") add_to_preamble(document, "\\%s{%s}[thm]{\\protect\\solutionname}" % \
if mod == "theorems-bytype" or mod == "theorems-ams-bytype": (theoremName, LaTeXName))
add_to_preamble(document, "\\" + theoremName + "{" + LaTeXName + "}{\\protect\\solutionname}")
add_to_preamble(document, "\\providecommand{\solutionname}{Solution}") add_to_preamble(document, "\\providecommand{\solutionname}{Solution}")
i = j i = j