]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_2_0.py
Math.lyx: describe new supported font \mathscr
[lyx.git] / lib / lyx2lyx / lyx_2_0.py
index 9c0d7497df57a8c6d26b0f34198953351000fb3a..02cc1f0fca0fed11505156d2f187cd620965c9dd 100644 (file)
@@ -1568,7 +1568,6 @@ def revert_fontcolor(document):
                            + ', ' + str(blueout) + '}\n'
                            + '\\color{document_fontcolor}\n')
 
-
 def revert_shadedboxcolor(document):
     " Reverts shaded box color to preamble code "
     i = 0
@@ -2068,14 +2067,34 @@ def convert_mathdots(document):
 
 def revert_mathdots(document):
     " Load mathdots if used in the document "
+    i = 0
+    ddots = re.compile(r'\\begin_inset Formula .*\\ddots', re.DOTALL)
+    vdots = re.compile(r'\\begin_inset Formula .*\\vdots', re.DOTALL)
+    iddots = re.compile(r'\\begin_inset Formula .*\\iddots', re.DOTALL)
+    mathdots = find_token(document.header, "\\use_mathdots" , 0)
+    no = find_token(document.header, "\\use_mathdots 0" , 0)
+    auto = find_token(document.header, "\\use_mathdots 1" , 0)
+    yes = find_token(document.header, "\\use_mathdots 2" , 0)
+    if mathdots != -1:
+      del document.header[mathdots]
     while True:
-      i = find_token(document.header, "\\use_mathdots" , 0)
-      if i != -1:
-        # use \@ifundefined to catch also the "auto" case
-        add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
-        add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}\n"])
-        del document.header[i]
-      break
+      i = find_token(document.body, '\\begin_inset Formula', i)
+      if i == -1:
+        return
+      j = find_end_of_inset(document.body, i)
+      if j == -1:
+        document.warning("Malformed LyX document: Can't find end of Formula inset.")
+        return 
+      k = ddots.search("\n".join(document.body[i:j]))
+      l = vdots.search("\n".join(document.body[i:j]))
+      m = iddots.search("\n".join(document.body[i:j]))
+      if (yes == -1) and ((no != -1) or (not k and not l and not m) or (auto != -1 and not m)):
+        i += 1
+        continue
+      # use \@ifundefined to catch also the "auto" case
+      add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
+      add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}\n"])
+      return
 
 
 def convert_rule(document):
@@ -2161,6 +2180,28 @@ def revert_rule(document):
       else:
         return
 
+def revert_diagram(document):
+  " Add the feyn package if \\Diagram is used in math "
+  i = 0
+  re_diagram = re.compile(r'\\begin_inset Formula .*\\Diagram', re.DOTALL)
+  while True:
+    i = find_token(document.body, '\\begin_inset Formula', i)
+    if i == -1:
+      return
+    j = find_end_of_inset(document.body, i)
+    if j == -1:
+        document.warning("Malformed LyX document: Can't find end of Formula inset.")
+        return 
+    m = re_diagram.search("\n".join(document.body[i:j]))
+    if not m:
+      i += 1
+      continue
+    add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
+    add_to_preamble(document, "\\usepackage{feyn}")
+    # only need to do it once!
+    return
+
+
 
 ##
 # Conversion hub
@@ -2221,10 +2262,12 @@ convert = [[346, []],
            [397, [remove_Nameref]],
            [398, []],
            [399, [convert_mathdots]],
-           [400, [convert_rule]]
+           [400, [convert_rule]],
+           [401, []]
           ]
 
-revert =  [[399, [revert_rule]],
+revert =  [[400, [revert_diagram]],
+           [399, [revert_rule]],
            [398, [revert_mathdots]],
            [397, [revert_mathrsfs]],
            [396, []],