Fix revert_mhchem routine.

Please remember that find_token only looks at the beginning of the line!


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36054 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-11-04 13:56:46 +00:00
parent 224a56f215
commit 3215a451dd

View File

@ -1184,34 +1184,34 @@ def revert_suppress_date(document):
def revert_mhchem(document): def revert_mhchem(document):
"Revert mhchem loading to preamble code" "Revert mhchem loading to preamble code"
i = 0
j = 0
k = 0
mhchem = "off" mhchem = "off"
i = find_token(document.header, "\\use_mhchem 1", 0) i = find_token(document.header, "\\use_mhchem", 0)
if i != -1: if i == -1:
document.warning("Malformed LyX document: Could not find mhchem setting.")
mhchem = "auto" mhchem = "auto"
else: else:
i = find_token(document.header, "\\use_mhchem 2", 0) val = get_value(document.header, "\\use_mhchem", i)
if i != -1: if val == "1":
mhchem = "auto"
elif val == "2":
mhchem = "on" mhchem = "on"
del document.header[i]
if mhchem == "auto": if mhchem == "auto":
j = find_token(document.body, "\\cf{", 0) i = 0
if j != -1: while True:
mhchem = "on" i = find_token(document.body, "\\begin_inset Formula", i)
else: line = document.body[i]
j = find_token(document.body, "\\ce{", 0) if line.find("\\ce{") != -1 or line.find("\\cf{") != 1:
if j != -1: mhchem = "on"
mhchem = "on" break
if mhchem == "on": if mhchem == "on":
add_to_preamble(document, ["% this command was inserted by lyx2lyx"]) pre = ["% lyx2lyx mhchem commands",
add_to_preamble(document, ["\\PassOptionsToPackage{version=3}{mhchem}"]) "\\PassOptionsToPackage{version=3}{mhchem}",
add_to_preamble(document, ["\\usepackage{mhchem}"]) "\\usepackage{mhchem}"]
k = find_token(document.header, "\\use_mhchem", 0) add_to_preamble(document, pre)
if k == -1:
document.warning("Malformed LyX document: Could not find mhchem setting.")
return
del document.header[k]
def revert_fontenc(document): def revert_fontenc(document):