]> git.lyx.org Git - features.git/blobdiff - lib/lyx2lyx/lyx_2_4.py
Avoid copies of vectors.
[features.git] / lib / lyx2lyx / lyx_2_4.py
index f1c06ca39cd3b4b8880cda180fbd29b259e62c0d..9dfaeaea47a148ec28787a24d7f6afe391230b09 100644 (file)
@@ -27,11 +27,12 @@ from datetime import (datetime, date, time)
 # Uncomment only what you need to import, please.
 
 from parser_tools import (count_pars_in_inset, del_complete_lines, del_token,
-    find_end_of_inset, find_end_of_layout, find_token, find_token_backwards,
-    find_token_exact, find_re, get_bool_value, get_containing_inset,
-    get_containing_layout, get_option_value, get_value, get_quoted_value)
+     find_end_of, find_end_of_inset, find_end_of_layout, find_token,
+     find_token_backwards, find_token_exact, find_re, get_bool_value,
+     get_containing_inset, get_containing_layout, get_option_value, get_value,
+     get_quoted_value)
 #    del_value, 
-#    find_complete_lines, find_end_of,
+#    find_complete_lines,
 #    find_re, find_substring,
 #    is_in_inset, set_bool_value
 #    find_tokens, check_token
@@ -4369,6 +4370,63 @@ def convert_vcolumns2(document):
                                  r'\usepackage{varwidth}'])
 
 
+frontispiece_def = [
+    r'### Inserted by lyx2lyx (frontispiece layout) ###',
+    r'Style Frontispiece',
+    r'  CopyStyle             Titlehead',
+    r'  LatexName             frontispiece',
+    r'End',
+]
+
+
+def convert_koma_frontispiece(document):
+    """Remove local KOMA frontispiece definition"""
+    if document.textclass[:3] != "scr":
+        return
+
+    if document.del_local_layout(frontispiece_def):
+        document.add_module("ruby")
+
+
+def revert_koma_frontispiece(document):
+    """Add local KOMA frontispiece definition"""
+    if document.textclass[:3] != "scr":
+        return
+
+    if find_token(document.body, "\\begin_layout Frontispiece", 0) != -1:
+        document.append_local_layout(frontispiece_def)
+
+
+def revert_spellchecker_ignore(document):
+    """Revert document spellchecker dictionary"""
+    while True:
+        i = find_token(document.header, "\\spellchecker_ignore")
+        if i == -1:
+            return
+        del document.header[i]
+
+
+def revert_docbook_mathml_prefix(document):
+    """Revert the DocBook parameter to choose the prefix for the MathML name space"""
+    while True:
+        i = find_token(document.header, "\\docbook_mathml_prefix")
+        if i == -1:
+            return
+        del document.header[i]
+
+def revert_document_metadata(document):
+    """Revert document metadata"""
+    i = 0
+    while True:
+        i = find_token(document.header, "\\begin_metadata", i)
+        if i == -1:
+            return
+        j = find_end_of(document.header, i, "\\begin_metadata", "\\end_metadata")
+        if j == -1:
+            # this should not happen
+            break
+        document.header[i : j + 1] = []
+
 ##
 # Conversion hub
 #
@@ -4435,10 +4493,18 @@ convert = [
            [602, [convert_branch_colors]],
            [603, []],
            [604, []],
-           [605, [convert_vcolumns2]]
+           [605, [convert_vcolumns2]],
+           [606, [convert_koma_frontispiece]],
+           [607, []],
+           [608, []],
+           [609, []]
           ]
 
-revert =  [[604, [revert_vcolumns2]],
+revert =  [[608, [revert_document_metadata]],
+           [607, [revert_docbook_mathml_prefix]],
+           [606, [revert_spellchecker_ignore]],
+           [605, [revert_koma_frontispiece]],
+           [604, [revert_vcolumns2]],
            [603, [revert_branch_darkcols]],
            [602, [revert_darkmode_graphics]],
            [601, [revert_branch_colors]],