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')
40 ####################################################################
42 def fix_wrong_tables(document):
45 i = find_token(document.body, "\\begin_inset Tabular", i)
48 j = find_end_of_inset(document.body, i + 1)
50 document.warning("Malformed LyX document: Could not find end of tabular.")
54 nrows = int(document.body[i+1].split('"')[3])
55 ncols = int(document.body[i+1].split('"')[5])
57 for l in range(nrows):
59 for k in range(ncols):
60 m = find_token(document.body, '<cell', m)
62 if document.body[m].find('multicolumn') != -1:
63 multicol_cont = int(document.body[m].split('"')[1])
65 if multicol_cont == 2 and (k == 0 or prev_multicolumn == 0):
66 document.body[m] = document.body[m][:5] + document.body[m][21:]
69 prev_multicolumn = multicol_cont
76 def close_begin_deeper(document):
80 i = find_tokens(document.body, ["\\begin_deeper", "\\end_deeper"], i)
85 if document.body[i][:13] == "\\begin_deeper":
92 document.body[-2:-2] = ['\\end_deeper' for i in range(depth)]
95 def long_charstyle_names(document):
98 i = find_token(document.body, "\\begin_inset CharStyle", i)
101 document.body[i] = document.body[i].replace("CharStyle ", "CharStyle CharStyle:")
104 def revert_long_charstyle_names(document):
107 i = find_token(document.body, "\\begin_inset CharStyle", i)
110 document.body[i] = document.body[i].replace("CharStyle CharStyle:", "CharStyle")
114 def axe_show_label(document):
117 i = find_token(document.body, "\\begin_inset CharStyle", i)
120 if document.body[i + 1].find("show_label") != -1:
121 if document.body[i + 1].find("true") != -1:
122 document.body[i + 1] = "status open"
123 del document.body[ i + 2]
125 if document.body[i + 1].find("false") != -1:
126 document.body[i + 1] = "status collapsed"
127 del document.body[ i + 2]
129 document.warning("Malformed LyX document: show_label neither false nor true.")
131 document.warning("Malformed LyX document: show_label missing in CharStyle.")
136 def revert_show_label(document):
139 i = find_token(document.body, "\\begin_inset CharStyle", i)
142 if document.body[i + 1].find("status open") != -1:
143 document.body.insert(i + 1, "show_label true")
145 if document.body[i + 1].find("status collapsed") != -1:
146 document.body.insert(i + 1, "show_label false")
148 document.warning("Malformed LyX document: no legal status line in CharStyle.")
151 def revert_begin_modules(document):
154 i = find_token(document.header, "\\begin_modules", i)
157 j = find_end_of(document.header, i, "\\begin_modules", "\\end_modules")
159 # this should not happen
161 document.header[i : j + 1] = []
163 def convert_flex(document):
164 "Convert CharStyle to Flex"
167 i = find_token(document.body, "\\begin_inset CharStyle", i)
170 document.body[i] = document.body[i].replace('\\begin_inset CharStyle', '\\begin_inset Flex')
172 def revert_flex(document):
173 "Convert Flex to CharStyle"
176 i = find_token(document.body, "\\begin_inset Flex", i)
179 document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
182 # Discard PDF options for hyperref
183 def revert_pdf_options(document):
184 "Revert PDF options for hyperref."
186 i = find_token(document.header, "\\use_hyperref", i)
188 del document.header[i]
189 i = find_token(document.header, "\\pdf_store_options", i)
191 del document.header[i]
192 i = find_token(document.header, "\\pdf_title", 0)
194 del document.header[i]
195 i = find_token(document.header, "\\pdf_author", 0)
197 del document.header[i]
198 i = find_token(document.header, "\\pdf_subject", 0)
200 del document.header[i]
201 i = find_token(document.header, "\\pdf_keywords", 0)
203 del document.header[i]
204 i = find_token(document.header, "\\pdf_bookmarks", 0)
206 del document.header[i]
207 i = find_token(document.header, "\\pdf_bookmarksnumbered", i)
209 del document.header[i]
210 i = find_token(document.header, "\\pdf_bookmarksopen", i)
212 del document.header[i]
213 i = find_token(document.header, "\\pdf_bookmarksopenlevel", i)
215 del document.header[i]
216 i = find_token(document.header, "\\pdf_breaklinks", i)
218 del document.header[i]
219 i = find_token(document.header, "\\pdf_pdfborder", i)
221 del document.header[i]
222 i = find_token(document.header, "\\pdf_colorlinks", i)
224 del document.header[i]
225 i = find_token(document.header, "\\pdf_backref", i)
227 del document.header[i]
228 i = find_token(document.header, "\\pdf_pagebackref", i)
230 del document.header[i]
231 i = find_token(document.header, "\\pdf_pagemode", 0)
233 del document.header[i]
234 i = find_token(document.header, "\\pdf_quoted_options", 0)
236 del document.header[i]
239 def remove_inzip_options(document):
240 "Remove inzipName and embed options from the Graphics inset"
243 i = find_token(document.body, "\\begin_inset Graphics", i)
246 j = find_end_of_inset(document.body, i + 1)
249 document.warning("Malformed LyX document: Could not find end of graphics inset.")
250 # If there's a inzip param, just remove that
251 k = find_token(document.body, "\tinzipName", i + 1, j)
254 # embed option must follow the inzipName option
255 del document.body[k+1]
259 def convert_inset_command(document):
262 \begin_inset LatexCommand cmd
264 \begin_inset CommandInset InsetType
269 i = find_token(document.body, "\\begin_inset LatexCommand", i)
272 line = document.body[i]
273 r = re.compile(r'\\begin_inset LatexCommand (.*)$')
277 #this is adapted from factory.cpp
278 if cmdName[0:4].lower() == "cite":
279 insetName = "citation"
280 elif cmdName == "url" or cmdName == "htmlurl":
282 elif cmdName[-3:] == "ref":
284 elif cmdName == "tableofcontents":
286 elif cmdName == "printnomenclature":
287 insetName = "nomencl_print"
288 elif cmdName == "printindex":
289 insetName = "index_print"
292 insertion = ["\\begin_inset CommandInset " + insetName, "LatexCommand " + cmdName]
293 document.body[i : i+1] = insertion
296 def revert_inset_command(document):
299 \begin_inset CommandInset InsetType
302 \begin_inset LatexCommand cmd
303 Some insets may end up being converted to insets earlier versions of LyX
304 will not be able to recognize. Not sure what to do about that.
308 i = find_token(document.body, "\\begin_inset CommandInset", i)
311 nextline = document.body[i+1]
312 r = re.compile(r'LatexCommand\s+(.*)$')
313 m = r.match(nextline)
315 document.warning("Malformed LyX document: Missing LatexCommand in " + document.body[i] + ".")
318 insertion = ["\\begin_inset LatexCommand " + cmdName]
319 document.body[i : i+2] = insertion
322 def convert_wrapfig_options(document):
323 "Convert optional options for wrap floats (wrapfig)."
324 # adds the tokens "lines", "placement", and "overhang"
327 i = find_token(document.body, "\\begin_inset Wrap figure", i)
330 document.body.insert(i + 1, "lines 0")
331 j = find_token(document.body, "placement", i)
332 # placement can be already set or not; if not, set it
334 document.body.insert(i + 3, "overhang 0col%")
336 document.body.insert(i + 2, "placement o")
337 document.body.insert(i + 3, "overhang 0col%")
341 def revert_wrapfig_options(document):
342 "Revert optional options for wrap floats (wrapfig)."
345 i = find_token(document.body, "lines", i)
348 j = find_token(document.body, "overhang", i+1)
349 if j != i + 2 and j != -1:
350 document.warning("Malformed LyX document: Couldn't find overhang parameter of wrap float.")
354 del document.body[j-1]
358 def convert_latexcommand_index(document):
359 "Convert from LatexCommand form to collapsable form."
362 i = find_token(document.body, "\\begin_inset CommandInset index", i)
365 if document.body[i + 1] != "LatexCommand index": # Might also be index_print
367 fullcontent = document.body[i + 2][6:].strip('"')
368 document.body[i:i + 2] = ["\\begin_inset Index",
370 "\\begin_layout Standard"]
371 # Put here the conversions needed from LaTeX string to LyXText.
372 # Here we do a minimal conversion to prevent crashes and data loss.
373 # Manual patch-up may be needed.
374 # Umlauted characters (most common ones, can be extended):
375 fullcontent = fullcontent.replace(r'\\\"a', u'ä').replace(r'\\\"o', u'ö').replace(r'\\\"u', u'ü')
377 fullcontent = wrap_into_ert(fullcontent, r'\"', '"')
378 #fullcontent = fullcontent.replace(r'\"', '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout standard\n"\n\\end_layout\n\\end_inset\n')
380 r = re.compile('^(.*?)(\$.*?\$)(.*)')
385 f = m.group(2).replace('\\\\', '\\')
389 s = wrap_into_ert(s, r'\\', '\\backslash')
390 s = wrap_into_ert(s, '{', '{')
391 s = wrap_into_ert(s, '}', '}')
392 document.body.insert(i + 3, s)
394 document.body.insert(i + 3, "\\begin_inset Formula " + f)
395 document.body.insert(i + 4, "\\end_inset")
397 # Generic, \\ -> \backslash:
398 g = wrap_into_ert(g, r'\\', '\\backslash{}')
399 g = wrap_into_ert(g, '{', '{')
400 g = wrap_into_ert(g, '}', '}')
401 document.body.insert(i + 3, g)
402 document.body[i + 4] = "\\end_layout"
406 def revert_latexcommand_index(document):
407 "Revert from collapsable form to LatexCommand form."
410 i = find_token(document.body, "\\begin_inset Index", i)
413 j = find_end_of_inset(document.body, i + 1)
416 del document.body[j - 1]
417 del document.body[j - 2] # \end_layout
418 document.body[i] = "\\begin_inset CommandInset index"
419 document.body[i + 1] = "LatexCommand index"
420 # clean up multiline stuff
422 for k in range(i + 3, j - 2):
423 line = document.body[k]
424 if line.startswith("\\begin_inset ERT"):
426 if line.startswith("\\begin_inset Formula"):
428 if line.startswith("\\begin_layout Standard"):
430 if line.startswith("\\end_layout"):
432 if line.startswith("\\end_inset"):
434 if line.startswith("status collapsed"):
436 content = content + line;
437 document.body[i + 3] = "name " + '"' + content + '"'
438 for k in range(i + 4, j - 2):
439 del document.body[i + 4]
440 document.body.insert(i + 4, "")
441 del document.body[i + 2] # \begin_layout standard
445 def revert_wraptable(document):
446 "Revert wrap table to wrap figure."
449 i = find_token(document.body, "\\begin_inset Wrap table", i)
452 document.body[i] = document.body[i].replace('\\begin_inset Wrap table', '\\begin_inset Wrap figure')
456 def revert_vietnamese(document):
457 "Set language Vietnamese to English"
458 # Set document language from Vietnamese to English
460 if document.language == "vietnamese":
461 document.language = "english"
462 i = find_token(document.header, "\\language", 0)
464 document.header[i] = "\\language english"
467 j = find_token(document.body, "\\lang vietnamese", j)
470 document.body[j] = document.body[j].replace("\\lang vietnamese", "\\lang english")
474 def revert_japanese(document):
475 "Set language japanese-plain to japanese"
476 # Set document language from japanese-plain to japanese
478 if document.language == "japanese-plain":
479 document.language = "japanese"
480 i = find_token(document.header, "\\language", 0)
482 document.header[i] = "\\language japanese"
485 j = find_token(document.body, "\\lang japanese-plain", j)
488 document.body[j] = document.body[j].replace("\\lang japanese-plain", "\\lang japanese")
492 def revert_japanese_encoding(document):
493 "Set input encoding form EUC-JP-plain to EUC-JP etc."
494 # Set input encoding form EUC-JP-plain to EUC-JP etc.
496 i = find_token(document.header, "\\inputencoding EUC-JP-plain", 0)
498 document.header[i] = "\\inputencoding EUC-JP"
500 j = find_token(document.header, "\\inputencoding JIS-plain", 0)
502 document.header[j] = "\\inputencoding JIS"
504 k = find_token(document.header, "\\inputencoding SJIS-plain", 0)
505 if k != -1: # convert to UTF8 since there is currently no SJIS encoding
506 document.header[k] = "\\inputencoding UTF8"
509 def revert_inset_info(document):
510 'Replace info inset with its content'
513 i = find_token(document.body, '\\begin_inset Info', i)
516 j = find_end_of_inset(document.body, i + 1)
519 document.warning("Malformed LyX document: Could not find end of Info inset.")
522 for k in range(i, j+1):
523 if document.body[k].startswith("arg"):
524 arg = document.body[k][3:].strip().strip('"')
525 if document.body[k].startswith("type"):
526 type = document.body[k][4:].strip().strip('"')
527 # I think there is a newline after \\end_inset, which should be removed.
528 if document.body[j + 1].strip() == "":
529 document.body[i : (j + 2)] = [type + ':' + arg]
531 document.body[i : (j + 1)] = [type + ':' + arg]
534 def convert_pdf_options(document):
535 # Set the pdfusetitle tag, delete the pdf_store_options,
536 # set quotes for bookmarksopenlevel"
537 has_hr = get_value(document.header, "\\use_hyperref", 0, default = "0")
539 k = find_token(document.header, "\\use_hyperref", 0)
540 document.header.insert(k + 1, "\\pdf_pdfusetitle true")
541 k = find_token(document.header, "\\pdf_store_options", 0)
543 del document.header[k]
544 i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
546 document.header[i] = document.header[i].replace('"', '')
549 def revert_pdf_options_2(document):
550 # reset the pdfusetitle tag, set quotes for bookmarksopenlevel"
551 k = find_token(document.header, "\\use_hyperref", 0)
552 i = find_token(document.header, "\\pdf_pdfusetitle", k)
554 del document.header[i]
555 i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
557 values = document.header[i].split()
558 values[1] = ' "' + values[1] + '"'
559 document.header[i] = ''.join(values)
562 def convert_htmlurl(document):
563 'Convert "htmlurl" to "href" insets for docbook'
564 if document.backend != "docbook":
568 i = find_token(document.body, "\\begin_inset CommandInset url", i)
571 document.body[i] = "\\begin_inset CommandInset href"
572 document.body[i + 1] = "LatexCommand href"
576 def convert_url(document):
577 'Convert url insets to url charstyles'
578 if document.backend == "docbook":
582 i = find_token(document.body, "\\begin_inset CommandInset url", i)
585 n = find_token(document.body, "name", i)
587 # place the URL name in typewriter before the new URL insert
588 # grab the name 'bla' from the e.g. the line 'name "bla"',
589 # therefore start with the 6th character
590 name = document.body[n][6:-1]
591 newname = [name + " "]
592 document.body[i:i] = newname
594 j = find_token(document.body, "target", i)
596 document.warning("Malformed LyX document: Can't find target for url inset")
599 target = document.body[j][8:-1]
600 k = find_token(document.body, "\\end_inset", j)
602 document.warning("Malformed LyX document: Can't find end of url inset")
605 newstuff = ["\\begin_inset Flex URL",
606 "status collapsed", "",
607 "\\begin_layout Standard",
612 document.body[i:k] = newstuff
616 def revert_href(document):
617 'Reverts hyperlink insets (href) to url insets (url)'
620 i = find_token(document.body, "\\begin_inset CommandInset href", i)
623 document.body[i : i + 2] = \
624 ["\\begin_inset CommandInset url", "LatexCommand url"]
628 def convert_include(document):
629 'Converts include insets to new format.'
631 r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
633 i = find_token(document.body, "\\begin_inset Include", i)
636 line = document.body[i]
637 previewline = document.body[i + 1]
640 document.warning("Unable to match line " + str(i) + " of body!")
646 insertion = ["\\begin_inset CommandInset include",
647 "LatexCommand " + cmd, previewline,
648 "filename \"" + fn + "\""]
651 insertion.append("lstparams " + '"' + opt + '"')
653 document.body[i : i + 2] = insertion
657 def revert_include(document):
658 'Reverts include insets to old format.'
660 r1 = re.compile('LatexCommand (.+)')
661 r2 = re.compile('filename (.+)')
662 r3 = re.compile('options (.*)')
664 i = find_token(document.body, "\\begin_inset CommandInset include", i)
667 previewline = document.body[i + 1]
668 m = r1.match(document.body[i + 2])
670 document.warning("Malformed LyX document: No LatexCommand line for `" +
671 document.body[i] + "' on line " + str(i) + ".")
675 m = r2.match(document.body[i + 3])
677 document.warning("Malformed LyX document: No filename line for `" + \
678 document.body[i] + "' on line " + str(i) + ".")
684 if (cmd == "lstinputlisting"):
685 m = r3.match(document.body[i + 4])
689 newline = "\\begin_inset Include \\" + cmd + "{" + fn + "}"
691 newline += ("[" + options + "]")
692 insertion = [newline, previewline]
693 document.body[i : i + numlines] = insertion
697 def revert_albanian(document):
698 "Set language Albanian to English"
700 if document.language == "albanian":
701 document.language = "english"
702 i = find_token(document.header, "\\language", 0)
704 document.header[i] = "\\language english"
707 j = find_token(document.body, "\\lang albanian", j)
710 document.body[j] = document.body[j].replace("\\lang albanian", "\\lang english")
714 def revert_lowersorbian(document):
715 "Set language lower Sorbian to English"
717 if document.language == "lowersorbian":
718 document.language = "english"
719 i = find_token(document.header, "\\language", 0)
721 document.header[i] = "\\language english"
724 j = find_token(document.body, "\\lang lowersorbian", j)
727 document.body[j] = document.body[j].replace("\\lang lowersorbian", "\\lang english")
731 def revert_uppersorbian(document):
732 "Set language uppersorbian to usorbian as this was used in LyX 1.5"
734 if document.language == "uppersorbian":
735 document.language = "usorbian"
736 i = find_token(document.header, "\\language", 0)
738 document.header[i] = "\\language usorbian"
741 j = find_token(document.body, "\\lang uppersorbian", j)
744 document.body[j] = document.body[j].replace("\\lang uppersorbian", "\\lang usorbian")
748 def convert_usorbian(document):
749 "Set language usorbian to uppersorbian"
751 if document.language == "usorbian":
752 document.language = "uppersorbian"
753 i = find_token(document.header, "\\language", 0)
755 document.header[i] = "\\language uppersorbian"
758 j = find_token(document.body, "\\lang usorbian", j)
761 document.body[j] = document.body[j].replace("\\lang usorbian", "\\lang uppersorbian")
765 def revert_macro_optional_params(document):
766 "Convert macro definitions with optional parameters into ERTs"
767 # Stub to convert macro definitions with one or more optional parameters
768 # into uninterpreted ERT insets
771 def revert_hyperlinktype(document):
772 'Reverts hyperlink type'
776 i = find_token(document.body, "target", i)
779 j = find_token(document.body, "type", i)
787 def revert_pagebreak(document):
788 'Reverts pagebreak to ERT'
791 i = find_token(document.body, "\\pagebreak", i)
794 document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
795 '\\begin_layout Standard\n\n\n\\backslash\n' \
796 'pagebreak{}\n\\end_layout\n\n\\end_inset\n\n'
800 def revert_linebreak(document):
801 'Reverts linebreak to ERT'
804 i = find_token(document.body, "\\linebreak", i)
807 document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
808 '\\begin_layout Standard\n\n\n\\backslash\n' \
809 'linebreak{}\n\\end_layout\n\n\\end_inset\n\n'
813 def revert_latin(document):
814 "Set language Latin to English"
816 if document.language == "latin":
817 document.language = "english"
818 i = find_token(document.header, "\\language", 0)
820 document.header[i] = "\\language english"
823 j = find_token(document.body, "\\lang latin", j)
826 document.body[j] = document.body[j].replace("\\lang latin", "\\lang english")
830 def revert_samin(document):
831 "Set language North Sami to English"
833 if document.language == "samin":
834 document.language = "english"
835 i = find_token(document.header, "\\language", 0)
837 document.header[i] = "\\language english"
840 j = find_token(document.body, "\\lang samin", j)
843 document.body[j] = document.body[j].replace("\\lang samin", "\\lang english")
847 def convert_serbocroatian(document):
848 "Set language Serbocroatian to Croatian as this was really Croatian in LyX 1.5"
850 if document.language == "serbocroatian":
851 document.language = "croatian"
852 i = find_token(document.header, "\\language", 0)
854 document.header[i] = "\\language croatian"
857 j = find_token(document.body, "\\lang serbocroatian", j)
860 document.body[j] = document.body[j].replace("\\lang serbocroatian", "\\lang croatian")
864 def convert_framed_notes(document):
865 "Convert framed notes to boxes. "
868 i = find_tokens(document.body, ["\\begin_inset Note Framed", "\\begin_inset Note Shaded"], i)
872 document.body[i] = document.body[i].replace("\\begin_inset Note", "\\begin_inset Box")
873 document.body.insert(i + 1, 'position "t"\nhor_pos "c"\nhas_inner_box 0\ninner_pos "t"\n' \
874 'use_parbox 0\nwidth "100col%"\nspecial "none"\nheight "1in"\n' \
875 'height_special "totalheight"')
879 def revert_framed_notes(document):
880 "Revert framed boxes to notes. "
883 i = find_tokens(document.body, ["\\begin_inset Box Framed", "\\begin_inset Box Shaded"], i)
887 j = find_end_of_inset(document.body, i + 1)
890 document.warning("Malformed LyX document: Could not find end of Box inset.")
891 k = find_token(document.body, "status", i + 1, j)
893 document.warning("Malformed LyX document: Missing `status' tag in Box inset.")
895 status = document.body[k]
896 l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
898 document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Box inset.")
900 m = find_token(document.body, "\\end_layout", i + 1, j)
902 document.warning("Malformed LyX document: Missing `\\end_layout' in Box inset.")
904 ibox = find_token(document.body, "has_inner_box 1", i + 1, k)
905 pbox = find_token(document.body, "use_parbox 1", i + 1, k)
906 if ibox == -1 and pbox == -1:
907 document.body[i] = document.body[i].replace("\\begin_inset Box", "\\begin_inset Note")
908 del document.body[i+1:k]
910 document.body[i] = document.body[i].replace("\\begin_inset Box Shaded", "\\begin_inset Box Frameless")
911 document.body.insert(l + 1, "\\begin_inset Note Shaded\n" + status + "\n\\begin_layout Standard\n")
912 document.body.insert(m + 1, "\\end_layout\n\\end_inset")
916 def revert_slash(document):
917 'Revert \\SpecialChar \\slash{} to ERT'
918 for i in range(len(document.body)):
919 document.body[i] = document.body[i].replace('\\SpecialChar \\slash{}', \
920 '\\begin_inset ERT\nstatus collapsed\n\n' \
921 '\\begin_layout Standard\n\n\n\\backslash\n' \
922 'slash{}\n\\end_layout\n\n\\end_inset\n\n')
925 def revert_nobreakdash(document):
926 'Revert \\SpecialChar \\nobreakdash- to ERT'
928 for i in range(len(document.body)):
929 line = document.body[i]
930 r = re.compile(r'\\SpecialChar \\nobreakdash-')
934 document.body[i] = document.body[i].replace('\\SpecialChar \\nobreakdash-', \
935 '\\begin_inset ERT\nstatus collapsed\n\n' \
936 '\\begin_layout Standard\n\n\n\\backslash\n' \
937 'nobreakdash-\n\\end_layout\n\n\\end_inset\n\n')
940 j = find_token(document.header, "\\use_amsmath", 0)
942 document.warning("Malformed LyX document: Missing '\\use_amsmath'.")
944 document.header[j] = "\\use_amsmath 2"
947 def revert_bahasam(document):
948 "Set language Bahasa Malaysia to Bahasa Indonesia"
950 if document.language == "bahasam":
951 document.language = "bahasa"
952 i = find_token(document.header, "\\language", 0)
954 document.header[i] = "\\language bahasa"
957 j = find_token(document.body, "\\lang bahasam", j)
960 document.body[j] = document.body[j].replace("\\lang bahasam", "\\lang bahasa")
964 def revert_interlingua(document):
965 "Set language Interlingua to English"
967 if document.language == "interlingua":
968 document.language = "english"
969 i = find_token(document.header, "\\language", 0)
971 document.header[i] = "\\language english"
974 j = find_token(document.body, "\\lang interlingua", j)
977 document.body[j] = document.body[j].replace("\\lang interlingua", "\\lang english")
985 supported_versions = ["1.6.0","1.6"]
986 convert = [[277, [fix_wrong_tables]],
987 [278, [close_begin_deeper]],
988 [279, [long_charstyle_names]],
989 [280, [axe_show_label]],
992 [283, [convert_flex]],
996 [287, [convert_wrapfig_options]],
997 [288, [convert_inset_command]],
998 [289, [convert_latexcommand_index]],
1003 [294, [convert_pdf_options]],
1004 [295, [convert_htmlurl, convert_url]],
1005 [296, [convert_include]],
1006 [297, [convert_usorbian]],
1012 [303, [convert_serbocroatian]],
1013 [304, [convert_framed_notes]],
1019 revert = [[306, [revert_slash, revert_nobreakdash]],
1020 [305, [revert_interlingua]],
1021 [304, [revert_bahasam]],
1022 [303, [revert_framed_notes]],
1024 [301, [revert_latin, revert_samin]],
1025 [300, [revert_linebreak]],
1026 [299, [revert_pagebreak]],
1027 [298, [revert_hyperlinktype]],
1028 [297, [revert_macro_optional_params]],
1029 [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]],
1030 [295, [revert_include]],
1031 [294, [revert_href]],
1032 [293, [revert_pdf_options_2]],
1033 [292, [revert_inset_info]],
1034 [291, [revert_japanese, revert_japanese_encoding]],
1035 [290, [revert_vietnamese]],
1036 [289, [revert_wraptable]],
1037 [288, [revert_latexcommand_index]],
1038 [287, [revert_inset_command]],
1039 [286, [revert_wrapfig_options]],
1040 [285, [revert_pdf_options]],
1041 [284, [remove_inzip_options]],
1043 [282, [revert_flex]],
1045 [280, [revert_begin_modules]],
1046 [279, [revert_show_label]],
1047 [278, [revert_long_charstyle_names]],
1053 if __name__ == "__main__":