diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index 1ebb67c52c..c4912ab9dd 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 2)), - ("1_6", range(277,311), minor_versions("1.6" , 0))] # Bernhard Reiter: \nocite{*} + ("1_6", range(277,312), minor_versions("1.6" , 0))] # Richard Heck: AMS conversion def formats_list(): @@ -390,6 +390,28 @@ class LyX_base: self.header[i] = "\\textclass %s" % self.textclass + #Note that the module will be added at the END of the extant ones + def add_module(self, module): + i = find_token(self.header, "\\begin_modules", 0) + if i == -1: + #No modules yet included + i = find_token(self.header, "\\textclass", 0) + if i == -1: + self.warning("Malformed LyX document: No \\textclass!!") + return + modinfo = ["\\begin_modules", module, "\\end_modules"] + self.header[i + 1: i + 1] = modinfo + return + j = find_token(self.header, "\\end_modules", i) + if j == -1: + self.warning("Malformed LyX document: No \\end_modules.") + return + k = find_token(self.header, module, i) + if k != -1 and k < j: + return + self.header.insert(j, module) + + def set_parameter(self, param, value): " Set the value of the header parameter." i = find_token(self.header, '\\' + param, 0) diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 81ca4da28f..81edf662e2 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -36,27 +36,6 @@ def wrap_into_ert(string, src, dst): return string.replace(src, '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n' + dst + '\n\\end_layout\n\\end_inset\n') -def add_module(module): - i = find_token(document.header, "\\begin_modules", 0) - if i == -1: - #No modules yet included - i = find_token(document.header, "\\textclass", 0) - if i == -1: - document.warning("Malformed LyX document: No \\textclass!!") - return - modinfo = ["\\begin_modules", module, "\\end_modules"] - document.header[i + 1: i + 1] = modinfo - return - j = find_token(document.header, "\\end_modules", i) - if j == -1: - document.warning("Malformed LyX document: No \\end_modules.") - return - k = find_token(document.header, module, i) - if k != -1 and k < j: - return - document.header.insert(i + 1, module) - - #################################################################### def fix_wrong_tables(document): @@ -633,6 +612,43 @@ def convert_url(document): document.body[i:k] = newstuff i = k +def convert_ams_classes(document): + tc = document.textclass + if (tc != "amsart" and tc != "amsart-plain" and + tc == "amsart-seq" and tc == "amsbook"): + return + if tc == "amsart-plain": + document.textclass = "amsart" + document.set_textclass() + document.add_module("Theorems (Starred)") + return + if tc == "amsart-seq": + document.textclass = "amsart" + document.set_textclass() + document.add_module("Theorems (AMS)") + + #Now we want to see if any of the environments in the extended theorems + #module were used in this document. If so, we'll add that module, too. + layouts = ["Criterion", "Algorithm", "Axiom", "Condition", "Note", \ + "Notation", "Summary", "Acknowledgement", "Conclusion", "Fact", \ + "Assumption"] + + r = re.compile(r'^\\begin_layout (.*?)\*?\s*$') + i = 0 + while True: + i = find_token(document.body, "\\begin_layout", i) + if i == -1: + return + m = r.match(document.body[i]) + if m == None: + document.warning("Weirdly formed \\begin_layout at line " + i + " of body!") + i += 1 + continue + m = m.group(1) + if layouts.count(m) != 0: + document.add_module("Theorems (AMS-Extended)") + return + i += 1 def revert_href(document): 'Reverts hyperlink insets (href) to url insets (url)' @@ -1114,10 +1130,12 @@ convert = [[277, [fix_wrong_tables]], [307, []], [308, []], [309, []], - [310, []] + [310, []], + [311, [convert_ams_classes]] ] -revert = [[309, [revert_btprintall]], +revert = [[310, []], + [309, [revert_btprintall]], [308, [revert_nocite]], [307, [revert_serbianlatin]], [306, [revert_slash, revert_nobreakdash]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index bc65a0cc74..5d90106fad 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -118,7 +118,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 310; // Bernhard Reiter: support for \nocite{*} +int const LYX_FORMAT = 311; // Richard Heck: a dummy format to drive the AMS conversion } // namespace anon