]> git.lyx.org Git - features.git/commitdiff
Fix conversion of 1.5.x documents that conflict with mchchem
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 22 Nov 2010 21:07:20 +0000 (21:07 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Mon, 22 Nov 2010 21:07:20 +0000 (21:07 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36437 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/lyx_2_0.py

index 2cd365110f063ff0a5e5fa2f86b2e00570e65750..b3a9fe0fe78bcac1b9a03f9f43f90dd91249b192 100644 (file)
@@ -816,6 +816,28 @@ def revert_suppress_date(document):
     del document.header[i]
 
 
+def convert_mhchem(document):
+    "Set mhchem to off for versions older than 1.6.x"
+    if document.start < 277:
+        # LyX 1.5.x and older did never load mhchem.
+        # Therefore we must switch it off: Documents that use mhchem have
+        # a manual \usepackage anyway, and documents not using mhchem but
+        # custom macros with the same names as mhchem commands might get
+        # corrupted if mhchem is automatically loaded.
+        mhchem = 0 # off
+    else:
+        # LyX 1.6.x did always load mhchem automatically.
+        mhchem = 1 # auto
+    i = find_token(document.header, "\\use_esint", 0)
+    if i == -1:
+        # pre-1.5.x document
+        i = find_token(document.header, "\\use_amsmath", 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Could not find amsmath os esint setting.")
+        return
+    document.header.insert(i + 1, "\\use_mhchem %d" % mhchem)
+
+
 def revert_mhchem(document):
     "Revert mhchem loading to preamble code"
 
@@ -1805,7 +1827,9 @@ def revert_flexnames(document):
 
 def convert_mathdots(document):
     " Load mathdots automatically "
-    i = find_token(document.header, "\\use_esint" , 0)
+    i = find_token(document.header, "\\use_mhchem" , 0)
+    if i == -1:
+      i = find_token(document.header, "\\use_esint" , 0)
     if i != -1:
       document.header.insert(i + 1, "\\use_mathdots 1")
 
@@ -2367,7 +2391,7 @@ convert = [[346, []],
            [368, []],
            [369, [convert_author_id]],
            [370, []],
-           [371, []],
+           [371, [convert_mhchem]],
            [372, []],
            [373, [merge_gbrief]],
            [374, []],