return string.replace(src, '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n'
+ dst + '\n\\end_layout\n\\end_inset\n')
-
####################################################################
def fix_wrong_tables(document):
def revert_latexcommand_index(document):
- "Revert from collapsable form toLatexCommand form."
+ "Revert from collapsable form to LatexCommand form."
i = 0
while True:
i = find_token(document.body, "\\begin_inset Index", i)
line = line[10:]
if line.startswith("status collapsed"):
line = line[16:]
+ line = line.replace(u'ä', r'\\\"a').replace(u'ö', r'\\\"o').replace(u'ü', r'\\\"u')
content = content + line;
document.body[i + 3] = "name " + '"' + content + '"'
for k in range(i + 4, j - 2):
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)'
i = i + 1
+def revert_slash(document):
+ 'Revert \\SpecialChar \\slash{} to ERT'
+ for i in range(len(document.body)):
+ document.body[i] = document.body[i].replace('\\SpecialChar \\slash{}', \
+ '\\begin_inset ERT\nstatus collapsed\n\n' \
+ '\\begin_layout Standard\n\n\n\\backslash\n' \
+ 'slash{}\n\\end_layout\n\n\\end_inset\n\n')
+
+
+def revert_nobreakdash(document):
+ 'Revert \\SpecialChar \\nobreakdash- to ERT'
+ found = 0
+ for i in range(len(document.body)):
+ line = document.body[i]
+ r = re.compile(r'\\SpecialChar \\nobreakdash-')
+ m = r.match(line)
+ if m:
+ found = 1
+ document.body[i] = document.body[i].replace('\\SpecialChar \\nobreakdash-', \
+ '\\begin_inset ERT\nstatus collapsed\n\n' \
+ '\\begin_layout Standard\n\n\n\\backslash\n' \
+ 'nobreakdash-\n\\end_layout\n\n\\end_inset\n\n')
+ if not found:
+ return
+ j = find_token(document.header, "\\use_amsmath", 0)
+ if j == -1:
+ document.warning("Malformed LyX document: Missing '\\use_amsmath'.")
+ return
+ document.header[j] = "\\use_amsmath 2"
+
+
+def revert_nocite_key(body, start, end):
+ 'key "..." -> \nocite{...}'
+ for i in range(start, end):
+ if (body[i][0:5] == 'key "'):
+ body[i] = body[i].replace('key "', "\\backslash\nnocite{")
+ body[i] = body[i].replace('"', "}")
+ else:
+ body[i] = ""
+
+
+def revert_nocite(document):
+ "Revert LatexCommand nocite to ERT"
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\begin_inset CommandInset citation", i)
+ if i == -1:
+ return
+ i = i + 1
+ if (document.body[i] == "LatexCommand nocite"):
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ #this should not happen
+ document.warning("End of CommandInset citation not found in revert_nocite!")
+ revert_nocite_key(document.body, i + 1, len(document.body))
+ return
+ revert_nocite_key(document.body, i + 1, j)
+ document.body[i-1] = "\\begin_inset ERT"
+ document.body[i] = "status collapsed\n\n" \
+ "\\begin_layout Standard"
+ document.body.insert(j, "\\end_layout\n");
+ i = j
+
+
+def revert_btprintall(document):
+ "Revert (non-bibtopic) btPrintAll option to ERT \nocite{*}"
+ i = find_token(document.header, '\\use_bibtopic', 0)
+ if i == -1:
+ document.warning("Malformed lyx document: Missing '\\use_bibtopic'.")
+ return
+ if get_value(document.header, '\\use_bibtopic', 0) == "false":
+ i = 0
+ while i < len(document.body):
+ i = find_token(document.body, "\\begin_inset CommandInset bibtex", i)
+ if i == -1:
+ return
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ #this should not happen
+ document.warning("End of CommandInset bibtex not found in revert_btprintall!")
+ j = len(document.body)
+ for k in range(i, j):
+ if (document.body[k] == 'btprint "btPrintAll"'):
+ del document.body[k]
+ document.body.insert(i, "\\begin_inset ERT\n" \
+ "status collapsed\n\n\\begin_layout Standard\n\n" \
+ "\\backslash\nnocite{*}\n" \
+ "\\end_layout\n\\end_inset\n")
+ i = j
+
+
def revert_bahasam(document):
"Set language Bahasa Malaysia to Bahasa Indonesia"
i = 0
j = j + 1
+def revert_serbianlatin(document):
+ "Set language Serbian-Latin to Croatian"
+ i = 0
+ if document.language == "serbian-latin":
+ document.language = "croatian"
+ i = find_token(document.header, "\\language", 0)
+ if i != -1:
+ document.header[i] = "\\language croatian"
+ j = 0
+ while True:
+ j = find_token(document.body, "\\lang serbian-latin", j)
+ if j == -1:
+ return
+ document.body[j] = document.body[j].replace("\\lang serbian-latin", "\\lang croatian")
+ j = j + 1
+
+
##
# Conversion hub
#
[303, [convert_serbocroatian]],
[304, [convert_framed_notes]],
[305, []],
- [306, []]
+ [306, []],
+ [307, []],
+ [308, []],
+ [309, []],
+ [310, []],
+ [311, [convert_ams_classes]]
]
-revert = [[305, [revert_interlingua]],
+revert = [[310, []],
+ [309, [revert_btprintall]],
+ [308, [revert_nocite]],
+ [307, [revert_serbianlatin]],
+ [306, [revert_slash, revert_nobreakdash]],
+ [305, [revert_interlingua]],
[304, [revert_bahasam]],
[303, [revert_framed_notes]],
[302, []],