1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007 José Matos <jamatos@lyx.org>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 """ Convert files to the file format generated by lyx 1.6"""
25 from parser_tools import find_token, find_end_of, find_tokens, get_value
27 ####################################################################
28 # Private helper functions
30 def find_end_of_inset(lines, i):
31 " Find end of inset, where lines[i] is included."
32 return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
34 def wrap_into_ert(string, src, dst):
35 " Wrap a something into an ERT"
36 return string.replace(src, '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n'
37 + dst + '\n\\end_layout\n\\end_inset\n')
39 def add_module(module):
40 i = find_token(document.header, "\\begin_modules", 0)
42 #No modules yet included
43 i = find_token(document.header, "\\textclass", 0)
45 document.warning("Malformed LyX document: No \\textclass!!")
47 modinfo = ["\\begin_modules", module, "\\end_modules"]
48 document.header[i + 1: i + 1] = modinfo
50 j = find_token(document.header, "\\end_modules", i)
52 document.warning("Malformed LyX document: No \\end_modules.")
54 k = find_token(document.header, module, i)
57 document.header.insert(i + 1, module)
60 ####################################################################
62 def fix_wrong_tables(document):
65 i = find_token(document.body, "\\begin_inset Tabular", i)
68 j = find_end_of_inset(document.body, i + 1)
70 document.warning("Malformed LyX document: Could not find end of tabular.")
74 nrows = int(document.body[i+1].split('"')[3])
75 ncols = int(document.body[i+1].split('"')[5])
77 for l in range(nrows):
79 for k in range(ncols):
80 m = find_token(document.body, '<cell', m)
82 if document.body[m].find('multicolumn') != -1:
83 multicol_cont = int(document.body[m].split('"')[1])
85 if multicol_cont == 2 and (k == 0 or prev_multicolumn == 0):
86 document.body[m] = document.body[m][:5] + document.body[m][21:]
89 prev_multicolumn = multicol_cont
96 def close_begin_deeper(document):
100 i = find_tokens(document.body, ["\\begin_deeper", "\\end_deeper"], i)
105 if document.body[i][:13] == "\\begin_deeper":
112 document.body[-2:-2] = ['\\end_deeper' for i in range(depth)]
115 def long_charstyle_names(document):
118 i = find_token(document.body, "\\begin_inset CharStyle", i)
121 document.body[i] = document.body[i].replace("CharStyle ", "CharStyle CharStyle:")
124 def revert_long_charstyle_names(document):
127 i = find_token(document.body, "\\begin_inset CharStyle", i)
130 document.body[i] = document.body[i].replace("CharStyle CharStyle:", "CharStyle")
134 def axe_show_label(document):
137 i = find_token(document.body, "\\begin_inset CharStyle", i)
140 if document.body[i + 1].find("show_label") != -1:
141 if document.body[i + 1].find("true") != -1:
142 document.body[i + 1] = "status open"
143 del document.body[ i + 2]
145 if document.body[i + 1].find("false") != -1:
146 document.body[i + 1] = "status collapsed"
147 del document.body[ i + 2]
149 document.warning("Malformed LyX document: show_label neither false nor true.")
151 document.warning("Malformed LyX document: show_label missing in CharStyle.")
156 def revert_show_label(document):
159 i = find_token(document.body, "\\begin_inset CharStyle", i)
162 if document.body[i + 1].find("status open") != -1:
163 document.body.insert(i + 1, "show_label true")
165 if document.body[i + 1].find("status collapsed") != -1:
166 document.body.insert(i + 1, "show_label false")
168 document.warning("Malformed LyX document: no legal status line in CharStyle.")
171 def revert_begin_modules(document):
174 i = find_token(document.header, "\\begin_modules", i)
177 j = find_end_of(document.header, i, "\\begin_modules", "\\end_modules")
179 # this should not happen
181 document.header[i : j + 1] = []
183 def convert_flex(document):
184 "Convert CharStyle to Flex"
187 i = find_token(document.body, "\\begin_inset CharStyle", i)
190 document.body[i] = document.body[i].replace('\\begin_inset CharStyle', '\\begin_inset Flex')
192 def revert_flex(document):
193 "Convert Flex to CharStyle"
196 i = find_token(document.body, "\\begin_inset Flex", i)
199 document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
202 # Discard PDF options for hyperref
203 def revert_pdf_options(document):
204 "Revert PDF options for hyperref."
206 i = find_token(document.header, "\\use_hyperref", i)
208 del document.header[i]
209 i = find_token(document.header, "\\pdf_store_options", i)
211 del document.header[i]
212 i = find_token(document.header, "\\pdf_title", 0)
214 del document.header[i]
215 i = find_token(document.header, "\\pdf_author", 0)
217 del document.header[i]
218 i = find_token(document.header, "\\pdf_subject", 0)
220 del document.header[i]
221 i = find_token(document.header, "\\pdf_keywords", 0)
223 del document.header[i]
224 i = find_token(document.header, "\\pdf_bookmarks", 0)
226 del document.header[i]
227 i = find_token(document.header, "\\pdf_bookmarksnumbered", i)
229 del document.header[i]
230 i = find_token(document.header, "\\pdf_bookmarksopen", i)
232 del document.header[i]
233 i = find_token(document.header, "\\pdf_bookmarksopenlevel", i)
235 del document.header[i]
236 i = find_token(document.header, "\\pdf_breaklinks", i)
238 del document.header[i]
239 i = find_token(document.header, "\\pdf_pdfborder", i)
241 del document.header[i]
242 i = find_token(document.header, "\\pdf_colorlinks", i)
244 del document.header[i]
245 i = find_token(document.header, "\\pdf_backref", i)
247 del document.header[i]
248 i = find_token(document.header, "\\pdf_pagebackref", i)
250 del document.header[i]
251 i = find_token(document.header, "\\pdf_pagemode", 0)
253 del document.header[i]
254 i = find_token(document.header, "\\pdf_quoted_options", 0)
256 del document.header[i]
259 def remove_inzip_options(document):
260 "Remove inzipName and embed options from the Graphics inset"
263 i = find_token(document.body, "\\begin_inset Graphics", i)
266 j = find_end_of_inset(document.body, i + 1)
269 document.warning("Malformed LyX document: Could not find end of graphics inset.")
270 # If there's a inzip param, just remove that
271 k = find_token(document.body, "\tinzipName", i + 1, j)
274 # embed option must follow the inzipName option
275 del document.body[k+1]
279 def convert_inset_command(document):
282 \begin_inset LatexCommand cmd
284 \begin_inset CommandInset InsetType
289 i = find_token(document.body, "\\begin_inset LatexCommand", i)
292 line = document.body[i]
293 r = re.compile(r'\\begin_inset LatexCommand (.*)$')
297 #this is adapted from factory.cpp
298 if cmdName[0:4].lower() == "cite":
299 insetName = "citation"
300 elif cmdName == "url" or cmdName == "htmlurl":
302 elif cmdName[-3:] == "ref":
304 elif cmdName == "tableofcontents":
306 elif cmdName == "printnomenclature":
307 insetName = "nomencl_print"
308 elif cmdName == "printindex":
309 insetName = "index_print"
312 insertion = ["\\begin_inset CommandInset " + insetName, "LatexCommand " + cmdName]
313 document.body[i : i+1] = insertion
316 def revert_inset_command(document):
319 \begin_inset CommandInset InsetType
322 \begin_inset LatexCommand cmd
323 Some insets may end up being converted to insets earlier versions of LyX
324 will not be able to recognize. Not sure what to do about that.
328 i = find_token(document.body, "\\begin_inset CommandInset", i)
331 nextline = document.body[i+1]
332 r = re.compile(r'LatexCommand\s+(.*)$')
333 m = r.match(nextline)
335 document.warning("Malformed LyX document: Missing LatexCommand in " + document.body[i] + ".")
338 insertion = ["\\begin_inset LatexCommand " + cmdName]
339 document.body[i : i+2] = insertion
342 def convert_wrapfig_options(document):
343 "Convert optional options for wrap floats (wrapfig)."
344 # adds the tokens "lines", "placement", and "overhang"
347 i = find_token(document.body, "\\begin_inset Wrap figure", i)
350 document.body.insert(i + 1, "lines 0")
351 j = find_token(document.body, "placement", i)
352 # placement can be already set or not; if not, set it
354 document.body.insert(i + 3, "overhang 0col%")
356 document.body.insert(i + 2, "placement o")
357 document.body.insert(i + 3, "overhang 0col%")
361 def revert_wrapfig_options(document):
362 "Revert optional options for wrap floats (wrapfig)."
365 i = find_token(document.body, "lines", i)
368 j = find_token(document.body, "overhang", i+1)
369 if j != i + 2 and j != -1:
370 document.warning("Malformed LyX document: Couldn't find overhang parameter of wrap float.")
374 del document.body[j-1]
378 def convert_latexcommand_index(document):
379 "Convert from LatexCommand form to collapsable form."
382 i = find_token(document.body, "\\begin_inset CommandInset index", i)
385 if document.body[i + 1] != "LatexCommand index": # Might also be index_print
387 fullcontent = document.body[i + 2][6:].strip('"')
388 document.body[i:i + 2] = ["\\begin_inset Index",
390 "\\begin_layout Standard"]
391 # Put here the conversions needed from LaTeX string to LyXText.
392 # Here we do a minimal conversion to prevent crashes and data loss.
393 # Manual patch-up may be needed.
394 # Umlauted characters (most common ones, can be extended):
395 fullcontent = fullcontent.replace(r'\\\"a', u'ä').replace(r'\\\"o', u'ö').replace(r'\\\"u', u'ü')
397 fullcontent = wrap_into_ert(fullcontent, r'\"', '"')
398 #fullcontent = fullcontent.replace(r'\"', '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout standard\n"\n\\end_layout\n\\end_inset\n')
400 r = re.compile('^(.*?)(\$.*?\$)(.*)')
405 f = m.group(2).replace('\\\\', '\\')
409 s = wrap_into_ert(s, r'\\', '\\backslash')
410 s = wrap_into_ert(s, '{', '{')
411 s = wrap_into_ert(s, '}', '}')
412 document.body.insert(i + 3, s)
414 document.body.insert(i + 3, "\\begin_inset Formula " + f)
415 document.body.insert(i + 4, "\\end_inset")
417 # Generic, \\ -> \backslash:
418 g = wrap_into_ert(g, r'\\', '\\backslash{}')
419 g = wrap_into_ert(g, '{', '{')
420 g = wrap_into_ert(g, '}', '}')
421 document.body.insert(i + 3, g)
422 document.body[i + 4] = "\\end_layout"
426 def revert_latexcommand_index(document):
427 "Revert from collapsable form to LatexCommand form."
430 i = find_token(document.body, "\\begin_inset Index", i)
433 j = find_end_of_inset(document.body, i + 1)
436 del document.body[j - 1]
437 del document.body[j - 2] # \end_layout
438 document.body[i] = "\\begin_inset CommandInset index"
439 document.body[i + 1] = "LatexCommand index"
440 # clean up multiline stuff
442 for k in range(i + 3, j - 2):
443 line = document.body[k]
444 if line.startswith("\\begin_inset ERT"):
446 if line.startswith("\\begin_inset Formula"):
448 if line.startswith("\\begin_layout Standard"):
450 if line.startswith("\\end_layout"):
452 if line.startswith("\\end_inset"):
454 if line.startswith("status collapsed"):
456 line = line.replace(u'ä', r'\\\"a').replace(u'ö', r'\\\"o').replace(u'ü', r'\\\"u')
457 content = content + line;
458 document.body[i + 3] = "name " + '"' + content + '"'
459 for k in range(i + 4, j - 2):
460 del document.body[i + 4]
461 document.body.insert(i + 4, "")
462 del document.body[i + 2] # \begin_layout standard
466 def revert_wraptable(document):
467 "Revert wrap table to wrap figure."
470 i = find_token(document.body, "\\begin_inset Wrap table", i)
473 document.body[i] = document.body[i].replace('\\begin_inset Wrap table', '\\begin_inset Wrap figure')
477 def revert_vietnamese(document):
478 "Set language Vietnamese to English"
479 # Set document language from Vietnamese to English
481 if document.language == "vietnamese":
482 document.language = "english"
483 i = find_token(document.header, "\\language", 0)
485 document.header[i] = "\\language english"
488 j = find_token(document.body, "\\lang vietnamese", j)
491 document.body[j] = document.body[j].replace("\\lang vietnamese", "\\lang english")
495 def revert_japanese(document):
496 "Set language japanese-plain to japanese"
497 # Set document language from japanese-plain to japanese
499 if document.language == "japanese-plain":
500 document.language = "japanese"
501 i = find_token(document.header, "\\language", 0)
503 document.header[i] = "\\language japanese"
506 j = find_token(document.body, "\\lang japanese-plain", j)
509 document.body[j] = document.body[j].replace("\\lang japanese-plain", "\\lang japanese")
513 def revert_japanese_encoding(document):
514 "Set input encoding form EUC-JP-plain to EUC-JP etc."
515 # Set input encoding form EUC-JP-plain to EUC-JP etc.
517 i = find_token(document.header, "\\inputencoding EUC-JP-plain", 0)
519 document.header[i] = "\\inputencoding EUC-JP"
521 j = find_token(document.header, "\\inputencoding JIS-plain", 0)
523 document.header[j] = "\\inputencoding JIS"
525 k = find_token(document.header, "\\inputencoding SJIS-plain", 0)
526 if k != -1: # convert to UTF8 since there is currently no SJIS encoding
527 document.header[k] = "\\inputencoding UTF8"
530 def revert_inset_info(document):
531 'Replace info inset with its content'
534 i = find_token(document.body, '\\begin_inset Info', i)
537 j = find_end_of_inset(document.body, i + 1)
540 document.warning("Malformed LyX document: Could not find end of Info inset.")
543 for k in range(i, j+1):
544 if document.body[k].startswith("arg"):
545 arg = document.body[k][3:].strip().strip('"')
546 if document.body[k].startswith("type"):
547 type = document.body[k][4:].strip().strip('"')
548 # I think there is a newline after \\end_inset, which should be removed.
549 if document.body[j + 1].strip() == "":
550 document.body[i : (j + 2)] = [type + ':' + arg]
552 document.body[i : (j + 1)] = [type + ':' + arg]
555 def convert_pdf_options(document):
556 # Set the pdfusetitle tag, delete the pdf_store_options,
557 # set quotes for bookmarksopenlevel"
558 has_hr = get_value(document.header, "\\use_hyperref", 0, default = "0")
560 k = find_token(document.header, "\\use_hyperref", 0)
561 document.header.insert(k + 1, "\\pdf_pdfusetitle true")
562 k = find_token(document.header, "\\pdf_store_options", 0)
564 del document.header[k]
565 i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
567 document.header[i] = document.header[i].replace('"', '')
570 def revert_pdf_options_2(document):
571 # reset the pdfusetitle tag, set quotes for bookmarksopenlevel"
572 k = find_token(document.header, "\\use_hyperref", 0)
573 i = find_token(document.header, "\\pdf_pdfusetitle", k)
575 del document.header[i]
576 i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
578 values = document.header[i].split()
579 values[1] = ' "' + values[1] + '"'
580 document.header[i] = ''.join(values)
583 def convert_htmlurl(document):
584 'Convert "htmlurl" to "href" insets for docbook'
585 if document.backend != "docbook":
589 i = find_token(document.body, "\\begin_inset CommandInset url", i)
592 document.body[i] = "\\begin_inset CommandInset href"
593 document.body[i + 1] = "LatexCommand href"
597 def convert_url(document):
598 'Convert url insets to url charstyles'
599 if document.backend == "docbook":
603 i = find_token(document.body, "\\begin_inset CommandInset url", i)
606 n = find_token(document.body, "name", i)
608 # place the URL name in typewriter before the new URL insert
609 # grab the name 'bla' from the e.g. the line 'name "bla"',
610 # therefore start with the 6th character
611 name = document.body[n][6:-1]
612 newname = [name + " "]
613 document.body[i:i] = newname
615 j = find_token(document.body, "target", i)
617 document.warning("Malformed LyX document: Can't find target for url inset")
620 target = document.body[j][8:-1]
621 k = find_token(document.body, "\\end_inset", j)
623 document.warning("Malformed LyX document: Can't find end of url inset")
626 newstuff = ["\\begin_inset Flex URL",
627 "status collapsed", "",
628 "\\begin_layout Standard",
633 document.body[i:k] = newstuff
637 def revert_href(document):
638 'Reverts hyperlink insets (href) to url insets (url)'
641 i = find_token(document.body, "\\begin_inset CommandInset href", i)
644 document.body[i : i + 2] = \
645 ["\\begin_inset CommandInset url", "LatexCommand url"]
649 def convert_include(document):
650 'Converts include insets to new format.'
652 r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
654 i = find_token(document.body, "\\begin_inset Include", i)
657 line = document.body[i]
658 previewline = document.body[i + 1]
661 document.warning("Unable to match line " + str(i) + " of body!")
667 insertion = ["\\begin_inset CommandInset include",
668 "LatexCommand " + cmd, previewline,
669 "filename \"" + fn + "\""]
672 insertion.append("lstparams " + '"' + opt + '"')
674 document.body[i : i + 2] = insertion
678 def revert_include(document):
679 'Reverts include insets to old format.'
681 r1 = re.compile('LatexCommand (.+)')
682 r2 = re.compile('filename (.+)')
683 r3 = re.compile('options (.*)')
685 i = find_token(document.body, "\\begin_inset CommandInset include", i)
688 previewline = document.body[i + 1]
689 m = r1.match(document.body[i + 2])
691 document.warning("Malformed LyX document: No LatexCommand line for `" +
692 document.body[i] + "' on line " + str(i) + ".")
696 m = r2.match(document.body[i + 3])
698 document.warning("Malformed LyX document: No filename line for `" + \
699 document.body[i] + "' on line " + str(i) + ".")
705 if (cmd == "lstinputlisting"):
706 m = r3.match(document.body[i + 4])
710 newline = "\\begin_inset Include \\" + cmd + "{" + fn + "}"
712 newline += ("[" + options + "]")
713 insertion = [newline, previewline]
714 document.body[i : i + numlines] = insertion
718 def revert_albanian(document):
719 "Set language Albanian to English"
721 if document.language == "albanian":
722 document.language = "english"
723 i = find_token(document.header, "\\language", 0)
725 document.header[i] = "\\language english"
728 j = find_token(document.body, "\\lang albanian", j)
731 document.body[j] = document.body[j].replace("\\lang albanian", "\\lang english")
735 def revert_lowersorbian(document):
736 "Set language lower Sorbian to English"
738 if document.language == "lowersorbian":
739 document.language = "english"
740 i = find_token(document.header, "\\language", 0)
742 document.header[i] = "\\language english"
745 j = find_token(document.body, "\\lang lowersorbian", j)
748 document.body[j] = document.body[j].replace("\\lang lowersorbian", "\\lang english")
752 def revert_uppersorbian(document):
753 "Set language uppersorbian to usorbian as this was used in LyX 1.5"
755 if document.language == "uppersorbian":
756 document.language = "usorbian"
757 i = find_token(document.header, "\\language", 0)
759 document.header[i] = "\\language usorbian"
762 j = find_token(document.body, "\\lang uppersorbian", j)
765 document.body[j] = document.body[j].replace("\\lang uppersorbian", "\\lang usorbian")
769 def convert_usorbian(document):
770 "Set language usorbian to uppersorbian"
772 if document.language == "usorbian":
773 document.language = "uppersorbian"
774 i = find_token(document.header, "\\language", 0)
776 document.header[i] = "\\language uppersorbian"
779 j = find_token(document.body, "\\lang usorbian", j)
782 document.body[j] = document.body[j].replace("\\lang usorbian", "\\lang uppersorbian")
786 def revert_macro_optional_params(document):
787 "Convert macro definitions with optional parameters into ERTs"
788 # Stub to convert macro definitions with one or more optional parameters
789 # into uninterpreted ERT insets
792 def revert_hyperlinktype(document):
793 'Reverts hyperlink type'
797 i = find_token(document.body, "target", i)
800 j = find_token(document.body, "type", i)
808 def revert_pagebreak(document):
809 'Reverts pagebreak to ERT'
812 i = find_token(document.body, "\\pagebreak", i)
815 document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
816 '\\begin_layout Standard\n\n\n\\backslash\n' \
817 'pagebreak{}\n\\end_layout\n\n\\end_inset\n\n'
821 def revert_linebreak(document):
822 'Reverts linebreak to ERT'
825 i = find_token(document.body, "\\linebreak", i)
828 document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
829 '\\begin_layout Standard\n\n\n\\backslash\n' \
830 'linebreak{}\n\\end_layout\n\n\\end_inset\n\n'
834 def revert_latin(document):
835 "Set language Latin to English"
837 if document.language == "latin":
838 document.language = "english"
839 i = find_token(document.header, "\\language", 0)
841 document.header[i] = "\\language english"
844 j = find_token(document.body, "\\lang latin", j)
847 document.body[j] = document.body[j].replace("\\lang latin", "\\lang english")
851 def revert_samin(document):
852 "Set language North Sami to English"
854 if document.language == "samin":
855 document.language = "english"
856 i = find_token(document.header, "\\language", 0)
858 document.header[i] = "\\language english"
861 j = find_token(document.body, "\\lang samin", j)
864 document.body[j] = document.body[j].replace("\\lang samin", "\\lang english")
868 def convert_serbocroatian(document):
869 "Set language Serbocroatian to Croatian as this was really Croatian in LyX 1.5"
871 if document.language == "serbocroatian":
872 document.language = "croatian"
873 i = find_token(document.header, "\\language", 0)
875 document.header[i] = "\\language croatian"
878 j = find_token(document.body, "\\lang serbocroatian", j)
881 document.body[j] = document.body[j].replace("\\lang serbocroatian", "\\lang croatian")
885 def convert_framed_notes(document):
886 "Convert framed notes to boxes. "
889 i = find_tokens(document.body, ["\\begin_inset Note Framed", "\\begin_inset Note Shaded"], i)
893 document.body[i] = document.body[i].replace("\\begin_inset Note", "\\begin_inset Box")
894 document.body.insert(i + 1, 'position "t"\nhor_pos "c"\nhas_inner_box 0\ninner_pos "t"\n' \
895 'use_parbox 0\nwidth "100col%"\nspecial "none"\nheight "1in"\n' \
896 'height_special "totalheight"')
900 def revert_framed_notes(document):
901 "Revert framed boxes to notes. "
904 i = find_tokens(document.body, ["\\begin_inset Box Framed", "\\begin_inset Box Shaded"], i)
908 j = find_end_of_inset(document.body, i + 1)
911 document.warning("Malformed LyX document: Could not find end of Box inset.")
912 k = find_token(document.body, "status", i + 1, j)
914 document.warning("Malformed LyX document: Missing `status' tag in Box inset.")
916 status = document.body[k]
917 l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
919 document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Box inset.")
921 m = find_token(document.body, "\\end_layout", i + 1, j)
923 document.warning("Malformed LyX document: Missing `\\end_layout' in Box inset.")
925 ibox = find_token(document.body, "has_inner_box 1", i + 1, k)
926 pbox = find_token(document.body, "use_parbox 1", i + 1, k)
927 if ibox == -1 and pbox == -1:
928 document.body[i] = document.body[i].replace("\\begin_inset Box", "\\begin_inset Note")
929 del document.body[i+1:k]
931 document.body[i] = document.body[i].replace("\\begin_inset Box Shaded", "\\begin_inset Box Frameless")
932 document.body.insert(l + 1, "\\begin_inset Note Shaded\n" + status + "\n\\begin_layout Standard\n")
933 document.body.insert(m + 1, "\\end_layout\n\\end_inset")
937 def revert_slash(document):
938 'Revert \\SpecialChar \\slash{} to ERT'
939 for i in range(len(document.body)):
940 document.body[i] = document.body[i].replace('\\SpecialChar \\slash{}', \
941 '\\begin_inset ERT\nstatus collapsed\n\n' \
942 '\\begin_layout Standard\n\n\n\\backslash\n' \
943 'slash{}\n\\end_layout\n\n\\end_inset\n\n')
946 def revert_nobreakdash(document):
947 'Revert \\SpecialChar \\nobreakdash- to ERT'
949 for i in range(len(document.body)):
950 line = document.body[i]
951 r = re.compile(r'\\SpecialChar \\nobreakdash-')
955 document.body[i] = document.body[i].replace('\\SpecialChar \\nobreakdash-', \
956 '\\begin_inset ERT\nstatus collapsed\n\n' \
957 '\\begin_layout Standard\n\n\n\\backslash\n' \
958 'nobreakdash-\n\\end_layout\n\n\\end_inset\n\n')
961 j = find_token(document.header, "\\use_amsmath", 0)
963 document.warning("Malformed LyX document: Missing '\\use_amsmath'.")
965 document.header[j] = "\\use_amsmath 2"
968 def revert_nocite_key(body, start, end):
969 'key "..." -> \nocite{...}'
970 for i in range(start, end):
971 if (body[i][0:5] == 'key "'):
972 body[i] = body[i].replace('key "', "\\backslash\nnocite{")
973 body[i] = body[i].replace('"', "}")
978 def revert_nocite(document):
979 "Revert LatexCommand nocite to ERT"
982 i = find_token(document.body, "\\begin_inset CommandInset citation", i)
986 if (document.body[i] == "LatexCommand nocite"):
987 j = find_end_of_inset(document.body, i + 1)
989 #this should not happen
990 document.warning("End of CommandInset citation not found in revert_nocite!")
991 revert_nocite_key(document.body, i + 1, len(document.body))
993 revert_nocite_key(document.body, i + 1, j)
994 document.body[i-1] = "\\begin_inset ERT"
995 document.body[i] = "status collapsed\n\n" \
996 "\\begin_layout Standard"
997 document.body.insert(j, "\\end_layout\n");
1001 def revert_bahasam(document):
1002 "Set language Bahasa Malaysia to Bahasa Indonesia"
1004 if document.language == "bahasam":
1005 document.language = "bahasa"
1006 i = find_token(document.header, "\\language", 0)
1008 document.header[i] = "\\language bahasa"
1011 j = find_token(document.body, "\\lang bahasam", j)
1014 document.body[j] = document.body[j].replace("\\lang bahasam", "\\lang bahasa")
1018 def revert_interlingua(document):
1019 "Set language Interlingua to English"
1021 if document.language == "interlingua":
1022 document.language = "english"
1023 i = find_token(document.header, "\\language", 0)
1025 document.header[i] = "\\language english"
1028 j = find_token(document.body, "\\lang interlingua", j)
1031 document.body[j] = document.body[j].replace("\\lang interlingua", "\\lang english")
1035 def revert_serbianlatin(document):
1036 "Set language Serbian-Latin to Croatian"
1038 if document.language == "serbian-latin":
1039 document.language = "croatian"
1040 i = find_token(document.header, "\\language", 0)
1042 document.header[i] = "\\language croatian"
1045 j = find_token(document.body, "\\lang serbian-latin", j)
1048 document.body[j] = document.body[j].replace("\\lang serbian-latin", "\\lang croatian")
1056 supported_versions = ["1.6.0","1.6"]
1057 convert = [[277, [fix_wrong_tables]],
1058 [278, [close_begin_deeper]],
1059 [279, [long_charstyle_names]],
1060 [280, [axe_show_label]],
1063 [283, [convert_flex]],
1067 [287, [convert_wrapfig_options]],
1068 [288, [convert_inset_command]],
1069 [289, [convert_latexcommand_index]],
1074 [294, [convert_pdf_options]],
1075 [295, [convert_htmlurl, convert_url]],
1076 [296, [convert_include]],
1077 [297, [convert_usorbian]],
1083 [303, [convert_serbocroatian]],
1084 [304, [convert_framed_notes]],
1092 revert = [[308, [revert_nocite]],
1093 [307, [revert_serbianlatin]],
1094 [306, [revert_slash, revert_nobreakdash]],
1095 [305, [revert_interlingua]],
1096 [304, [revert_bahasam]],
1097 [303, [revert_framed_notes]],
1099 [301, [revert_latin, revert_samin]],
1100 [300, [revert_linebreak]],
1101 [299, [revert_pagebreak]],
1102 [298, [revert_hyperlinktype]],
1103 [297, [revert_macro_optional_params]],
1104 [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]],
1105 [295, [revert_include]],
1106 [294, [revert_href]],
1107 [293, [revert_pdf_options_2]],
1108 [292, [revert_inset_info]],
1109 [291, [revert_japanese, revert_japanese_encoding]],
1110 [290, [revert_vietnamese]],
1111 [289, [revert_wraptable]],
1112 [288, [revert_latexcommand_index]],
1113 [287, [revert_inset_command]],
1114 [286, [revert_wrapfig_options]],
1115 [285, [revert_pdf_options]],
1116 [284, [remove_inzip_options]],
1118 [282, [revert_flex]],
1120 [280, [revert_begin_modules]],
1121 [279, [revert_show_label]],
1122 [278, [revert_long_charstyle_names]],
1128 if __name__ == "__main__":