1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2008 The LyX Team <lyx-devel@lists.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, get_value_string
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")
36 # document.body[i] = wrap_insert_ert(...)
37 # wrap_into_ert may returns a multiline string, which should NOT appear
38 # in document.body. Insetad, do something like this:
39 # subst = wrap_inset_ert(...)
40 # subst = subst.split('\n')
41 # document.body[i:i+1] = subst
43 # where the last statement resets the counter to accord with the added
45 def wrap_into_ert(string, src, dst):
46 " Wrap a something into an ERT"
47 return string.replace(src, '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n'
48 + dst + '\n\\end_layout\n\\end_inset\n')
50 def add_to_preamble(document, text):
51 """ Add text to the preamble if it is not already there.
52 Only the first line is checked!"""
54 if find_token(document.preamble, text[0], 0) != -1:
57 document.preamble.extend(text)
59 # Convert a LyX length into a LaTeX length
61 units = {"text%":"\\backslash\ntextwidth", "col%":"\\backslash\ncolumnwidth",
62 "page%":"\\backslash\npagewidth", "line%":"\\backslash\nlinewidth",
63 "theight%":"\\backslash\ntextheight", "pheight%":"\\backslash\npageheight"}
65 # Convert LyX units to LaTeX units
66 for unit in units.keys():
67 if len.find(unit) != -1:
68 len = '%f' % (len2value(len) / 100)
69 len = len.strip('0') + units[unit]
74 # Return the value of len without the unit in numerical form.
76 result = re.search('([+-]?[0-9.]+)', len)
78 return float(result.group(1))
82 # Unfortunately, this doesn't really work, since Standard isn't always default.
83 # But it's as good as we can do right now.
84 def find_default_layout(document, start, end):
85 l = find_token(document.body, "\\begin_layout Standard", start, end)
87 l = find_token(document.body, "\\begin_layout PlainLayout", start, end)
89 l = find_token(document.body, "\\begin_layout Plain Layout", start, end)
92 def get_option(document, m, option, default):
93 l = document.body[m].find(option)
96 val = document.body[m][l:].split('"')[1]
99 def remove_option(document, m, option):
100 l = document.body[m].find(option)
102 val = document.body[m][l:].split('"')[1]
103 document.body[m] = document.body[m][:l-1] + document.body[m][l+len(option + '="' + val + '"'):]
106 def set_option(document, m, option, value):
107 l = document.body[m].find(option)
109 oldval = document.body[m][l:].split('"')[1]
110 l = l + len(option + '="')
111 document.body[m] = document.body[m][:l] + value + document.body[m][l+len(oldval):]
113 document.body[m] = document.body[m][:-1] + ' ' + option + '="' + value + '">'
117 ####################################################################
119 def convert_ltcaption(document):
122 i = find_token(document.body, "\\begin_inset Tabular", i)
125 j = find_end_of_inset(document.body, i + 1)
127 document.warning("Malformed LyX document: Could not find end of tabular.")
130 nrows = int(document.body[i+1].split('"')[3])
131 ncols = int(document.body[i+1].split('"')[5])
134 for k in range(nrows):
135 m = find_token(document.body, "<row", m)
138 for k in range(ncols):
139 m = find_token(document.body, "<cell", m)
141 mend = find_token(document.body, "</cell>", m + 1)
142 # first look for caption insets
143 mcap = find_token(document.body, "\\begin_inset Caption", m + 1, mend)
144 # then look for ERT captions
146 mcap = find_token(document.body, "caption", m + 1, mend)
148 mcap = find_token(document.body, "\\backslash", mcap - 1, mcap)
151 if caption == 'true':
153 set_option(document, r, 'caption', 'true')
154 set_option(document, m, 'multicolumn', '1')
155 set_option(document, m, 'bottomline', 'false')
156 set_option(document, m, 'topline', 'false')
157 set_option(document, m, 'rightline', 'false')
158 set_option(document, m, 'leftline', 'false')
159 #j = find_end_of_inset(document.body, j + 1)
161 set_option(document, m, 'multicolumn', '2')
168 #FIXME Use of wrap_into_ert can confuse lyx2lyx
169 def revert_ltcaption(document):
172 i = find_token(document.body, "\\begin_inset Tabular", i)
175 j = find_end_of_inset(document.body, i + 1)
177 document.warning("Malformed LyX document: Could not find end of tabular.")
181 nrows = int(document.body[i+1].split('"')[3])
182 ncols = int(document.body[i+1].split('"')[5])
184 for k in range(nrows):
185 m = find_token(document.body, "<row", m)
186 caption = get_option(document, m, 'caption', 'false')
187 if caption == 'true':
188 remove_option(document, m, 'caption')
189 for k in range(ncols):
190 m = find_token(document.body, "<cell", m)
191 remove_option(document, m, 'multicolumn')
193 m = find_token(document.body, "\\begin_inset Caption", m)
196 m = find_end_of_inset(document.body, m + 1)
197 document.body[m] += wrap_into_ert("","","\\backslash\n\\backslash\n%")
203 def convert_tablines(document):
206 i = find_token(document.body, "\\begin_inset Tabular", i)
208 # LyX 1.3 inserted an extra space between \begin_inset
209 # and Tabular so let us try if this is the case and fix it.
210 i = find_token(document.body, "\\begin_inset Tabular", i)
214 document.body[i] = "\\begin_inset Tabular"
215 j = find_end_of_inset(document.body, i + 1)
217 document.warning("Malformed LyX document: Could not find end of tabular.")
221 nrows = int(document.body[i+1].split('"')[3])
222 ncols = int(document.body[i+1].split('"')[5])
225 for k in range(ncols):
226 m = find_token(document.body, "<column", m)
227 left = get_option(document, m, 'leftline', 'false')
228 right = get_option(document, m, 'rightline', 'false')
229 col_info.append([left, right])
230 remove_option(document, m, 'leftline')
231 remove_option(document, m, 'rightline')
235 for k in range(nrows):
236 m = find_token(document.body, "<row", m)
237 top = get_option(document, m, 'topline', 'false')
238 bottom = get_option(document, m, 'bottomline', 'false')
239 row_info.append([top, bottom])
240 remove_option(document, m, 'topline')
241 remove_option(document, m, 'bottomline')
246 for k in range(nrows*ncols):
247 m = find_token(document.body, "<cell", m)
248 mc_info.append(get_option(document, m, 'multicolumn', '0'))
251 for l in range(nrows):
252 for k in range(ncols):
253 m = find_token(document.body, '<cell', m)
254 if mc_info[l*ncols + k] == '0':
255 r = set_option(document, m, 'topline', row_info[l][0])
256 r = set_option(document, m, 'bottomline', row_info[l][1])
257 r = set_option(document, m, 'leftline', col_info[k][0])
258 r = set_option(document, m, 'rightline', col_info[k][1])
259 elif mc_info[l*ncols + k] == '1':
261 while s < ncols and mc_info[l*ncols + s] == '2':
263 if s < ncols and mc_info[l*ncols + s] != '1':
264 r = set_option(document, m, 'rightline', col_info[k][1])
265 if k > 0 and mc_info[l*ncols + k - 1] == '0':
266 r = set_option(document, m, 'leftline', col_info[k][0])
271 def revert_tablines(document):
274 i = find_token(document.body, "\\begin_inset Tabular", i)
277 j = find_end_of_inset(document.body, i + 1)
279 document.warning("Malformed LyX document: Could not find end of tabular.")
283 nrows = int(document.body[i+1].split('"')[3])
284 ncols = int(document.body[i+1].split('"')[5])
287 for k in range(nrows*ncols):
288 m = find_token(document.body, "<cell", m)
289 top = get_option(document, m, 'topline', 'false')
290 bottom = get_option(document, m, 'bottomline', 'false')
291 left = get_option(document, m, 'leftline', 'false')
292 right = get_option(document, m, 'rightline', 'false')
293 lines.append([top, bottom, left, right])
296 # we will want to ignore longtable captions
299 for k in range(nrows):
300 m = find_token(document.body, "<row", m)
301 caption = get_option(document, m, 'caption', 'false')
302 caption_info.append([caption])
307 for k in range(ncols):
308 m = find_token(document.body, "<column", m)
310 for l in range(nrows):
311 left = lines[l*ncols + k][2]
312 if left == 'false' and caption_info[l] == 'false':
314 set_option(document, m, 'leftline', left)
316 for l in range(nrows):
317 right = lines[l*ncols + k][3]
318 if right == 'false' and caption_info[l] == 'false':
320 set_option(document, m, 'rightline', right)
324 for k in range(nrows):
325 m = find_token(document.body, "<row", m)
327 for l in range(ncols):
328 top = lines[k*ncols + l][0]
331 if caption_info[k] == 'false':
333 set_option(document, m, 'topline', top)
335 for l in range(ncols):
336 bottom = lines[k*ncols + l][1]
337 if bottom == 'false':
339 if caption_info[k] == 'false':
341 set_option(document, m, 'bottomline', bottom)
347 def fix_wrong_tables(document):
350 i = find_token(document.body, "\\begin_inset Tabular", i)
353 j = find_end_of_inset(document.body, i + 1)
355 document.warning("Malformed LyX document: Could not find end of tabular.")
359 nrows = int(document.body[i+1].split('"')[3])
360 ncols = int(document.body[i+1].split('"')[5])
362 for l in range(nrows):
364 for k in range(ncols):
365 m = find_token(document.body, '<cell', m)
367 if document.body[m].find('multicolumn') != -1:
368 multicol_cont = int(document.body[m].split('"')[1])
370 if multicol_cont == 2 and (k == 0 or prev_multicolumn == 0):
371 document.body[m] = document.body[m][:5] + document.body[m][21:]
374 prev_multicolumn = multicol_cont
381 def close_begin_deeper(document):
385 i = find_tokens(document.body, ["\\begin_deeper", "\\end_deeper"], i)
390 if document.body[i][:13] == "\\begin_deeper":
397 document.body[-2:-2] = ['\\end_deeper' for i in range(depth)]
400 def long_charstyle_names(document):
403 i = find_token(document.body, "\\begin_inset CharStyle", i)
406 document.body[i] = document.body[i].replace("CharStyle ", "CharStyle CharStyle:")
409 def revert_long_charstyle_names(document):
412 i = find_token(document.body, "\\begin_inset CharStyle", i)
415 document.body[i] = document.body[i].replace("CharStyle CharStyle:", "CharStyle")
419 def axe_show_label(document):
422 i = find_token(document.body, "\\begin_inset CharStyle", i)
425 if document.body[i + 1].find("show_label") != -1:
426 if document.body[i + 1].find("true") != -1:
427 document.body[i + 1] = "status open"
428 del document.body[ i + 2]
430 if document.body[i + 1].find("false") != -1:
431 document.body[i + 1] = "status collapsed"
432 del document.body[ i + 2]
434 document.warning("Malformed LyX document: show_label neither false nor true.")
436 document.warning("Malformed LyX document: show_label missing in CharStyle.")
441 def revert_show_label(document):
444 i = find_token(document.body, "\\begin_inset CharStyle", i)
447 if document.body[i + 1].find("status open") != -1:
448 document.body.insert(i + 1, "show_label true")
450 if document.body[i + 1].find("status collapsed") != -1:
451 document.body.insert(i + 1, "show_label false")
453 document.warning("Malformed LyX document: no legal status line in CharStyle.")
456 def revert_begin_modules(document):
459 i = find_token(document.header, "\\begin_modules", i)
462 j = find_end_of(document.header, i, "\\begin_modules", "\\end_modules")
464 # this should not happen
466 document.header[i : j + 1] = []
468 def convert_flex(document):
469 "Convert CharStyle to Flex"
472 i = find_token(document.body, "\\begin_inset CharStyle", i)
475 document.body[i] = document.body[i].replace('\\begin_inset CharStyle', '\\begin_inset Flex')
477 def revert_flex(document):
478 "Convert Flex to CharStyle"
481 i = find_token(document.body, "\\begin_inset Flex", i)
484 document.body[i] = document.body[i].replace('\\begin_inset Flex', '\\begin_inset CharStyle')
487 # Discard PDF options for hyperref
488 def revert_pdf_options(document):
489 "Revert PDF options for hyperref."
490 # store the PDF options and delete the entries from the Lyx file
498 bookmarksnumbered = ""
500 bookmarksopenlevel = ""
508 i = find_token(document.header, "\\use_hyperref", i)
510 hyperref = get_value(document.header, "\\use_hyperref", i) == 'true'
511 del document.header[i]
512 i = find_token(document.header, "\\pdf_store_options", i)
514 del document.header[i]
515 i = find_token(document.header, "\\pdf_title", 0)
517 title = get_value_string(document.header, '\\pdf_title', 0, 0, True)
518 title = ' pdftitle={' + title + '}'
519 del document.header[i]
520 i = find_token(document.header, "\\pdf_author", 0)
522 author = get_value_string(document.header, '\\pdf_author', 0, 0, True)
524 author = ' pdfauthor={' + author + '}'
526 author = ',\n pdfauthor={' + author + '}'
527 del document.header[i]
528 i = find_token(document.header, "\\pdf_subject", 0)
530 subject = get_value_string(document.header, '\\pdf_subject', 0, 0, True)
531 if title == "" and author == "":
532 subject = ' pdfsubject={' + subject + '}'
534 subject = ',\n pdfsubject={' + subject + '}'
535 del document.header[i]
536 i = find_token(document.header, "\\pdf_keywords", 0)
538 keywords = get_value_string(document.header, '\\pdf_keywords', 0, 0, True)
539 if title == "" and author == "" and subject == "":
540 keywords = ' pdfkeywords={' + keywords + '}'
542 keywords = ',\n pdfkeywords={' + keywords + '}'
543 del document.header[i]
544 i = find_token(document.header, "\\pdf_bookmarks", 0)
546 bookmarks = get_value_string(document.header, '\\pdf_bookmarks', 0)
547 bookmarks = ',\n bookmarks=' + bookmarks
548 del document.header[i]
549 i = find_token(document.header, "\\pdf_bookmarksnumbered", i)
551 bookmarksnumbered = get_value_string(document.header, '\\pdf_bookmarksnumbered', 0)
552 bookmarksnumbered = ',\n bookmarksnumbered=' + bookmarksnumbered
553 del document.header[i]
554 i = find_token(document.header, "\\pdf_bookmarksopen", i)
556 bookmarksopen = get_value_string(document.header, '\\pdf_bookmarksopen', 0)
557 bookmarksopen = ',\n bookmarksopen=' + bookmarksopen
558 del document.header[i]
559 i = find_token(document.header, "\\pdf_bookmarksopenlevel", i)
561 bookmarksopenlevel = get_value_string(document.header, '\\pdf_bookmarksopenlevel', 0, 0, True)
562 bookmarksopenlevel = ',\n bookmarksopenlevel=' + bookmarksopenlevel
563 del document.header[i]
564 i = find_token(document.header, "\\pdf_breaklinks", i)
566 breaklinks = get_value_string(document.header, '\\pdf_breaklinks', 0)
567 breaklinks = ',\n breaklinks=' + breaklinks
568 del document.header[i]
569 i = find_token(document.header, "\\pdf_pdfborder", i)
571 pdfborder = get_value_string(document.header, '\\pdf_pdfborder', 0)
572 if pdfborder == 'true':
573 pdfborder = ',\n pdfborder={0 0 0}'
575 pdfborder = ',\n pdfborder={0 0 1}'
576 del document.header[i]
577 i = find_token(document.header, "\\pdf_colorlinks", i)
579 colorlinks = get_value_string(document.header, '\\pdf_colorlinks', 0)
580 colorlinks = ',\n colorlinks=' + colorlinks
581 del document.header[i]
582 i = find_token(document.header, "\\pdf_backref", i)
584 backref = get_value_string(document.header, '\\pdf_backref', 0)
585 backref = ',\n backref=' + backref
586 del document.header[i]
587 i = find_token(document.header, "\\pdf_pagebackref", i)
589 pagebackref = get_value_string(document.header, '\\pdf_pagebackref', 0)
590 pagebackref = ',\n pagebackref=' + pagebackref
591 del document.header[i]
592 i = find_token(document.header, "\\pdf_pagemode", 0)
594 pagemode = get_value_string(document.header, '\\pdf_pagemode', 0)
595 pagemode = ',\n pdfpagemode=' + pagemode
596 del document.header[i]
597 i = find_token(document.header, "\\pdf_quoted_options", 0)
599 otheroptions = get_value_string(document.header, '\\pdf_quoted_options', 0, 0, True)
600 if title == "" and author == "" and subject == "" and keywords == "":
601 otheroptions = ' ' + otheroptions
603 otheroptions = ',\n ' + otheroptions
604 del document.header[i]
606 # write to the preamble when hyperref was used
608 # preamble write preparations
609 # bookmark numbers are only output when they are turned on
610 if bookmarksopen == ',\n bookmarksopen=true':
611 bookmarksopen = bookmarksopen + bookmarksopenlevel
612 if bookmarks == ',\n bookmarks=true':
613 bookmarks = bookmarks + bookmarksnumbered + bookmarksopen
615 bookmarks = bookmarks
616 # hypersetup is only output when there are things to be set up
617 setupstart = '\\hypersetup{%\n'
619 if otheroptions == "" and title == "" and author == ""\
620 and subject == "" and keywords == "":
624 add_to_preamble(document,
625 ['% Commands inserted by lyx2lyx for PDF properties',
626 '\\usepackage[unicode=true'
645 def remove_inzip_options(document):
646 "Remove inzipName and embed options from the Graphics inset"
649 i = find_token(document.body, "\\begin_inset Graphics", i)
652 j = find_end_of_inset(document.body, i + 1)
655 document.warning("Malformed LyX document: Could not find end of graphics inset.")
656 # If there's a inzip param, just remove that
657 k = find_token(document.body, "\tinzipName", i + 1, j)
660 # embed option must follow the inzipName option
661 del document.body[k+1]
665 def convert_inset_command(document):
668 \begin_inset LatexCommand cmd
670 \begin_inset CommandInset InsetType
675 i = find_token(document.body, "\\begin_inset LatexCommand", i)
678 line = document.body[i]
679 r = re.compile(r'\\begin_inset LatexCommand (.*)$')
683 #this is adapted from factory.cpp
684 if cmdName[0:4].lower() == "cite":
685 insetName = "citation"
686 elif cmdName == "url" or cmdName == "htmlurl":
688 elif cmdName[-3:] == "ref":
690 elif cmdName == "tableofcontents":
692 elif cmdName == "printnomenclature":
693 insetName = "nomencl_print"
694 elif cmdName == "printindex":
695 insetName = "index_print"
698 insertion = ["\\begin_inset CommandInset " + insetName, "LatexCommand " + cmdName]
699 document.body[i : i+1] = insertion
702 def revert_inset_command(document):
705 \begin_inset CommandInset InsetType
708 \begin_inset LatexCommand cmd
709 Some insets may end up being converted to insets earlier versions of LyX
710 will not be able to recognize. Not sure what to do about that.
714 i = find_token(document.body, "\\begin_inset CommandInset", i)
717 nextline = document.body[i+1]
718 r = re.compile(r'LatexCommand\s+(.*)$')
719 m = r.match(nextline)
721 document.warning("Malformed LyX document: Missing LatexCommand in " + document.body[i] + ".")
724 insertion = ["\\begin_inset LatexCommand " + cmdName]
725 document.body[i : i+2] = insertion
728 def convert_wrapfig_options(document):
729 "Convert optional options for wrap floats (wrapfig)."
730 # adds the tokens "lines", "placement", and "overhang"
733 i = find_token(document.body, "\\begin_inset Wrap figure", i)
736 document.body.insert(i + 1, "lines 0")
737 j = find_token(document.body, "placement", i)
738 # placement can be already set or not; if not, set it
740 document.body.insert(i + 3, "overhang 0col%")
742 document.body.insert(i + 2, "placement o")
743 document.body.insert(i + 3, "overhang 0col%")
747 def revert_wrapfig_options(document):
748 "Revert optional options for wrap floats (wrapfig)."
751 i = find_token(document.body, "lines", i)
754 j = find_token(document.body, "overhang", i+1)
755 if j != i + 2 and j != -1:
756 document.warning("Malformed LyX document: Couldn't find overhang parameter of wrap float.")
760 del document.body[j-1]
764 # To convert and revert indices, we need to convert between LaTeX
765 # strings and LyXText. Here we do a minimal conversion to prevent
766 # crashes and data loss. Manual patch-up may be needed.
778 def convert_latexcommand_index(document):
779 "Convert from LatexCommand form to collapsable form."
782 i = find_token(document.body, "\\begin_inset CommandInset index", i)
785 if document.body[i + 1] != "LatexCommand index": # Might also be index_print
787 fullcontent = document.body[i + 2][5:]
789 fullcontent = fullcontent[1:-1]
790 document.body[i:i + 3] = ["\\begin_inset Index",
792 "\\begin_layout Standard"]
794 # We are now on the blank line preceding "\end_inset"
795 # We will write the content here, into the inset.
797 # Do the LaTeX --> LyX text conversion
798 for rep in replacements:
799 fullcontent = fullcontent.replace(rep[0], rep[1])
801 fullcontent = wrap_into_ert(fullcontent, r'\"', '"')
803 r = re.compile('^(.*?)(\$.*?\$)(.*)')
804 lines = fullcontent.split('\n')
806 #document.warning("LINE: " + line)
807 #document.warning(str(i) + ":" + document.body[i])
808 #document.warning("LAST: " + document.body[-1])
813 f = m.group(2).replace('\\\\', '\\')
817 s = wrap_into_ert(s, r'\\', '\\backslash')
818 s = wrap_into_ert(s, '{', '{')
819 s = wrap_into_ert(s, '}', '}')
820 subst = s.split('\n')
821 document.body[i:i] = subst
823 document.body.insert(i + 1, "\\begin_inset Formula " + f)
824 document.body.insert(i + 2, "\\end_inset")
826 # Generic, \\ -> \backslash:
827 g = wrap_into_ert(g, r'\\', '\\backslash')
828 g = wrap_into_ert(g, '{', '{')
829 g = wrap_into_ert(g, '}', '}')
830 subst = g.split('\n')
831 document.body[i+1:i+1] = subst
833 document.body.insert(i + 1, "\\end_layout")
836 def revert_latexcommand_index(document):
837 "Revert from collapsable form to LatexCommand form."
840 i = find_token(document.body, "\\begin_inset Index", i)
843 j = find_end_of_inset(document.body, i + 1)
846 del document.body[j - 1]
847 del document.body[j - 2] # \end_layout
848 document.body[i] = "\\begin_inset CommandInset index"
849 document.body[i + 1] = "LatexCommand index"
850 # clean up multiline stuff
853 for k in range(i + 3, j - 2):
854 line = document.body[k]
855 if line.startswith("\\begin_inset ERT"):
856 ert_end = find_end_of_inset(document.body, k + 1)
858 if line.startswith("\\begin_inset Formula"):
860 if line.startswith("\\begin_layout Standard"):
862 if line.startswith("\\begin_layout Plain Layout"):
864 if line.startswith("\\end_layout"):
866 if line.startswith("\\end_inset"):
868 if line.startswith("status collapsed"):
870 if line.startswith("status open"):
872 # a lossless reversion is not possible
873 # try at least to handle some common insets and settings
874 # do not replace inside ERTs
876 # Do the LyX text --> LaTeX conversion
877 for rep in replacements:
878 line = line.replace(rep[1], rep[0])
879 line = line.replace(r'\backslash', r'\textbackslash{}')
880 line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}')
881 line = line.replace(r'\shape italic', r'\itshape{}').replace(r'\shape smallcaps', r'\scshape{}')
882 line = line.replace(r'\shape slanted', r'\slshape{}').replace(r'\shape default', r'\upshape{}')
883 line = line.replace(r'\emph on', r'\em{}').replace(r'\emph default', r'\em{}')
884 line = line.replace(r'\noun on', r'\scshape{}').replace(r'\noun default', r'\upshape{}')
885 line = line.replace(r'\bar under', r'\underbar{').replace(r'\bar default', r'}')
886 line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}')
887 line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}')
888 line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'')
890 line = line.replace(r'\backslash', r'\\')
891 content = content + line;
892 document.body[i + 3] = "name " + '"' + content + '"'
893 for k in range(i + 4, j - 2):
894 del document.body[i + 4]
895 document.body.insert(i + 4, "")
896 del document.body[i + 2] # \begin_layout standard
900 def revert_wraptable(document):
901 "Revert wrap table to wrap figure."
904 i = find_token(document.body, "\\begin_inset Wrap table", i)
907 document.body[i] = document.body[i].replace('\\begin_inset Wrap table', '\\begin_inset Wrap figure')
911 def revert_vietnamese(document):
912 "Set language Vietnamese to English"
913 # Set document language from Vietnamese to English
915 if document.language == "vietnamese":
916 document.language = "english"
917 i = find_token(document.header, "\\language", 0)
919 document.header[i] = "\\language english"
922 j = find_token(document.body, "\\lang vietnamese", j)
925 document.body[j] = document.body[j].replace("\\lang vietnamese", "\\lang english")
929 def revert_japanese(document):
930 "Set language japanese-plain to japanese"
931 # Set document language from japanese-plain to japanese
933 if document.language == "japanese-plain":
934 document.language = "japanese"
935 i = find_token(document.header, "\\language", 0)
937 document.header[i] = "\\language japanese"
940 j = find_token(document.body, "\\lang japanese-plain", j)
943 document.body[j] = document.body[j].replace("\\lang japanese-plain", "\\lang japanese")
947 def revert_japanese_encoding(document):
948 "Set input encoding form EUC-JP-plain to EUC-JP etc."
949 # Set input encoding form EUC-JP-plain to EUC-JP etc.
951 i = find_token(document.header, "\\inputencoding EUC-JP-plain", 0)
953 document.header[i] = "\\inputencoding EUC-JP"
955 j = find_token(document.header, "\\inputencoding JIS-plain", 0)
957 document.header[j] = "\\inputencoding JIS"
959 k = find_token(document.header, "\\inputencoding SJIS-plain", 0)
960 if k != -1: # convert to UTF8 since there is currently no SJIS encoding
961 document.header[k] = "\\inputencoding UTF8"
964 def revert_inset_info(document):
965 'Replace info inset with its content'
968 i = find_token(document.body, '\\begin_inset Info', i)
971 j = find_end_of_inset(document.body, i + 1)
974 document.warning("Malformed LyX document: Could not find end of Info inset.")
977 for k in range(i, j+1):
978 if document.body[k].startswith("arg"):
979 arg = document.body[k][3:].strip().strip('"')
980 if document.body[k].startswith("type"):
981 type = document.body[k][4:].strip().strip('"')
982 # I think there is a newline after \\end_inset, which should be removed.
983 if document.body[j + 1].strip() == "":
984 document.body[i : (j + 2)] = [type + ':' + arg]
986 document.body[i : (j + 1)] = [type + ':' + arg]
989 def convert_pdf_options(document):
990 # Set the pdfusetitle tag, delete the pdf_store_options,
991 # set quotes for bookmarksopenlevel"
992 has_hr = get_value(document.header, "\\use_hyperref", 0, default = "0")
994 k = find_token(document.header, "\\use_hyperref", 0)
995 document.header.insert(k + 1, "\\pdf_pdfusetitle true")
996 k = find_token(document.header, "\\pdf_store_options", 0)
998 del document.header[k]
999 i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
1001 document.header[i] = document.header[i].replace('"', '')
1004 def revert_pdf_options_2(document):
1005 # reset the pdfusetitle tag, set quotes for bookmarksopenlevel"
1006 k = find_token(document.header, "\\use_hyperref", 0)
1007 i = find_token(document.header, "\\pdf_pdfusetitle", k)
1009 del document.header[i]
1010 i = find_token(document.header, "\\pdf_bookmarksopenlevel", k)
1012 values = document.header[i].split()
1013 values[1] = ' "' + values[1] + '"'
1014 document.header[i] = ''.join(values)
1017 def convert_htmlurl(document):
1018 'Convert "htmlurl" to "href" insets for docbook'
1019 if document.backend != "docbook":
1023 i = find_token(document.body, "\\begin_inset CommandInset url", i)
1026 document.body[i] = "\\begin_inset CommandInset href"
1027 document.body[i + 1] = "LatexCommand href"
1031 def convert_url(document):
1032 'Convert url insets to url charstyles'
1033 if document.backend == "docbook":
1037 i = find_token(document.body, "\\begin_inset CommandInset url", i)
1040 n = find_token(document.body, "name", i)
1042 # place the URL name in typewriter before the new URL insert
1043 # grab the name 'bla' from the e.g. the line 'name "bla"',
1044 # therefore start with the 6th character
1045 name = document.body[n][6:-1]
1046 newname = [name + " "]
1047 document.body[i:i] = newname
1049 j = find_token(document.body, "target", i)
1051 document.warning("Malformed LyX document: Can't find target for url inset")
1054 target = document.body[j][8:-1]
1055 k = find_token(document.body, "\\end_inset", j)
1057 document.warning("Malformed LyX document: Can't find end of url inset")
1060 newstuff = ["\\begin_inset Flex URL",
1061 "status collapsed", "",
1062 "\\begin_layout Standard",
1067 document.body[i:k] = newstuff
1070 def convert_ams_classes(document):
1071 tc = document.textclass
1072 if (tc != "amsart" and tc != "amsart-plain" and
1073 tc != "amsart-seq" and tc != "amsbook"):
1075 if tc == "amsart-plain":
1076 document.textclass = "amsart"
1077 document.set_textclass()
1078 document.add_module("Theorems (Starred)")
1080 if tc == "amsart-seq":
1081 document.textclass = "amsart"
1082 document.set_textclass()
1083 document.add_module("Theorems (AMS)")
1085 #Now we want to see if any of the environments in the extended theorems
1086 #module were used in this document. If so, we'll add that module, too.
1087 layouts = ["Criterion", "Algorithm", "Axiom", "Condition", "Note", \
1088 "Notation", "Summary", "Acknowledgement", "Conclusion", "Fact", \
1091 r = re.compile(r'^\\begin_layout (.*?)\*?\s*$')
1094 i = find_token(document.body, "\\begin_layout", i)
1097 m = r.match(document.body[i])
1099 document.warning("Weirdly formed \\begin_layout at line %d of body!" % i)
1103 if layouts.count(m) != 0:
1104 document.add_module("Theorems (AMS-Extended)")
1108 def revert_href(document):
1109 'Reverts hyperlink insets (href) to url insets (url)'
1112 i = find_token(document.body, "\\begin_inset CommandInset href", i)
1115 document.body[i : i + 2] = \
1116 ["\\begin_inset CommandInset url", "LatexCommand url"]
1120 def convert_include(document):
1121 'Converts include insets to new format.'
1123 r = re.compile(r'\\begin_inset Include\s+\\([^{]+){([^}]*)}(?:\[(.*)\])?')
1125 i = find_token(document.body, "\\begin_inset Include", i)
1128 line = document.body[i]
1129 previewline = document.body[i + 1]
1132 document.warning("Unable to match line " + str(i) + " of body!")
1138 insertion = ["\\begin_inset CommandInset include",
1139 "LatexCommand " + cmd, previewline,
1140 "filename \"" + fn + "\""]
1143 insertion.append("lstparams " + '"' + opt + '"')
1145 document.body[i : i + 2] = insertion
1149 def revert_include(document):
1150 'Reverts include insets to old format.'
1152 r1 = re.compile('LatexCommand (.+)')
1153 r2 = re.compile('filename (.+)')
1154 r3 = re.compile('options (.*)')
1156 i = find_token(document.body, "\\begin_inset CommandInset include", i)
1159 previewline = document.body[i + 1]
1160 m = r1.match(document.body[i + 2])
1162 document.warning("Malformed LyX document: No LatexCommand line for `" +
1163 document.body[i] + "' on line " + str(i) + ".")
1167 m = r2.match(document.body[i + 3])
1169 document.warning("Malformed LyX document: No filename line for `" + \
1170 document.body[i] + "' on line " + str(i) + ".")
1176 if (cmd == "lstinputlisting"):
1177 m = r3.match(document.body[i + 4])
1179 options = m.group(1)
1181 newline = "\\begin_inset Include \\" + cmd + "{" + fn + "}"
1183 newline += ("[" + options + "]")
1184 insertion = [newline, previewline]
1185 document.body[i : i + numlines] = insertion
1189 def revert_albanian(document):
1190 "Set language Albanian to English"
1192 if document.language == "albanian":
1193 document.language = "english"
1194 i = find_token(document.header, "\\language", 0)
1196 document.header[i] = "\\language english"
1199 j = find_token(document.body, "\\lang albanian", j)
1202 document.body[j] = document.body[j].replace("\\lang albanian", "\\lang english")
1206 def revert_lowersorbian(document):
1207 "Set language lower Sorbian to English"
1209 if document.language == "lowersorbian":
1210 document.language = "english"
1211 i = find_token(document.header, "\\language", 0)
1213 document.header[i] = "\\language english"
1216 j = find_token(document.body, "\\lang lowersorbian", j)
1219 document.body[j] = document.body[j].replace("\\lang lowersorbian", "\\lang english")
1223 def revert_uppersorbian(document):
1224 "Set language uppersorbian to usorbian as this was used in LyX 1.5"
1226 if document.language == "uppersorbian":
1227 document.language = "usorbian"
1228 i = find_token(document.header, "\\language", 0)
1230 document.header[i] = "\\language usorbian"
1233 j = find_token(document.body, "\\lang uppersorbian", j)
1236 document.body[j] = document.body[j].replace("\\lang uppersorbian", "\\lang usorbian")
1240 def convert_usorbian(document):
1241 "Set language usorbian to uppersorbian"
1243 if document.language == "usorbian":
1244 document.language = "uppersorbian"
1245 i = find_token(document.header, "\\language", 0)
1247 document.header[i] = "\\language uppersorbian"
1250 j = find_token(document.body, "\\lang usorbian", j)
1253 document.body[j] = document.body[j].replace("\\lang usorbian", "\\lang uppersorbian")
1257 def revert_macro_optional_params(document):
1258 "Convert macro definitions with optional parameters into ERTs"
1259 # Stub to convert macro definitions with one or more optional parameters
1260 # into uninterpreted ERT insets
1263 def revert_hyperlinktype(document):
1264 'Reverts hyperlink type'
1268 i = find_token(document.body, "target", i)
1271 j = find_token(document.body, "type", i)
1275 del document.body[j]
1279 def revert_pagebreak(document):
1280 'Reverts pagebreak to ERT'
1283 i = find_token(document.body, "\\pagebreak", i)
1286 document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
1287 '\\begin_layout Standard\n\n\n\\backslash\n' \
1288 'pagebreak{}\n\\end_layout\n\n\\end_inset\n\n'
1292 def revert_linebreak(document):
1293 'Reverts linebreak to ERT'
1296 i = find_token(document.body, "\\linebreak", i)
1299 document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
1300 '\\begin_layout Standard\n\n\n\\backslash\n' \
1301 'linebreak{}\n\\end_layout\n\n\\end_inset\n\n'
1305 def revert_latin(document):
1306 "Set language Latin to English"
1308 if document.language == "latin":
1309 document.language = "english"
1310 i = find_token(document.header, "\\language", 0)
1312 document.header[i] = "\\language english"
1315 j = find_token(document.body, "\\lang latin", j)
1318 document.body[j] = document.body[j].replace("\\lang latin", "\\lang english")
1322 def revert_samin(document):
1323 "Set language North Sami to English"
1325 if document.language == "samin":
1326 document.language = "english"
1327 i = find_token(document.header, "\\language", 0)
1329 document.header[i] = "\\language english"
1332 j = find_token(document.body, "\\lang samin", j)
1335 document.body[j] = document.body[j].replace("\\lang samin", "\\lang english")
1339 def convert_serbocroatian(document):
1340 "Set language Serbocroatian to Croatian as this was really Croatian in LyX 1.5"
1342 if document.language == "serbocroatian":
1343 document.language = "croatian"
1344 i = find_token(document.header, "\\language", 0)
1346 document.header[i] = "\\language croatian"
1349 j = find_token(document.body, "\\lang serbocroatian", j)
1352 document.body[j] = document.body[j].replace("\\lang serbocroatian", "\\lang croatian")
1356 def convert_framed_notes(document):
1357 "Convert framed notes to boxes. "
1360 i = find_tokens(document.body, ["\\begin_inset Note Framed", "\\begin_inset Note Shaded"], i)
1363 subst = [document.body[i].replace("\\begin_inset Note", "\\begin_inset Box"),
1372 'height_special "totalheight"']
1373 document.body[i:i+1] = subst
1377 def convert_module_names(document):
1378 modulemap = { 'Braille' : 'braille', 'Endnote' : 'endnotes', 'Foot to End' : 'foottoend',\
1379 'Hanging' : 'hanging', 'Linguistics' : 'linguistics', 'Logical Markup' : 'logicalmkup', \
1380 'Theorems (AMS-Extended)' : 'theorems-ams-extended', 'Theorems (AMS)' : 'theorems-ams', \
1381 'Theorems (Order By Chapter)' : 'theorems-chap', 'Theorems (Order By Section)' : 'theorems-sec', \
1382 'Theorems (Starred)' : 'theorems-starred', 'Theorems' : 'theorems-std' }
1383 modlist = document.get_module_list()
1384 if len(modlist) == 0:
1388 if modulemap.has_key(mod):
1389 newmodlist.append(modulemap[mod])
1391 document.warning("Can't find module %s in the module map!" % mod)
1392 newmodlist.append(mod)
1393 document.set_module_list(newmodlist)
1396 def revert_module_names(document):
1397 modulemap = { 'braille' : 'Braille', 'endnotes' : 'Endnote', 'foottoend' : 'Foot to End',\
1398 'hanging' : 'Hanging', 'linguistics' : 'Linguistics', 'logicalmkup' : 'Logical Markup', \
1399 'theorems-ams-extended' : 'Theorems (AMS-Extended)', 'theorems-ams' : 'Theorems (AMS)', \
1400 'theorems-chap' : 'Theorems (Order By Chapter)', 'theorems-sec' : 'Theorems (Order By Section)', \
1401 'theorems-starred' : 'Theorems (Starred)', 'theorems-std' : 'Theorems'}
1402 modlist = document.get_module_list()
1403 if len(modlist) == 0:
1407 if modulemap.has_key(mod):
1408 newmodlist.append(modulemap[mod])
1410 document.warning("Can't find module %s in the module map!" % mod)
1411 newmodlist.append(mod)
1412 document.set_module_list(newmodlist)
1415 def revert_colsep(document):
1416 i = find_token(document.header, "\\columnsep", 0)
1419 colsepline = document.header[i]
1420 r = re.compile(r'\\columnsep (.*)')
1421 m = r.match(colsepline)
1423 document.warning("Malformed column separation line!")
1426 del document.header[i]
1427 #it seems to be safe to add the package even if it is already used
1428 pretext = ["\\usepackage{geometry}", "\\geometry{columnsep=" + colsep + "}"]
1430 add_to_preamble(document, pretext)
1433 def revert_framed_notes(document):
1434 "Revert framed boxes to notes. "
1437 i = find_tokens(document.body, ["\\begin_inset Box Framed", "\\begin_inset Box Shaded"], i)
1441 j = find_end_of_inset(document.body, i + 1)
1444 document.warning("Malformed LyX document: Could not find end of Box inset.")
1445 k = find_token(document.body, "status", i + 1, j)
1447 document.warning("Malformed LyX document: Missing `status' tag in Box inset.")
1449 status = document.body[k]
1450 l = find_default_layout(document, i + 1, j)
1452 document.warning("Malformed LyX document: Missing `\\begin_layout' in Box inset.")
1454 m = find_token(document.body, "\\end_layout", i + 1, j)
1456 document.warning("Malformed LyX document: Missing `\\end_layout' in Box inset.")
1458 ibox = find_token(document.body, "has_inner_box 1", i + 1, k)
1459 pbox = find_token(document.body, "use_parbox 1", i + 1, k)
1460 if ibox == -1 and pbox == -1:
1461 document.body[i] = document.body[i].replace("\\begin_inset Box", "\\begin_inset Note")
1462 del document.body[i+1:k]
1464 document.body[i] = document.body[i].replace("\\begin_inset Box Shaded", "\\begin_inset Box Frameless")
1465 subst1 = [document.body[l],
1466 "\\begin_inset Note Shaded",
1468 '\\begin_layout Standard']
1469 document.body[l:l + 1] = subst1
1470 subst2 = [document.body[m], "\\end_layout", "\\end_inset"]
1471 document.body[m:m + 1] = subst2
1475 def revert_slash(document):
1476 'Revert \\SpecialChar \\slash{} to ERT'
1477 r = re.compile(r'\\SpecialChar \\slash{}')
1479 while i < len(document.body):
1480 m = r.match(document.body[i])
1482 subst = ['\\begin_inset ERT',
1483 'status collapsed', '',
1484 '\\begin_layout Standard',
1485 '', '', '\\backslash',
1489 document.body[i: i+1] = subst
1495 def revert_nobreakdash(document):
1496 'Revert \\SpecialChar \\nobreakdash- to ERT'
1498 while i < len(document.body):
1499 line = document.body[i]
1500 r = re.compile(r'\\SpecialChar \\nobreakdash-')
1503 subst = ['\\begin_inset ERT',
1504 'status collapsed', '',
1505 '\\begin_layout Standard', '', '',
1510 document.body[i:i+1] = subst
1512 j = find_token(document.header, "\\use_amsmath", 0)
1514 document.warning("Malformed LyX document: Missing '\\use_amsmath'.")
1516 document.header[j] = "\\use_amsmath 2"
1521 #Returns number of lines added/removed
1522 def revert_nocite_key(body, start, end):
1523 'key "..." -> \nocite{...}'
1524 r = re.compile(r'^key "(.*)"')
1528 m = r.match(body[i])
1530 body[i:i+1] = ["\\backslash", "nocite{" + m.group(1) + "}"]
1531 j += 1 # because we added a line
1532 i += 2 # skip that line
1535 j -= 1 # because we deleted a line
1536 # no need to change i, since it now points to the next line
1540 def revert_nocite(document):
1541 "Revert LatexCommand nocite to ERT"
1544 i = find_token(document.body, "\\begin_inset CommandInset citation", i)
1547 if (document.body[i+1] != "LatexCommand nocite"):
1548 # note that we already incremented i
1551 insetEnd = find_end_of_inset(document.body, i)
1553 #this should not happen
1554 document.warning("End of CommandInset citation not found in revert_nocite!")
1557 paramLocation = i + 2 #start of the inset's parameters
1559 document.body[i:i+2] = \
1560 ["\\begin_inset ERT", "status collapsed", "", "\\begin_layout Standard"]
1561 # that added two lines
1564 #print insetEnd, document.body[i: insetEnd + 1]
1565 insetEnd += revert_nocite_key(document.body, paramLocation, insetEnd)
1566 #print insetEnd, document.body[i: insetEnd + 1]
1567 document.body.insert(insetEnd, "\\end_layout")
1568 document.body.insert(insetEnd + 1, "")
1572 def revert_btprintall(document):
1573 "Revert (non-bibtopic) btPrintAll option to ERT \nocite{*}"
1574 i = find_token(document.header, '\\use_bibtopic', 0)
1576 document.warning("Malformed lyx document: Missing '\\use_bibtopic'.")
1578 if get_value(document.header, '\\use_bibtopic', 0) == "false":
1580 while i < len(document.body):
1581 i = find_token(document.body, "\\begin_inset CommandInset bibtex", i)
1584 j = find_end_of_inset(document.body, i + 1)
1586 #this should not happen
1587 document.warning("End of CommandInset bibtex not found in revert_btprintall!")
1588 j = len(document.body)
1589 # this range isn't really right, but it should be OK, since we shouldn't
1590 # see more than one matching line in each inset
1592 for k in range(i, j):
1593 if (document.body[k] == 'btprint "btPrintAll"'):
1594 del document.body[k]
1595 subst = ["\\begin_inset ERT",
1596 "status collapsed", "",
1597 "\\begin_layout Standard", "",
1602 document.body[i:i] = subst
1603 addlines = addedlines + len(subst) - 1
1607 def revert_bahasam(document):
1608 "Set language Bahasa Malaysia to Bahasa Indonesia"
1610 if document.language == "bahasam":
1611 document.language = "bahasa"
1612 i = find_token(document.header, "\\language", 0)
1614 document.header[i] = "\\language bahasa"
1617 j = find_token(document.body, "\\lang bahasam", j)
1620 document.body[j] = document.body[j].replace("\\lang bahasam", "\\lang bahasa")
1624 def revert_interlingua(document):
1625 "Set language Interlingua to English"
1627 if document.language == "interlingua":
1628 document.language = "english"
1629 i = find_token(document.header, "\\language", 0)
1631 document.header[i] = "\\language english"
1634 j = find_token(document.body, "\\lang interlingua", j)
1637 document.body[j] = document.body[j].replace("\\lang interlingua", "\\lang english")
1641 def revert_serbianlatin(document):
1642 "Set language Serbian-Latin to Croatian"
1644 if document.language == "serbian-latin":
1645 document.language = "croatian"
1646 i = find_token(document.header, "\\language", 0)
1648 document.header[i] = "\\language croatian"
1651 j = find_token(document.body, "\\lang serbian-latin", j)
1654 document.body[j] = document.body[j].replace("\\lang serbian-latin", "\\lang croatian")
1658 def revert_rotfloat(document):
1659 " Revert sideways custom floats. "
1662 # whitespace intended (exclude \\begin_inset FloatList)
1663 i = find_token(document.body, "\\begin_inset Float ", i)
1666 line = document.body[i]
1667 r = re.compile(r'\\begin_inset Float (.*)$')
1670 document.warning("Unable to match line " + str(i) + " of body!")
1673 floattype = m.group(1)
1674 if floattype == "figure" or floattype == "table":
1677 j = find_end_of_inset(document.body, i)
1679 document.warning("Malformed lyx document: Missing '\\end_inset'.")
1683 if get_value(document.body, 'sideways', i, j) == "false":
1686 l = find_default_layout(document, i + 1, j)
1688 document.warning("Malformed LyX document: Missing `\\begin_layout' in Float inset.")
1690 subst = ['\\begin_layout Standard',
1691 '\\begin_inset ERT',
1692 'status collapsed', '',
1693 '\\begin_layout Standard', '', '',
1695 'end{sideways' + floattype + '}',
1696 '\\end_layout', '', '\\end_inset']
1697 document.body[j : j+1] = subst
1698 addedLines = len(subst) - 1
1699 del document.body[i+1 : l]
1700 addedLines -= (l-1) - (i+1)
1701 subst = ['\\begin_inset ERT', 'status collapsed', '',
1702 '\\begin_layout Standard', '', '', '\\backslash',
1703 'begin{sideways' + floattype + '}',
1704 '\\end_layout', '', '\\end_inset', '',
1706 document.body[i : i+1] = subst
1707 addedLines += len(subst) - 1
1708 if floattype == "algorithm":
1709 add_to_preamble(document,
1710 ['% Commands inserted by lyx2lyx for sideways algorithm float',
1711 '\\usepackage{rotfloat}',
1712 '\\floatstyle{ruled}',
1713 '\\newfloat{algorithm}{tbp}{loa}',
1714 '\\floatname{algorithm}{Algorithm}'])
1716 document.warning("Cannot create preamble definition for custom float" + floattype + ".")
1720 def revert_widesideways(document):
1721 " Revert wide sideways floats. "
1724 # whitespace intended (exclude \\begin_inset FloatList)
1725 i = find_token(document.body, '\\begin_inset Float ', i)
1728 line = document.body[i]
1729 r = re.compile(r'\\begin_inset Float (.*)$')
1732 document.warning("Unable to match line " + str(i) + " of body!")
1735 floattype = m.group(1)
1736 if floattype != "figure" and floattype != "table":
1739 j = find_end_of_inset(document.body, i)
1741 document.warning("Malformed lyx document: Missing '\\end_inset'.")
1744 if get_value(document.body, 'sideways', i, j) == "false" or \
1745 get_value(document.body, 'wide', i, j) == "false":
1748 l = find_default_layout(document, i + 1, j)
1750 document.warning("Malformed LyX document: Missing `\\begin_layout' in Float inset.")
1752 subst = ['\\begin_layout Standard', '\\begin_inset ERT',
1753 'status collapsed', '',
1754 '\\begin_layout Standard', '', '', '\\backslash',
1755 'end{sideways' + floattype + '*}',
1756 '\\end_layout', '', '\\end_inset']
1757 document.body[j : j+1] = subst
1758 addedLines = len(subst) - 1
1759 del document.body[i+1:l-1]
1760 addedLines -= (l-1) - (i+1)
1761 subst = ['\\begin_inset ERT', 'status collapsed', '',
1762 '\\begin_layout Standard', '', '', '\\backslash',
1763 'begin{sideways' + floattype + '*}', '\\end_layout', '',
1764 '\\end_inset', '', '\\end_layout', '']
1765 document.body[i : i+1] = subst
1766 addedLines += len(subst) - 1
1767 add_to_preamble(document, ['\\usepackage{rotfloat}\n'])
1771 def revert_inset_embedding(document, type):
1772 ' Remove embed tag from certain type of insets'
1775 i = find_token(document.body, "\\begin_inset %s" % type, i)
1778 j = find_end_of_inset(document.body, i)
1780 document.warning("Malformed lyx document: Missing '\\end_inset'.")
1783 k = find_token(document.body, "\tembed", i, j)
1785 k = find_token(document.body, "embed", i, j)
1787 del document.body[k]
1791 def revert_external_embedding(document):
1792 ' Remove embed tag from external inset '
1793 revert_inset_embedding(document, 'External')
1796 def convert_subfig(document):
1797 " Convert subfigures to subfloats. "
1800 i = find_token(document.body, '\\begin_inset Graphics', i)
1803 j = find_end_of_inset(document.body, i)
1805 document.warning("Malformed lyx document: Missing '\\end_inset'.")
1808 k = find_token(document.body, '\tsubcaption', i, j)
1812 l = find_token(document.body, '\tsubcaptionText', i, j)
1813 caption = document.body[l][16:].strip('"')
1814 savestr = document.body[i]
1815 laststr = document.body[j]
1816 del document.body[l]
1817 del document.body[k]
1819 subst = ['\\begin_inset Float figure', 'wide false', 'sideways false',
1820 'status open', '', '\\begin_layout Plain Layout', '\\begin_inset',
1821 'Caption', '', '\\begin_layout Plain Layout',
1822 caption, '\\end_layout', '', '\\end_inset', '',
1823 '\\end_layout', '', '\\begin_layout Plain Layout', savestr]
1824 document.body[i : i+1] = subst
1825 addedLines += len(subst) - 1
1826 subst = ['', '\\end_layout', '', '\\end_inset', laststr]
1827 document.body[j : j+1] = subst
1828 addedLines += len(subst) - 1
1832 def revert_subfig(document):
1833 " Revert subfloats. "
1836 # whitespace intended (exclude \\begin_inset FloatList)
1837 i = find_token(document.body, '\\begin_inset Float ', i)
1841 j = find_end_of_inset(document.body, i)
1843 document.warning("Malformed lyx document: Missing '\\end_inset' (float).")
1846 # look for embedded float (= subfloat)
1847 # whitespace intended (exclude \\begin_inset FloatList)
1848 k = find_token(document.body, '\\begin_inset Float ', i + 1, j)
1851 l = find_end_of_inset(document.body, k)
1853 document.warning("Malformed lyx document: Missing '\\end_inset' (embedded float).")
1856 m = find_default_layout(document, k + 1, l)
1858 cap = find_token(document.body, '\\begin_inset Caption', k + 1, l)
1862 capend = find_end_of_inset(document.body, cap)
1864 document.warning("Malformed lyx document: Missing '\\end_inset' (caption).")
1868 lbl = find_token(document.body, '\\begin_inset CommandInset label', cap, capend)
1870 lblend = find_end_of_inset(document.body, lbl + 1)
1872 document.warning("Malformed lyx document: Missing '\\end_inset' (label).")
1874 for line in document.body[lbl:lblend + 1]:
1875 if line.startswith('name '):
1876 label = line.split()[1].strip('"')
1883 opt = find_token(document.body, '\\begin_inset OptArg', cap, capend)
1885 optend = find_end_of_inset(document.body, opt)
1887 document.warning("Malformed lyx document: Missing '\\end_inset' (OptArg).")
1889 optc = find_default_layout(document, opt, optend)
1891 document.warning("Malformed LyX document: Missing `\\begin_layout' in Float inset.")
1893 optcend = find_end_of(document.body, optc, "\\begin_layout", "\\end_layout")
1894 for line in document.body[optc:optcend]:
1895 if not line.startswith('\\'):
1896 shortcap += line.strip()
1900 for line in document.body[cap:capend]:
1901 if line in document.body[lbl:lblend]:
1903 elif line in document.body[opt:optend]:
1905 elif not line.startswith('\\'):
1906 caption += line.strip()
1908 caption += "\\backslash\nlabel{" + label + "}"
1909 document.body[l] = '\\begin_layout Plain Layout\n\\begin_inset ERT\nstatus collapsed\n\n' \
1910 '\\begin_layout Plain Layout\n\n}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n\\begin_layout Plain Layout\n'
1911 del document.body[cap:capend+1]
1912 del document.body[k+1:m-1]
1913 insertion = '\\begin_inset ERT\nstatus collapsed\n\n' \
1914 '\\begin_layout Plain Layout\n\n\\backslash\n' \
1916 if len(shortcap) > 0:
1917 insertion = insertion + "[" + shortcap + "]"
1918 if len(caption) > 0:
1919 insertion = insertion + "[" + caption + "]"
1920 insertion = insertion + '{%\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n'
1921 document.body[k] = insertion
1922 add_to_preamble(document,
1923 ['\\usepackage{subfig}\n'])
1927 def revert_wrapplacement(document):
1928 " Revert placement options wrap floats (wrapfig). "
1931 i = find_token(document.body, "lines", i)
1934 j = find_token(document.body, "placement", i+1)
1936 document.warning("Malformed LyX document: Couldn't find placement parameter of wrap float.")
1938 document.body[j] = document.body[j].replace("placement O", "placement o")
1939 document.body[j] = document.body[j].replace("placement I", "placement i")
1940 document.body[j] = document.body[j].replace("placement L", "placement l")
1941 document.body[j] = document.body[j].replace("placement R", "placement r")
1945 def remove_extra_embedded_files(document):
1946 " Remove \extra_embedded_files from buffer params "
1947 i = find_token(document.header, '\\extra_embedded_files', 0)
1950 document.header.pop(i)
1953 def convert_spaceinset(document):
1954 " Convert '\\InsetSpace foo' to '\\begin_inset Space foo\n\\end_inset' "
1956 while i < len(document.body):
1957 m = re.match(r'(.*)\\InsetSpace (.*)', document.body[i])
1961 subst = [before, "\\begin_inset Space " + after, "\\end_inset"]
1962 document.body[i: i+1] = subst
1968 def revert_spaceinset(document):
1969 " Revert '\\begin_inset Space foo\n\\end_inset' to '\\InsetSpace foo' "
1972 i = find_token(document.body, "\\begin_inset Space", i)
1975 j = find_end_of_inset(document.body, i)
1977 document.warning("Malformed LyX document: Could not find end of space inset.")
1979 document.body[i] = document.body[i].replace('\\begin_inset Space', '\\InsetSpace')
1980 del document.body[j]
1983 def convert_hfill(document):
1984 " Convert hfill to space inset "
1987 i = find_token(document.body, "\\hfill", i)
1990 subst = document.body[i].replace('\\hfill', \
1991 '\n\\begin_inset Space \\hfill{}\n\\end_inset')
1992 subst = subst.split('\n')
1993 document.body[i : i+1] = subst
1997 def revert_hfills(document):
1998 ' Revert \\hfill commands '
1999 hfill = re.compile(r'\\hfill')
2000 dotfill = re.compile(r'\\dotfill')
2001 hrulefill = re.compile(r'\\hrulefill')
2004 i = find_token(document.body, "\\InsetSpace", i)
2007 if hfill.search(document.body[i]):
2008 document.body[i] = \
2009 document.body[i].replace('\\InsetSpace \\hfill{}', '\\hfill')
2012 if dotfill.search(document.body[i]):
2013 subst = document.body[i].replace('\\InsetSpace \\dotfill{}', \
2014 '\\begin_inset ERT\nstatus collapsed\n\n' \
2015 '\\begin_layout Standard\n\n\n\\backslash\n' \
2016 'dotfill{}\n\\end_layout\n\n\\end_inset\n\n')
2017 subst = subst.split('\n')
2018 document.body[i : i+1] = subst
2021 if hrulefill.search(document.body[i]):
2022 subst = document.body[i].replace('\\InsetSpace \\hrulefill{}', \
2023 '\\begin_inset ERT\nstatus collapsed\n\n' \
2024 '\\begin_layout Standard\n\n\n\\backslash\n' \
2025 'hrulefill{}\n\\end_layout\n\n\\end_inset\n\n')
2026 subst = subst.split('\n')
2027 document.body[i : i+1] = subst
2032 def revert_hspace(document):
2033 ' Revert \\InsetSpace \\hspace{} to ERT '
2035 hspace = re.compile(r'\\hspace{}')
2036 hstar = re.compile(r'\\hspace\*{}')
2038 i = find_token(document.body, "\\InsetSpace \\hspace", i)
2041 length = get_value(document.body, '\\length', i+1)
2043 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
2045 del document.body[i+1]
2047 if hstar.search(document.body[i]):
2048 subst = document.body[i].replace('\\InsetSpace \\hspace*{}', \
2049 '\\begin_inset ERT\nstatus collapsed\n\n' \
2050 '\\begin_layout Standard\n\n\n\\backslash\n' \
2051 'hspace*{' + length + '}\n\\end_layout\n\n\\end_inset\n\n')
2052 subst = subst.split('\n')
2053 document.body[i : i+1] = subst
2054 addedLines += len(subst) - 1
2057 if hspace.search(document.body[i]):
2058 subst = document.body[i].replace('\\InsetSpace \\hspace{}', \
2059 '\\begin_inset ERT\nstatus collapsed\n\n' \
2060 '\\begin_layout Standard\n\n\n\\backslash\n' \
2061 'hspace{' + length + '}\n\\end_layout\n\n\\end_inset\n\n')
2062 subst = subst.split('\n')
2063 document.body[i : i+1] = subst
2064 addedLines += len(subst) - 1
2070 def revert_protected_hfill(document):
2071 ' Revert \\begin_inset Space \\hspace*{\\fill} to ERT '
2074 i = find_token(document.body, '\\begin_inset Space \\hspace*{\\fill}', i)
2077 j = find_end_of_inset(document.body, i)
2079 document.warning("Malformed LyX document: Could not find end of space inset.")
2081 del document.body[j]
2082 subst = document.body[i].replace('\\begin_inset Space \\hspace*{\\fill}', \
2083 '\\begin_inset ERT\nstatus collapsed\n\n' \
2084 '\\begin_layout Standard\n\n\n\\backslash\n' \
2085 'hspace*{\n\\backslash\nfill}\n\\end_layout\n\n\\end_inset\n\n')
2086 subst = subst.split('\n')
2087 document.body[i : i+1] = subst
2091 def revert_leftarrowfill(document):
2092 ' Revert \\begin_inset Space \\leftarrowfill{} to ERT '
2095 i = find_token(document.body, '\\begin_inset Space \\leftarrowfill{}', i)
2098 j = find_end_of_inset(document.body, i)
2100 document.warning("Malformed LyX document: Could not find end of space inset.")
2102 del document.body[j]
2103 subst = document.body[i].replace('\\begin_inset Space \\leftarrowfill{}', \
2104 '\\begin_inset ERT\nstatus collapsed\n\n' \
2105 '\\begin_layout Standard\n\n\n\\backslash\n' \
2106 'leftarrowfill{}\n\\end_layout\n\n\\end_inset\n\n')
2107 subst = subst.split('\n')
2108 document.body[i : i+1] = subst
2112 def revert_rightarrowfill(document):
2113 ' Revert \\begin_inset Space \\rightarrowfill{} to ERT '
2116 i = find_token(document.body, '\\begin_inset Space \\rightarrowfill{}', i)
2119 j = find_end_of_inset(document.body, i)
2121 document.warning("Malformed LyX document: Could not find end of space inset.")
2123 del document.body[j]
2124 subst = document.body[i].replace('\\begin_inset Space \\rightarrowfill{}', \
2125 '\\begin_inset ERT\nstatus collapsed\n\n' \
2126 '\\begin_layout Standard\n\n\n\\backslash\n' \
2127 'rightarrowfill{}\n\\end_layout\n\n\\end_inset\n\n')
2128 subst = subst.split('\n')
2129 document.body[i : i+1] = subst
2133 def revert_upbracefill(document):
2134 ' Revert \\begin_inset Space \\upbracefill{} to ERT '
2137 i = find_token(document.body, '\\begin_inset Space \\upbracefill{}', i)
2140 j = find_end_of_inset(document.body, i)
2142 document.warning("Malformed LyX document: Could not find end of space inset.")
2144 del document.body[j]
2145 subst = document.body[i].replace('\\begin_inset Space \\upbracefill{}', \
2146 '\\begin_inset ERT\nstatus collapsed\n\n' \
2147 '\\begin_layout Standard\n\n\n\\backslash\n' \
2148 'upbracefill{}\n\\end_layout\n\n\\end_inset\n\n')
2149 subst = subst.split('\n')
2150 document.body[i : i+1] = subst
2154 def revert_downbracefill(document):
2155 ' Revert \\begin_inset Space \\downbracefill{} to ERT '
2158 i = find_token(document.body, '\\begin_inset Space \\downbracefill{}', i)
2161 j = find_end_of_inset(document.body, i)
2163 document.warning("Malformed LyX document: Could not find end of space inset.")
2165 del document.body[j]
2166 subst = document.body[i].replace('\\begin_inset Space \\downbracefill{}', \
2167 '\\begin_inset ERT\nstatus collapsed\n\n' \
2168 '\\begin_layout Standard\n\n\n\\backslash\n' \
2169 'downbracefill{}\n\\end_layout\n\n\\end_inset\n\n')
2170 subst = subst.split('\n')
2171 document.body[i : i+1] = subst
2175 def revert_local_layout(document):
2176 ' Revert local layout headers.'
2179 i = find_token(document.header, "\\begin_local_layout", i)
2182 j = find_end_of(document.header, i, "\\begin_local_layout", "\\end_local_layout")
2184 # this should not happen
2186 document.header[i : j + 1] = []
2189 def convert_pagebreaks(document):
2190 ' Convert inline Newpage insets to new format '
2193 i = find_token(document.body, '\\newpage', i)
2196 document.body[i:i+1] = ['\\begin_inset Newpage newpage',
2200 i = find_token(document.body, '\\pagebreak', i)
2203 document.body[i:i+1] = ['\\begin_inset Newpage pagebreak',
2207 i = find_token(document.body, '\\clearpage', i)
2210 document.body[i:i+1] = ['\\begin_inset Newpage clearpage',
2214 i = find_token(document.body, '\\cleardoublepage', i)
2217 document.body[i:i+1] = ['\\begin_inset Newpage cleardoublepage',
2221 def revert_pagebreaks(document):
2222 ' Revert \\begin_inset Newpage to previous inline format '
2225 i = find_token(document.body, '\\begin_inset Newpage', i)
2228 j = find_end_of_inset(document.body, i)
2230 document.warning("Malformed LyX document: Could not find end of Newpage inset.")
2232 del document.body[j]
2233 document.body[i] = document.body[i].replace('\\begin_inset Newpage newpage', '\\newpage')
2234 document.body[i] = document.body[i].replace('\\begin_inset Newpage pagebreak', '\\pagebreak')
2235 document.body[i] = document.body[i].replace('\\begin_inset Newpage clearpage', '\\clearpage')
2236 document.body[i] = document.body[i].replace('\\begin_inset Newpage cleardoublepage', '\\cleardoublepage')
2239 def convert_linebreaks(document):
2240 ' Convert inline Newline insets to new format '
2243 i = find_token(document.body, '\\newline', i)
2246 document.body[i:i+1] = ['\\begin_inset Newline newline',
2250 i = find_token(document.body, '\\linebreak', i)
2253 document.body[i:i+1] = ['\\begin_inset Newline linebreak',
2257 def revert_linebreaks(document):
2258 ' Revert \\begin_inset Newline to previous inline format '
2261 i = find_token(document.body, '\\begin_inset Newline', i)
2264 j = find_end_of_inset(document.body, i)
2266 document.warning("Malformed LyX document: Could not find end of Newline inset.")
2268 del document.body[j]
2269 document.body[i] = document.body[i].replace('\\begin_inset Newline newline', '\\newline')
2270 document.body[i] = document.body[i].replace('\\begin_inset Newline linebreak', '\\linebreak')
2273 def convert_japanese_plain(document):
2274 ' Set language japanese-plain to japanese '
2276 if document.language == "japanese-plain":
2277 document.language = "japanese"
2278 i = find_token(document.header, "\\language", 0)
2280 document.header[i] = "\\language japanese"
2283 j = find_token(document.body, "\\lang japanese-plain", j)
2286 document.body[j] = document.body[j].replace("\\lang japanese-plain", "\\lang japanese")
2290 def revert_pdfpages(document):
2291 ' Revert pdfpages external inset to ERT '
2294 i = find_token(document.body, "\\begin_inset External", i)
2297 j = find_end_of_inset(document.body, i)
2299 document.warning("Malformed lyx document: Missing '\\end_inset'.")
2302 if get_value(document.body, 'template', i, j) == "PDFPages":
2303 filename = get_value(document.body, 'filename', i, j)
2305 r = re.compile(r'\textra PDFLaTeX \"(.*)\"$')
2306 for k in range(i, j):
2307 m = r.match(document.body[k])
2310 angle = get_value(document.body, 'rotateAngle', i, j)
2311 width = get_value(document.body, 'width', i, j)
2312 height = get_value(document.body, 'height', i, j)
2313 scale = get_value(document.body, 'scale', i, j)
2314 keepAspectRatio = find_token(document.body, "\tkeepAspectRatio", i, j)
2318 options += ",angle=" + angle
2320 options += "angle=" + angle
2323 options += ",width=" + convert_len(width)
2325 options += "width=" + convert_len(width)
2328 options += ",height=" + convert_len(height)
2330 options += "height=" + convert_len(height)
2333 options += ",scale=" + scale
2335 options += "scale=" + scale
2336 if keepAspectRatio != '':
2338 options += ",keepaspectratio"
2340 options += "keepaspectratio"
2342 options = '[' + options + ']'
2343 del document.body[i+1:j+1]
2344 document.body[i:i+1] = ['\\begin_inset ERT',
2347 '\\begin_layout Standard',
2350 'includepdf' + options + '{' + filename + '}',
2354 add_to_preamble(document, ['\\usepackage{pdfpages}\n'])
2360 def revert_mexican(document):
2361 ' Set language Spanish(Mexico) to Spanish '
2363 if document.language == "spanish-mexico":
2364 document.language = "spanish"
2365 i = find_token(document.header, "\\language", 0)
2367 document.header[i] = "\\language spanish"
2370 j = find_token(document.body, "\\lang spanish-mexico", j)
2373 document.body[j] = document.body[j].replace("\\lang spanish-mexico", "\\lang spanish")
2377 def remove_embedding(document):
2378 ' Remove embed tag from all insets '
2379 revert_inset_embedding(document, 'Graphics')
2380 revert_inset_embedding(document, 'External')
2381 revert_inset_embedding(document, 'CommandInset include')
2382 revert_inset_embedding(document, 'CommandInset bibtex')
2385 def revert_master(document):
2386 ' Remove master param '
2387 i = find_token(document.header, "\\master", 0)
2389 del document.header[i]
2392 def revert_graphics_group(document):
2393 ' Revert group information from graphics insets '
2396 i = find_token(document.body, "\\begin_inset Graphics", i)
2399 j = find_end_of_inset(document.body, i)
2401 document.warning("Malformed lyx document: Missing '\\end_inset'.")
2404 k = find_token(document.body, " groupId", i, j)
2408 del document.body[k]
2412 def update_apa_styles(document):
2413 ' Replace obsolete styles '
2415 if document.textclass != "apa":
2418 obsoletedby = { "Acknowledgments": "Acknowledgements",
2419 "Section*": "Section",
2420 "Subsection*": "Subsection",
2421 "Subsubsection*": "Subsubsection",
2422 "Paragraph*": "Paragraph",
2423 "Subparagraph*": "Subparagraph"}
2426 i = find_token(document.body, "\\begin_layout", i)
2430 layout = document.body[i][14:]
2431 if layout in obsoletedby:
2432 document.body[i] = "\\begin_layout " + obsoletedby[layout]
2437 def convert_paper_sizes(document):
2438 ' exchange size options legalpaper and executivepaper to correct order '
2439 # routine is needed to fix http://bugzilla.lyx.org/show_bug.cgi?id=4868
2442 i = find_token(document.header, "\\papersize executivepaper", 0)
2444 document.header[i] = "\\papersize legalpaper"
2446 j = find_token(document.header, "\\papersize legalpaper", 0)
2448 document.header[j] = "\\papersize executivepaper"
2451 def revert_paper_sizes(document):
2452 ' exchange size options legalpaper and executivepaper to correct order '
2455 i = find_token(document.header, "\\papersize executivepaper", 0)
2457 document.header[i] = "\\papersize legalpaper"
2459 j = find_token(document.header, "\\papersize legalpaper", 0)
2461 document.header[j] = "\\papersize executivepaper"
2464 def convert_InsetSpace(document):
2465 " Convert '\\begin_inset Space foo' to '\\begin_inset space foo'"
2468 i = find_token(document.body, "\\begin_inset Space", i)
2471 document.body[i] = document.body[i].replace('\\begin_inset Space', '\\begin_inset space')
2474 def revert_InsetSpace(document):
2475 " Revert '\\begin_inset space foo' to '\\begin_inset Space foo'"
2478 i = find_token(document.body, "\\begin_inset space", i)
2481 document.body[i] = document.body[i].replace('\\begin_inset space', '\\begin_inset Space')
2488 supported_versions = ["1.6.0","1.6"]
2489 convert = [[277, [fix_wrong_tables]],
2490 [278, [close_begin_deeper]],
2491 [279, [long_charstyle_names]],
2492 [280, [axe_show_label]],
2495 [283, [convert_flex]],
2499 [287, [convert_wrapfig_options]],
2500 [288, [convert_inset_command]],
2501 [289, [convert_latexcommand_index]],
2506 [294, [convert_pdf_options]],
2507 [295, [convert_htmlurl, convert_url]],
2508 [296, [convert_include]],
2509 [297, [convert_usorbian]],
2515 [303, [convert_serbocroatian]],
2516 [304, [convert_framed_notes]],
2523 [311, [convert_ams_classes]],
2525 [313, [convert_module_names]],
2528 [316, [convert_subfig]],
2531 [319, [convert_spaceinset, convert_hfill]],
2533 [321, [convert_tablines]],
2535 [323, [convert_pagebreaks]],
2536 [324, [convert_linebreaks]],
2537 [325, [convert_japanese_plain]],
2540 [328, [remove_embedding, remove_extra_embedded_files, remove_inzip_options]],
2543 [331, [convert_ltcaption]],
2545 [333, [update_apa_styles]],
2546 [334, [convert_paper_sizes]],
2547 [335, [convert_InsetSpace]],
2550 revert = [[334, [revert_InsetSpace]],
2551 [333, [revert_paper_sizes]],
2553 [331, [revert_graphics_group]],
2554 [330, [revert_ltcaption]],
2555 [329, [revert_leftarrowfill, revert_rightarrowfill, revert_upbracefill, revert_downbracefill]],
2556 [328, [revert_master]],
2558 [326, [revert_mexican]],
2559 [325, [revert_pdfpages]],
2561 [323, [revert_linebreaks]],
2562 [322, [revert_pagebreaks]],
2563 [321, [revert_local_layout]],
2564 [320, [revert_tablines]],
2565 [319, [revert_protected_hfill]],
2566 [318, [revert_spaceinset, revert_hfills, revert_hspace]],
2567 [317, [remove_extra_embedded_files]],
2568 [316, [revert_wrapplacement]],
2569 [315, [revert_subfig]],
2570 [314, [revert_colsep]],
2572 [312, [revert_module_names]],
2573 [311, [revert_rotfloat, revert_widesideways]],
2574 [310, [revert_external_embedding]],
2575 [309, [revert_btprintall]],
2576 [308, [revert_nocite]],
2577 [307, [revert_serbianlatin]],
2578 [306, [revert_slash, revert_nobreakdash]],
2579 [305, [revert_interlingua]],
2580 [304, [revert_bahasam]],
2581 [303, [revert_framed_notes]],
2583 [301, [revert_latin, revert_samin]],
2584 [300, [revert_linebreak]],
2585 [299, [revert_pagebreak]],
2586 [298, [revert_hyperlinktype]],
2587 [297, [revert_macro_optional_params]],
2588 [296, [revert_albanian, revert_lowersorbian, revert_uppersorbian]],
2589 [295, [revert_include]],
2590 [294, [revert_href]],
2591 [293, [revert_pdf_options_2]],
2592 [292, [revert_inset_info]],
2593 [291, [revert_japanese, revert_japanese_encoding]],
2594 [290, [revert_vietnamese]],
2595 [289, [revert_wraptable]],
2596 [288, [revert_latexcommand_index]],
2597 [287, [revert_inset_command]],
2598 [286, [revert_wrapfig_options]],
2599 [285, [revert_pdf_options]],
2600 [284, [remove_inzip_options]],
2602 [282, [revert_flex]],
2604 [280, [revert_begin_modules]],
2605 [279, [revert_show_label]],
2606 [278, [revert_long_charstyle_names]],
2612 if __name__ == "__main__":