1 # -*- coding: utf-8 -*-
2 # This file is part of lyx2lyx
3 # -*- coding: utf-8 -*-
4 # Copyright (C) 2011 The LyX team
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 """ Convert files to the file format generated by lyx 2.0"""
26 from parser_tools import find_token, find_end_of, find_tokens, \
27 find_token_exact, find_end_of_inset, find_end_of_layout, \
28 find_token_backwards, is_in_inset, get_value, get_quoted_value, \
29 del_token, check_token, get_option_value
31 from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \
32 put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
33 revert_font_attrs, hex2ratio, str2bool
35 ####################################################################
36 # Private helper functions
38 def remove_option(lines, m, option):
39 ''' removes option from line m. returns whether we did anything '''
40 l = lines[m].find(option)
43 val = lines[m][l:].split('"')[1]
44 lines[m] = lines[m][:l - 1] + lines[m][l+len(option + '="' + val + '"'):]
48 ###############################################################################
50 ### Conversion and reversion routines
52 ###############################################################################
54 def revert_swiss(document):
55 " Set language german-ch to ngerman "
57 if document.language == "german-ch":
58 document.language = "ngerman"
59 i = find_token(document.header, "\\language", 0)
61 document.header[i] = "\\language ngerman"
64 j = find_token(document.body, "\\lang german-ch", j)
67 document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
71 def revert_tabularvalign(document):
72 " Revert the tabular valign option "
75 i = find_token(document.body, "\\begin_inset Tabular", i)
78 end = find_end_of_inset(document.body, i)
80 document.warning("Can't find end of inset at line " + str(i))
83 fline = find_token(document.body, "<features", i, end)
85 document.warning("Can't find features for inset at line " + str(i))
88 p = document.body[fline].find("islongtable")
90 q = document.body[fline].find("tabularvalignment")
92 document.body[fline] = re.sub(r' tabularvalignment=\"[a-z]+\"', "", document.body[fline])
97 tabularvalignment = 'c'
98 # which valignment is specified?
99 m = document.body[fline].find('tabularvalignment="top"')
101 tabularvalignment = 't'
102 m = document.body[fline].find('tabularvalignment="bottom"')
104 tabularvalignment = 'b'
105 # delete tabularvalignment
106 q = document.body[fline].find("tabularvalignment")
108 document.body[fline] = re.sub(r' tabularvalignment=\"[a-z]+\"', "", document.body[fline])
110 # don't add a box when centered
111 if tabularvalignment == 'c':
114 subst = ['\\end_inset', '\\end_layout']
115 document.body[end:end] = subst # just inserts those lines
116 subst = ['\\begin_inset Box Frameless',
117 'position "' + tabularvalignment +'"',
122 # we don't know the width, assume 50%
126 'height_special "totalheight"',
129 '\\begin_layout Plain Layout']
130 document.body[i:i] = subst # this just inserts the array at i
131 # since there could be a tabular inside a tabular, we cannot
136 def revert_phantom_types(document, ptype, cmd):
137 " Reverts phantom to ERT "
140 i = find_token(document.body, "\\begin_inset Phantom " + ptype, i)
143 end = find_end_of_inset(document.body, i)
145 document.warning("Can't find end of inset at line " + str(i))
148 blay = find_token(document.body, "\\begin_layout Plain Layout", i, end)
150 document.warning("Can't find layout for inset at line " + str(i))
153 bend = find_end_of_layout(document.body, blay)
155 document.warning("Malformed LyX document: Could not find end of Phantom inset's layout.")
158 substi = ["\\begin_inset ERT", "status collapsed", "",
159 "\\begin_layout Plain Layout", "", "", "\\backslash",
160 cmd + "{", "\\end_layout", "", "\\end_inset"]
161 substj = ["\\size default", "", "\\begin_inset ERT", "status collapsed", "",
162 "\\begin_layout Plain Layout", "", "}", "\\end_layout", "", "\\end_inset"]
163 # do the later one first so as not to mess up the numbering
164 document.body[bend:end + 1] = substj
165 document.body[i:blay + 1] = substi
166 i = end + len(substi) + len(substj) - (end - bend) - (blay - i) - 2
169 def revert_phantom(document):
170 revert_phantom_types(document, "Phantom", "phantom")
172 def revert_hphantom(document):
173 revert_phantom_types(document, "HPhantom", "hphantom")
175 def revert_vphantom(document):
176 revert_phantom_types(document, "VPhantom", "vphantom")
179 def revert_xetex(document):
180 " Reverts documents that use XeTeX "
182 i = find_token(document.header, '\\use_xetex', 0)
184 document.warning("Malformed LyX document: Missing \\use_xetex.")
186 if not str2bool(get_value(document.header, "\\use_xetex", i)):
187 del document.header[i]
189 del document.header[i]
191 # 1.) set doc encoding to utf8-plain
192 i = find_token(document.header, "\\inputencoding", 0)
194 document.warning("Malformed LyX document: Missing \\inputencoding.")
196 document.header[i] = "\\inputencoding utf8-plain"
198 # 2.) check font settings
200 roman = sans = typew = "default"
202 sf_scale = tt_scale = 100.0
204 i = find_token(document.header, "\\font_roman", 0)
206 document.warning("Malformed LyX document: Missing \\font_roman.")
208 roman = get_value(document.header, "\\font_roman", i)
209 document.header[i] = "\\font_roman default"
211 i = find_token(document.header, "\\font_sans", 0)
213 document.warning("Malformed LyX document: Missing \\font_sans.")
215 sans = get_value(document.header, "\\font_sans", i)
216 document.header[i] = "\\font_sans default"
218 i = find_token(document.header, "\\font_typewriter", 0)
220 document.warning("Malformed LyX document: Missing \\font_typewriter.")
222 typew = get_value(document.header, "\\font_typewriter", i)
223 document.header[i] = "\\font_typewriter default"
225 i = find_token(document.header, "\\font_osf", 0)
227 document.warning("Malformed LyX document: Missing \\font_osf.")
229 osf = str2bool(get_value(document.header, "\\font_osf", i))
230 document.header[i] = "\\font_osf false"
232 i = find_token(document.header, "\\font_sc", 0)
234 document.warning("Malformed LyX document: Missing \\font_sc.")
236 # we do not need this value.
237 document.header[i] = "\\font_sc false"
239 i = find_token(document.header, "\\font_sf_scale", 0)
241 document.warning("Malformed LyX document: Missing \\font_sf_scale.")
243 val = get_value(document.header, '\\font_sf_scale', i)
246 sf_scale = float(val)
248 document.warning("Invalid font_sf_scale value: " + val)
249 document.header[i] = "\\font_sf_scale 100"
251 i = find_token(document.header, "\\font_tt_scale", 0)
253 document.warning("Malformed LyX document: Missing \\font_tt_scale.")
255 val = get_value(document.header, '\\font_tt_scale', i)
258 tt_scale = float(val)
260 document.warning("Invalid font_tt_scale value: " + val)
261 document.header[i] = "\\font_tt_scale 100"
263 # 3.) set preamble stuff
264 pretext = ['%% This document must be processed with xelatex!']
265 pretext.append('\\usepackage{fontspec}')
266 if roman != "default":
267 pretext.append('\\setmainfont[Mapping=tex-text]{' + roman + '}')
268 if sans != "default":
269 sf = '\\setsansfont['
270 if sf_scale != 100.0:
271 sf += 'Scale=' + str(sf_scale / 100.0) + ','
272 sf += 'Mapping=tex-text]{' + sans + '}'
274 if typew != "default":
276 if tt_scale != 100.0:
277 tw += '[Scale=' + str(tt_scale / 100.0) + ']'
278 tw += '{' + typew + '}'
281 pretext.append('\\defaultfontfeatures{Numbers=OldStyle}')
282 pretext.append('\\usepackage{xunicode}')
283 pretext.append('\\usepackage{xltxtra}')
284 insert_to_preamble(document, pretext)
287 def revert_outputformat(document):
288 " Remove default output format param "
290 if not del_token(document.header, '\\default_output_format', 0):
291 document.warning("Malformed LyX document: Missing \\default_output_format.")
294 def revert_backgroundcolor(document):
295 " Reverts background color to preamble code "
296 i = find_token(document.header, "\\backgroundcolor", 0)
299 colorcode = get_value(document.header, '\\backgroundcolor', i)
300 del document.header[i]
301 # don't clutter the preamble if backgroundcolor is not set
302 if colorcode == "#ffffff":
304 red = hex2ratio(colorcode[1:3])
305 green = hex2ratio(colorcode[3:5])
306 blue = hex2ratio(colorcode[5:7])
307 insert_to_preamble(document, \
308 ['% To set the background color',
309 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
310 '\\definecolor{page_backgroundcolor}{rgb}{' + red + ',' + green + ',' + blue + '}',
311 '\\pagecolor{page_backgroundcolor}'])
314 def add_use_indices(document):
315 " Add \\use_indices if it is missing "
316 i = find_token(document.header, '\\use_indices', 0)
319 i = find_token(document.header, '\\use_bibtopic', 0)
321 i = find_token(document.header, '\\cite_engine', 0)
323 i = find_token(document.header, '\\use_mathdots', 0)
325 i = find_token(document.header, '\\use_mhchem', 0)
327 i = find_token(document.header, '\\use_esint', 0)
329 i = find_token(document.header, '\\use_amsmath', 0)
331 document.warning("Malformed LyX document: Missing \\use_indices.")
333 document.header.insert(i + 1, '\\use_indices 0')
337 def revert_splitindex(document):
338 " Reverts splitindex-aware documents "
339 i = add_use_indices(document)
342 useindices = str2bool(get_value(document.header, "\\use_indices", i))
343 del document.header[i]
346 preamble.append("\\usepackage{splitidx})")
348 # deal with index declarations in the preamble
351 i = find_token(document.header, "\\index", i)
354 k = find_token(document.header, "\\end_index", i)
356 document.warning("Malformed LyX document: Missing \\end_index.")
359 line = document.header[i]
360 l = re.compile(r'\\index (.*)$')
363 ishortcut = get_value(document.header, '\\shortcut', i, k)
365 preamble.append("\\newindex[" + iname + "]{" + ishortcut + "}")
366 del document.header[i:k + 1]
368 insert_to_preamble(document, preamble)
370 # deal with index insets
371 # these need to have the argument removed
374 i = find_token(document.body, "\\begin_inset Index", i)
377 line = document.body[i]
378 l = re.compile(r'\\begin_inset Index (.*)$')
381 if itype == "idx" or indices == "false":
382 document.body[i] = "\\begin_inset Index"
384 k = find_end_of_inset(document.body, i)
386 document.warning("Can't find end of index inset!")
389 content = lyx2latex(document, document.body[i:k])
391 content = content.replace('"', r'\"')
392 subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
393 document.body[i:k + 1] = subst
396 # deal with index_print insets
399 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
402 k = find_end_of_inset(document.body, i)
403 ptype = get_quoted_value(document.body, 'type', i, k)
405 j = find_token(document.body, "type", i, k)
408 del document.body[i:k + 1]
410 subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
411 document.body[i:k + 1] = subst
415 def convert_splitindex(document):
416 " Converts index and printindex insets to splitindex-aware format "
417 add_use_indices(document)
420 i = find_token(document.body, "\\begin_inset Index", i)
423 document.body[i] = document.body[i].replace("\\begin_inset Index",
424 "\\begin_inset Index idx")
428 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
431 if document.body[i + 1].find('LatexCommand printindex') == -1:
432 document.warning("Malformed LyX document: Incomplete printindex inset.")
434 subst = ["LatexCommand printindex",
436 document.body[i + 1:i + 2] = subst
440 def revert_subindex(document):
441 " Reverts \\printsubindex CommandInset types "
442 i = add_use_indices(document)
445 useindices = str2bool(get_value(document.header, "\\use_indices", i))
448 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
451 k = find_end_of_inset(document.body, i)
452 ctype = get_value(document.body, 'LatexCommand', i, k)
453 if ctype != "printsubindex":
456 ptype = get_quoted_value(document.body, 'type', i, k)
458 del document.body[i:k + 1]
460 subst = put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")
461 document.body[i:k + 1] = subst
465 def revert_printindexall(document):
466 " Reverts \\print[sub]index* CommandInset types "
467 i = add_use_indices(document)
470 useindices = str2bool(get_value(document.header, "\\use_indices", i))
473 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
476 k = find_end_of_inset(document.body, i)
477 ctype = get_value(document.body, 'LatexCommand', i, k)
478 if ctype != "printindex*" and ctype != "printsubindex*":
482 del document.body[i:k + 1]
484 subst = put_cmd_in_ert("\\" + ctype + "{}")
485 document.body[i:k + 1] = subst
489 def revert_strikeout(document):
490 " Reverts \\strikeout font attribute "
491 changed = revert_font_attrs(document.body, "\\uuline", "\\uuline")
492 changed = revert_font_attrs(document.body, "\\uwave", "\\uwave") or changed
493 changed = revert_font_attrs(document.body, "\\strikeout", "\\sout") or changed
495 insert_to_preamble(document, \
496 ['% for proper underlining',
497 '\\PassOptionsToPackage{normalem}{ulem}',
498 '\\usepackage{ulem}'])
501 def revert_ulinelatex(document):
502 " Reverts \\uline font attribute "
503 i = find_token(document.body, '\\bar under', 0)
506 insert_to_preamble(document,\
507 ['% for proper underlining',
508 '\\PassOptionsToPackage{normalem}{ulem}',
509 '\\usepackage{ulem}',
510 '\\let\\cite@rig\\cite',
511 '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}',
512 ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}',
513 '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}'])
516 def revert_custom_processors(document):
517 " Remove bibtex_command and index_command params "
519 if not del_token(document.header, '\\bibtex_command', 0):
520 document.warning("Malformed LyX document: Missing \\bibtex_command.")
522 if not del_token(document.header, '\\index_command', 0):
523 document.warning("Malformed LyX document: Missing \\index_command.")
526 def convert_nomencl_width(document):
527 " Add set_width param to nomencl_print "
530 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
533 document.body.insert(i + 2, "set_width \"none\"")
537 def revert_nomencl_width(document):
538 " Remove set_width param from nomencl_print "
541 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
544 j = find_end_of_inset(document.body, i)
545 if not del_token(document.body, "set_width", i, j):
546 document.warning("Can't find set_width option for nomencl_print!")
550 def revert_nomencl_cwidth(document):
551 " Remove width param from nomencl_print "
554 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
557 j = find_end_of_inset(document.body, i)
558 l = find_token(document.body, "width", i, j)
562 width = get_quoted_value(document.body, "width", i, j)
564 insert_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
568 def revert_applemac(document):
569 " Revert applemac encoding to auto "
570 if document.encoding != "applemac":
572 document.encoding = "auto"
573 i = find_token(document.header, "\\encoding", 0)
575 document.header[i] = "\\encoding auto"
578 def revert_longtable_align(document):
579 " Remove longtable alignment setting "
582 i = find_token(document.body, "\\begin_inset Tabular", i)
585 end = find_end_of_inset(document.body, i)
587 document.warning("Can't find end of inset at line " + str(i))
590 fline = find_token(document.body, "<features", i, end)
592 document.warning("Can't find features for inset at line " + str(i))
595 j = document.body[fline].find("longtabularalignment")
599 # FIXME Is this correct? It wipes out everything after the
601 document.body[fline] = document.body[fline][:j - 1] + '>'
602 # since there could be a tabular inside this one, we
603 # cannot jump to end.
607 def revert_branch_filename(document):
608 " Remove \\filename_suffix parameter from branches "
611 i = find_token(document.header, "\\filename_suffix", i)
614 del document.header[i]
617 def revert_paragraph_indentation(document):
618 " Revert custom paragraph indentation to preamble code "
619 i = find_token(document.header, "\\paragraph_indentation", 0)
622 length = get_value(document.header, "\\paragraph_indentation", i)
623 # we need only remove the line if indentation is default
624 if length != "default":
625 # handle percent lengths
626 length = latex_length(length)[1]
627 insert_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
628 del document.header[i]
631 def revert_percent_skip_lengths(document):
632 " Revert relative lengths for paragraph skip separation to preamble code "
633 i = find_token(document.header, "\\defskip", 0)
636 length = get_value(document.header, "\\defskip", i)
637 # only revert when a custom length was set and when
638 # it used a percent length
639 if length in ('smallskip', 'medskip', 'bigskip'):
641 # handle percent lengths
642 percent, length = latex_length(length)
644 insert_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
645 # set defskip to medskip as default
646 document.header[i] = "\\defskip medskip"
649 def revert_percent_vspace_lengths(document):
650 " Revert relative VSpace lengths to ERT "
653 i = find_token(document.body, "\\begin_inset VSpace", i)
656 # only revert if a custom length was set and if
657 # it used a percent length
658 r = re.compile(r'\\begin_inset VSpace (.*)$')
659 m = r.match(document.body[i])
661 if length in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
664 # check if the space has a star (protected space)
665 protected = (document.body[i].rfind("*") != -1)
667 length = length.rstrip('*')
668 # handle percent lengths
669 percent, length = latex_length(length)
670 # revert the VSpace inset to ERT
673 subst = put_cmd_in_ert("\\vspace*{" + length + "}")
675 subst = put_cmd_in_ert("\\vspace{" + length + "}")
676 document.body[i:i + 2] = subst
680 def revert_percent_hspace_lengths(document):
681 " Revert relative HSpace lengths to ERT "
684 i = find_token_exact(document.body, "\\begin_inset space \\hspace", i)
687 j = find_end_of_inset(document.body, i)
689 document.warning("Can't find end of inset at line " + str(i))
692 # only revert if a custom length was set...
693 length = get_value(document.body, '\\length', i + 1, j)
695 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
699 if document.body[i].find("\\hspace*{}") != -1:
701 # ...and if it used a percent length
702 percent, length = latex_length(length)
703 # revert the HSpace inset to ERT
705 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
706 document.body[i:j + 1] = subst
707 # if we did a substitution, this will still be ok
711 def revert_hspace_glue_lengths(document):
712 " Revert HSpace glue lengths to ERT "
715 i = find_token_exact(document.body, "\\begin_inset space \\hspace", i)
718 j = find_end_of_inset(document.body, i)
720 document.warning("Can't find end of inset at line " + str(i))
723 length = get_value(document.body, '\\length', i + 1, j)
725 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
729 if document.body[i].find("\\hspace*{}") != -1:
731 # only revert if the length contains a plus or minus at pos != 0
732 if length.find('-',1) != -1 or length.find('+',1) != -1:
733 # handle percent lengths
734 length = latex_length(length)[1]
735 # revert the HSpace inset to ERT
736 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
737 document.body[i:j+1] = subst
741 def convert_author_id(document):
742 " Add the author_id to the \\author definition and make sure 0 is not used"
745 re_author = re.compile(r'(\\author) (\".*\")\s*(.*)$')
748 i = find_token(document.header, "\\author", i)
751 m = re_author.match(document.header[i])
755 document.header[i] = "\\author %i %s %s" % (anum, name, email)
761 i = find_token(document.body, "\\change_", i)
764 change = document.body[i].split(' ');
767 author_id = int(change[1])
769 document.body[i] = "%s %i %s" % (type, author_id + 1, time)
773 def revert_author_id(document):
774 " Remove the author_id from the \\author definition "
777 rx = re.compile(r'(\\author)\s+(-?\d+)\s+(\".*\")\s*(.*)$')
781 i = find_token(document.header, "\\author", i)
784 m = rx.match(document.header[i])
786 author_id = int(m.group(2))
787 idmap[author_id] = anum
790 document.header[i] = "\\author %s %s" % (name, email)
792 # FIXME Should this be incremented if we didn't match?
797 i = find_token(document.body, "\\change_", i)
800 change = document.body[i].split(' ');
803 author_id = int(change[1])
805 document.body[i] = "%s %i %s" % (type, idmap[author_id], time)
809 def revert_suppress_date(document):
810 " Revert suppressing of default document date to preamble code "
811 i = find_token(document.header, "\\suppress_date", 0)
814 # remove the preamble line and write to the preamble
815 # when suppress_date was true
816 date = str2bool(get_value(document.header, "\\suppress_date", i))
818 add_to_preamble(document, ["\\date{}"])
819 del document.header[i]
822 def convert_mhchem(document):
823 "Set mhchem to off for versions older than 1.6.x"
824 if document.start < 277:
825 # LyX 1.5.x and older did never load mhchem.
826 # Therefore we must switch it off: Documents that use mhchem have
827 # a manual \usepackage anyway, and documents not using mhchem but
828 # custom macros with the same names as mhchem commands might get
829 # corrupted if mhchem is automatically loaded.
832 # LyX 1.6.x did always load mhchem automatically.
834 i = find_token(document.header, "\\use_esint", 0)
837 i = find_token(document.header, "\\use_amsmath", 0)
839 document.warning("Malformed LyX document: Could not find amsmath os esint setting.")
841 document.header.insert(i + 1, "\\use_mhchem %d" % mhchem)
844 def revert_mhchem(document):
845 "Revert mhchem loading to preamble code"
848 i = find_token(document.header, "\\use_mhchem", 0)
850 document.warning("Malformed LyX document: Could not find mhchem setting.")
853 val = get_value(document.header, "\\use_mhchem", i)
858 del document.header[i]
867 i = find_token(document.body, "\\begin_inset Formula", i)
870 line = document.body[i]
871 if line.find("\\ce{") != -1 or line.find("\\cf{") != -1:
877 pre = ["\\PassOptionsToPackage{version=3}{mhchem}",
878 "\\usepackage{mhchem}"]
879 insert_to_preamble(document, pre)
882 def revert_fontenc(document):
883 " Remove fontencoding param "
884 if not del_token(document.header, '\\fontencoding', 0):
885 document.warning("Malformed LyX document: Missing \\fontencoding.")
888 def merge_gbrief(document):
889 " Merge g-brief-en and g-brief-de to one class "
891 if document.textclass != "g-brief-de":
892 if document.textclass == "g-brief-en":
893 document.textclass = "g-brief"
894 document.set_textclass()
897 obsoletedby = { "Brieftext": "Letter",
898 "Unterschrift": "Signature",
900 "Zusatz": "Addition",
903 "RetourAdresse": "ReturnAddress",
904 "MeinZeichen": "MyRef",
905 "IhrZeichen": "YourRef",
906 "IhrSchreiben": "YourMail",
909 "Konto": "BankAccount",
910 "Postvermerk": "PostalComment",
911 "Adresse": "Address",
913 "Betreff": "Reference",
920 i = find_token(document.body, "\\begin_layout", i)
924 layout = document.body[i][14:]
925 if layout in obsoletedby:
926 document.body[i] = "\\begin_layout " + obsoletedby[layout]
930 document.textclass = "g-brief"
931 document.set_textclass()
934 def revert_gbrief(document):
935 " Revert g-brief to g-brief-en "
936 if document.textclass == "g-brief":
937 document.textclass = "g-brief-en"
938 document.set_textclass()
941 def revert_html_options(document):
942 " Remove html options "
943 del_token(document.header, '\\html_use_mathml', 0)
944 del_token(document.header, '\\html_be_strict', 0)
947 def revert_includeonly(document):
950 i = find_token(document.header, "\\begin_includeonly", i)
953 j = find_end_of(document.header, i, "\\begin_includeonly", "\\end_includeonly")
955 document.warning("Unable to find end of includeonly section!!")
957 document.header[i : j + 1] = []
960 def revert_includeall(document):
961 " Remove maintain_unincluded_children param "
962 del_token(document.header, '\\maintain_unincluded_children', 0)
965 def revert_multirow(document):
966 " Revert multirow cells in tables to TeX-code"
968 # first, let's find out if we need to do anything
969 # cell type 3 is multirow begin cell
970 i = find_token(document.body, '<cell multirow="3"', 0)
974 add_to_preamble(document, ["\\usepackage{multirow}"])
978 # find begin/end of table
979 begin_table = find_token(document.body, '<lyxtabular version=', begin_table)
980 if begin_table == -1:
982 end_table = find_end_of(document.body, begin_table, '<lyxtabular', '</lyxtabular>')
984 document.warning("Malformed LyX document: Could not find end of table.")
987 # does this table have multirow?
988 i = find_token(document.body, '<cell multirow="3"', begin_table, end_table)
990 begin_table = end_table
993 # store the number of rows and columns
994 numrows = get_option_value(document.body[begin_table], "rows")
995 numcols = get_option_value(document.body[begin_table], "columns")
997 numrows = int(numrows)
998 numcols = int(numcols)
1000 document.warning("Unable to determine rows and columns!")
1001 begin_table = end_table
1006 # collect info on rows and columns of this table.
1007 begin_row = begin_table
1008 for row in range(numrows):
1009 begin_row = find_token(document.body, '<row>', begin_row, end_table)
1011 document.warning("Can't find row " + str(row + 1))
1013 end_row = find_end_of(document.body, begin_row, '<row>', '</row>')
1015 document.warning("Can't find end of row " + str(row + 1))
1017 begin_cell = begin_row
1018 multirows.append([])
1019 for column in range(numcols):
1020 begin_cell = find_token(document.body, '<cell ', begin_cell, end_row)
1021 if begin_cell == -1:
1022 document.warning("Can't find column " + str(column + 1) + \
1023 "in row " + str(row + 1))
1026 # this will fail if someone puts "</cell>" in a cell, but
1027 # that seems fairly unlikely.
1028 end_cell = find_end_of(document.body, begin_cell, '<cell', '</cell>')
1030 document.warning("Can't find end of column " + str(column + 1) + \
1031 "in row " + str(row + 1))
1033 multirows[row].append([begin_cell, end_cell, 0])
1034 if document.body[begin_cell].find('multirow="3"') != -1:
1035 multirows[row][column][2] = 3 # begin multirow
1036 mrstarts.append([row, column])
1037 elif document.body[begin_cell].find('multirow="4"') != -1:
1038 multirows[row][column][2] = 4 # in multirow
1039 begin_cell = end_cell
1041 # end of table info collection
1043 # work from the back to avoid messing up numbering
1049 col_width = get_option_value(document.body[begin_table + 2 + col], "width")
1050 # "0pt" means that no width is specified
1051 if not col_width or col_width == "0pt":
1053 # determine the number of cells that are part of the multirow
1055 for r in range(row + 1, numrows):
1056 if multirows[r][col][2] != 4:
1059 # take the opportunity to revert this line
1060 lineno = multirows[r][col][0]
1061 document.body[lineno] = document.body[lineno].\
1062 replace(' multirow="4" ', ' ').\
1063 replace('valignment="middle"', 'valignment="top"').\
1064 replace(' topline="true" ', ' ')
1065 # remove bottom line of previous multirow-part cell
1066 lineno = multirows[r-1][col][0]
1067 document.body[lineno] = document.body[lineno].replace(' bottomline="true" ', ' ')
1068 # revert beginning cell
1069 bcell = multirows[row][col][0]
1070 ecell = multirows[row][col][1]
1071 document.body[bcell] = document.body[bcell].\
1072 replace(' multirow="3" ', ' ').\
1073 replace('valignment="middle"', 'valignment="top"')
1074 blay = find_token(document.body, "\\begin_layout", bcell, ecell)
1076 document.warning("Can't find layout for cell!")
1078 bend = find_end_of_layout(document.body, blay)
1080 document.warning("Can't find end of layout for cell!")
1082 # do the later one first, so as not to mess up the numbering
1083 # we are wrapping the whole cell in this ert
1084 # so before the end of the layout...
1085 document.body[bend:bend] = put_cmd_in_ert("}")
1086 # ...and after the beginning
1087 document.body[blay + 1:blay + 1] = \
1088 put_cmd_in_ert("\\multirow{" + str(nummrs) + "}{" + col_width + "}{")
1090 begin_table = end_table
1093 def convert_math_output(document):
1094 " Convert \html_use_mathml to \html_math_output "
1095 i = find_token(document.header, "\\html_use_mathml", 0)
1098 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1099 m = rgx.match(document.header[i])
1100 newval = "0" # MathML
1102 val = str2bool(m.group(1))
1104 newval = "2" # Images
1106 document.warning("Can't match " + document.header[i])
1107 document.header[i] = "\\html_math_output " + newval
1110 def revert_math_output(document):
1111 " Revert \html_math_output to \html_use_mathml "
1112 i = find_token(document.header, "\\html_math_output", 0)
1115 rgx = re.compile(r'\\html_math_output\s+(\d)')
1116 m = rgx.match(document.header[i])
1120 if val == "1" or val == "2":
1123 document.warning("Unable to match " + document.header[i])
1124 document.header[i] = "\\html_use_mathml " + newval
1128 def revert_inset_preview(document):
1129 " Dissolves the preview inset "
1132 i = find_token(document.body, "\\begin_inset Preview", i)
1135 iend = find_end_of_inset(document.body, i)
1137 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1141 # This has several issues.
1142 # We need to do something about the layouts inside InsetPreview.
1143 # If we just leave the first one, then we have something like:
1144 # \begin_layout Standard
1146 # \begin_layout Standard
1147 # and we get a "no \end_layout" error. So something has to be done.
1148 # Ideally, we would check if it is the same as the layout we are in.
1149 # If so, we just remove it; if not, we end the active one. But it is
1150 # not easy to know what layout we are in, due to depth changes, etc,
1151 # and it is not clear to me how much work it is worth doing. In most
1152 # cases, the layout will probably be the same.
1154 # For the same reason, we have to remove the \end_layout tag at the
1155 # end of the last layout in the inset. Again, that will sometimes be
1156 # wrong, but it will usually be right. To know what to do, we would
1157 # again have to know what layout the inset is in.
1159 blay = find_token(document.body, "\\begin_layout", i, iend)
1161 document.warning("Can't find layout for preview inset!")
1162 # always do the later one first...
1163 del document.body[iend]
1164 del document.body[i]
1165 # deletions mean we do not need to reset i
1168 # This is where we would check what layout we are in.
1169 # The check for Standard is definitely wrong.
1171 # lay = document.body[blay].split(None, 1)[1]
1172 # if lay != oldlayout:
1173 # # record a boolean to tell us what to do later....
1174 # # better to do it later, since (a) it won't mess up
1175 # # the numbering and (b) we only modify at the end.
1177 # we want to delete the last \\end_layout in this inset, too.
1178 # note that this may not be the \\end_layout that goes with blay!!
1179 bend = find_end_of_layout(document.body, blay)
1181 tmp = find_token(document.body, "\\end_layout", bend + 1, iend)
1186 document.warning("Unable to find last layout in preview inset!")
1187 del document.body[iend]
1188 del document.body[i]
1189 # deletions mean we do not need to reset i
1191 # always do the later one first...
1192 del document.body[iend]
1193 del document.body[bend]
1194 del document.body[i:blay + 1]
1195 # we do not need to reset i
1198 def revert_equalspacing_xymatrix(document):
1199 " Revert a Formula with xymatrix@! to an ERT inset "
1201 has_preamble = False
1202 has_equal_spacing = False
1205 i = find_token(document.body, "\\begin_inset Formula", i)
1208 j = find_end_of_inset(document.body, i)
1210 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1214 for curline in range(i,j):
1215 found = document.body[curline].find("\\xymatrix@!")
1220 has_equal_spacing = True
1221 content = [document.body[i][21:]]
1222 content += document.body[i + 1:j]
1223 subst = put_cmd_in_ert(content)
1224 document.body[i:j + 1] = subst
1225 i += len(subst) - (j - i) + 1
1227 for curline in range(i,j):
1228 l = document.body[curline].find("\\xymatrix")
1230 has_preamble = True;
1234 if has_equal_spacing and not has_preamble:
1235 add_to_preamble(document, ['\\usepackage[all]{xy}'])
1238 def revert_notefontcolor(document):
1239 " Reverts greyed-out note font color to preamble code "
1241 i = find_token(document.header, "\\notefontcolor", 0)
1245 colorcode = get_value(document.header, '\\notefontcolor', i)
1246 del document.header[i]
1248 # are there any grey notes?
1249 if find_token(document.body, "\\begin_inset Note Greyedout", 0) == -1:
1250 # no need to do anything else, and \renewcommand will throw
1251 # an error since lyxgreyedout will not exist.
1254 # the color code is in the form #rrggbb where every character denotes a hex number
1255 red = hex2ratio(colorcode[1:3])
1256 green = hex2ratio(colorcode[3:5])
1257 blue = hex2ratio(colorcode[5:7])
1258 # write the preamble
1259 insert_to_preamble(document,
1260 [ '% for greyed-out notes',
1261 '\\@ifundefined{definecolor}{\\usepackage{color}}{}'
1262 '\\definecolor{note_fontcolor}{rgb}{%s,%s,%s}' % (red, green, blue),
1263 '\\renewenvironment{lyxgreyedout}',
1264 ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}'])
1267 def revert_turkmen(document):
1268 "Set language Turkmen to English"
1270 if document.language == "turkmen":
1271 document.language = "english"
1272 i = find_token(document.header, "\\language", 0)
1274 document.header[i] = "\\language english"
1278 j = find_token(document.body, "\\lang turkmen", j)
1281 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1285 def revert_fontcolor(document):
1286 " Reverts font color to preamble code "
1287 i = find_token(document.header, "\\fontcolor", 0)
1290 colorcode = get_value(document.header, '\\fontcolor', i)
1291 del document.header[i]
1292 # don't clutter the preamble if font color is not set
1293 if colorcode == "#000000":
1295 # the color code is in the form #rrggbb where every character denotes a hex number
1296 red = hex2ratio(colorcode[1:3])
1297 green = hex2ratio(colorcode[3:5])
1298 blue = hex2ratio(colorcode[5:7])
1299 # write the preamble
1300 insert_to_preamble(document,
1301 ['% Set the font color',
1302 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
1303 '\\definecolor{document_fontcolor}{rgb}{%s,%s,%s}' % (red, green, blue),
1304 '\\color{document_fontcolor}'])
1307 def revert_shadedboxcolor(document):
1308 " Reverts shaded box color to preamble code "
1309 i = find_token(document.header, "\\boxbgcolor", 0)
1312 colorcode = get_value(document.header, '\\boxbgcolor', i)
1313 del document.header[i]
1314 # the color code is in the form #rrggbb
1315 red = hex2ratio(colorcode[1:3])
1316 green = hex2ratio(colorcode[3:5])
1317 blue = hex2ratio(colorcode[5:7])
1318 # write the preamble
1319 insert_to_preamble(document,
1320 ['% Set the color of boxes with shaded background',
1321 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
1322 "\\definecolor{shadecolor}{rgb}{%s,%s,%s}" % (red, green, blue)])
1325 def revert_lyx_version(document):
1326 " Reverts LyX Version information from Inset Info "
1327 version = "LyX version"
1329 import lyx2lyx_version
1330 version = lyx2lyx_version.version
1336 i = find_token(document.body, '\\begin_inset Info', i)
1339 j = find_end_of_inset(document.body, i + 1)
1341 document.warning("Malformed LyX document: Could not find end of Info inset.")
1350 typ = get_quoted_value(document.body, "type", i, j)
1351 arg = get_quoted_value(document.body, "arg", i, j)
1352 if arg != "version" or typ != "lyxinfo":
1356 # We do not actually know the version of LyX used to produce the document.
1357 # But we can use our version, since we are reverting.
1359 # Now we want to check if the line after "\end_inset" is empty. It normally
1360 # is, so we want to remove it, too.
1362 if document.body[j + 1].strip() == "":
1364 document.body[i: lastline] = s
1368 def revert_math_scale(document):
1369 " Remove math scaling and LaTeX options "
1370 del_token(document.header, '\\html_math_img_scale', 0)
1371 del_token(document.header, '\\html_latex_start', 0)
1372 del_token(document.header, '\\html_latex_end', 0)
1375 def revert_pagesizes(document):
1376 " Revert page sizes to default "
1377 i = find_token(document.header, '\\papersize', 0)
1379 size = document.header[i][11:]
1380 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1381 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1382 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1383 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1384 or size == "b5j" or size == "b6j":
1385 del document.header[i]
1388 def revert_DIN_C_pagesizes(document):
1389 " Revert DIN C page sizes to default "
1390 i = find_token(document.header, '\\papersize', 0)
1392 size = document.header[i][11:]
1393 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1394 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1395 or size == "c6paper":
1396 del document.header[i]
1399 def convert_html_quotes(document):
1400 " Remove quotes around html_latex_start and html_latex_end "
1402 i = find_token(document.header, '\\html_latex_start', 0)
1404 line = document.header[i]
1405 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1408 document.header[i] = "\\html_latex_start " + m.group(1)
1410 i = find_token(document.header, '\\html_latex_end', 0)
1412 line = document.header[i]
1413 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1416 document.header[i] = "\\html_latex_end " + m.group(1)
1419 def revert_html_quotes(document):
1420 " Remove quotes around html_latex_start and html_latex_end "
1422 i = find_token(document.header, '\\html_latex_start', 0)
1424 line = document.header[i]
1425 l = re.compile(r'\\html_latex_start\s+(.*)')
1428 document.warning("Weird html_latex_start line: " + line)
1429 del document.header[i]
1431 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1433 i = find_token(document.header, '\\html_latex_end', 0)
1435 line = document.header[i]
1436 l = re.compile(r'\\html_latex_end\s+(.*)')
1439 document.warning("Weird html_latex_end line: " + line)
1440 del document.header[i]
1442 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1445 def revert_output_sync(document):
1446 " Remove forward search options "
1447 del_token(document.header, '\\output_sync_macro', 0)
1448 del_token(document.header, '\\output_sync', 0)
1451 def revert_align_decimal(document):
1454 i = find_token(document.body, "\\begin_inset Tabular", i)
1457 j = find_end_of_inset(document.body, i)
1459 document.warning("Unable to find end of Tabular inset at line " + str(i))
1462 cell = find_token(document.body, "<cell", i, j)
1464 document.warning("Can't find any cells in Tabular inset at line " + str(i))
1469 k = find_token(document.body, "<column", k, cell)
1472 if document.body[k].find('alignment="decimal"') == -1:
1475 remove_option(document.body, k, 'decimal_point')
1476 document.body[k] = \
1477 document.body[k].replace('alignment="decimal"', 'alignment="center"')
1481 def convert_optarg(document):
1482 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1485 i = find_token(document.body, '\\begin_inset OptArg', i)
1488 document.body[i] = "\\begin_inset Argument"
1492 def revert_argument(document):
1493 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1496 i = find_token(document.body, '\\begin_inset Argument', i)
1499 document.body[i] = "\\begin_inset OptArg"
1503 def revert_makebox(document):
1504 " Convert \\makebox to TeX code "
1507 i = find_token(document.body, '\\begin_inset Box', i)
1510 z = find_end_of_inset(document.body, i)
1512 document.warning("Malformed LyX document: Can't find end of box inset.")
1515 blay = find_token(document.body, "\\begin_layout", i, z)
1517 document.warning("Malformed LyX document: Can't find layout in box.")
1520 # by looking before the layout we make sure we're actually finding
1521 # an option, not text.
1522 j = find_token(document.body, 'use_makebox', i, blay)
1527 if not check_token(document.body[i], "\\begin_inset Box Frameless") \
1528 or get_value(document.body, 'use_makebox', j) != 1:
1529 del document.body[j]
1532 bend = find_end_of_layout(document.body, blay)
1533 if bend == -1 or bend > z:
1534 document.warning("Malformed LyX document: Can't find end of layout in box.")
1537 # determine the alignment
1538 align = get_quoted_value(document.body, 'hor_pos', i, blay, "c")
1539 # determine the width
1540 length = get_quoted_value(document.body, 'width', i, blay, "50col%")
1541 length = latex_length(length)[1]
1542 # remove the \end_layout \end_inset pair
1543 document.body[bend:z + 1] = put_cmd_in_ert("}")
1544 subst = "\\makebox[" + length + "][" \
1546 document.body[i:blay + 1] = put_cmd_in_ert(subst)
1550 def convert_use_makebox(document):
1551 " Adds use_makebox option for boxes "
1554 i = find_token(document.body, '\\begin_inset Box', i)
1557 # all of this is to make sure we actually find the use_parbox
1558 # that is an option for this box, not some text elsewhere.
1559 z = find_end_of_inset(document.body, i)
1561 document.warning("Can't find end of box inset!!")
1564 blay = find_token(document.body, "\\begin_layout", i, z)
1566 document.warning("Can't find layout in box inset!!")
1569 # so now we are looking for use_parbox before the box's layout
1570 k = find_token(document.body, 'use_parbox', i, blay)
1572 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1575 document.body.insert(k + 1, "use_makebox 0")
1576 i = blay + 1 # not z + 1 (box insets may be nested)
1579 def revert_IEEEtran(document):
1580 " Convert IEEEtran layouts and styles to TeX code "
1582 if document.textclass != "IEEEtran":
1585 revert_flex_inset(document.body, "IEEE membership", "\\IEEEmembership")
1586 revert_flex_inset(document.body, "Lowercase", "\\MakeLowercase")
1588 layouts = ("Special Paper Notice", "After Title Text", "Publication ID",
1589 "Page headings", "Biography without photo")
1590 latexcmd = {"Special Paper Notice": "\\IEEEspecialpapernotice",
1591 "After Title Text": "\\IEEEaftertitletext",
1592 "Publication ID": "\\IEEEpubid"}
1593 obsoletedby = {"Page headings": "MarkBoth",
1594 "Biography without photo": "BiographyNoPhoto"}
1596 for layout in layouts:
1599 i = find_token(document.body, '\\begin_layout ' + layout, i)
1602 j = find_end_of_layout(document.body, i)
1604 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1607 if layout in list(obsoletedby.keys()):
1608 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1611 content = lyx2latex(document, document.body[i:j + 1])
1612 add_to_preamble(document, [latexcmd[layout] + "{" + content + "}"])
1613 del document.body[i:j + 1]
1614 # no need to reset i
1617 def convert_prettyref(document):
1618 " Converts prettyref references to neutral formatted refs "
1619 re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
1620 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
1624 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
1627 j = find_end_of_inset(document.body, i)
1629 document.warning("Malformed LyX document: No end of InsetRef!")
1632 k = find_token(document.body, "LatexCommand prettyref", i, j)
1634 document.body[k] = "LatexCommand formatted"
1636 document.header.insert(-1, "\\use_refstyle 0")
1639 def revert_refstyle(document):
1640 " Reverts neutral formatted refs to prettyref "
1641 re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
1642 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
1646 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
1649 j = find_end_of_inset(document.body, i)
1651 document.warning("Malformed LyX document: No end of InsetRef")
1654 k = find_token(document.body, "LatexCommand formatted", i, j)
1656 document.body[k] = "LatexCommand prettyref"
1658 i = find_token(document.header, "\\use_refstyle", 0)
1660 document.header.pop(i)
1663 def revert_nameref(document):
1664 " Convert namerefs to regular references "
1665 cmds = ["Nameref", "nameref"]
1667 rx = re.compile(r'reference "(.*)"')
1670 oldcmd = "LatexCommand " + cmd
1672 # It seems better to look for this, as most of the reference
1673 # insets won't be ones we care about.
1674 i = find_token(document.body, oldcmd, i)
1679 # Make sure it is actually in an inset!
1680 # A normal line could begin with "LatexCommand nameref"!
1681 val = is_in_inset(document.body, cmdloc, \
1682 "\\begin_inset CommandInset ref")
1687 # ok, so it is in an InsetRef
1688 refline = find_token(document.body, "reference", stins, endins)
1690 document.warning("Can't find reference for inset at line " + stinst + "!!")
1692 m = rx.match(document.body[refline])
1694 document.warning("Can't match reference line: " + document.body[ref])
1698 newcontent = put_cmd_in_ert('\\' + cmd + '{' + ref + '}')
1699 document.body[stins:endins + 1] = newcontent
1702 add_to_preamble(document, ["\\usepackage{nameref}"])
1705 def remove_Nameref(document):
1706 " Convert Nameref commands to nameref commands "
1709 # It seems better to look for this, as most of the reference
1710 # insets won't be ones we care about.
1711 i = find_token(document.body, "LatexCommand Nameref" , i)
1717 # Make sure it is actually in an inset!
1718 val = is_in_inset(document.body, cmdloc, \
1719 "\\begin_inset CommandInset ref")
1722 document.body[cmdloc] = "LatexCommand nameref"
1725 def revert_mathrsfs(document):
1726 " Load mathrsfs if \mathrsfs us use in the document "
1728 for line in document.body:
1729 if line.find("\\mathscr{") != -1:
1730 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
1734 def convert_flexnames(document):
1735 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
1738 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
1740 i = find_token(document.body, "\\begin_inset Flex", i)
1743 m = rx.match(document.body[i])
1745 document.body[i] = "\\begin_inset Flex " + m.group(1)
1750 "Alert" : "CharStyle:Alert",
1751 "Code" : "CharStyle:Code",
1752 "Concepts" : "CharStyle:Concepts",
1753 "E-Mail" : "CharStyle:E-Mail",
1754 "Emph" : "CharStyle:Emph",
1755 "Expression" : "CharStyle:Expression",
1756 "Initial" : "CharStyle:Initial",
1757 "Institute" : "CharStyle:Institute",
1758 "Meaning" : "CharStyle:Meaning",
1759 "Noun" : "CharStyle:Noun",
1760 "Strong" : "CharStyle:Strong",
1761 "Structure" : "CharStyle:Structure",
1762 "ArticleMode" : "Custom:ArticleMode",
1763 "Endnote" : "Custom:Endnote",
1764 "Glosse" : "Custom:Glosse",
1765 "PresentationMode" : "Custom:PresentationMode",
1766 "Tri-Glosse" : "Custom:Tri-Glosse"
1770 "Abbrev" : "Element:Abbrev",
1771 "CCC-Code" : "Element:CCC-Code",
1772 "Citation-number" : "Element:Citation-number",
1773 "City" : "Element:City",
1774 "Code" : "Element:Code",
1775 "CODEN" : "Element:CODEN",
1776 "Country" : "Element:Country",
1777 "Day" : "Element:Day",
1778 "Directory" : "Element:Directory",
1779 "Dscr" : "Element:Dscr",
1780 "Email" : "Element:Email",
1781 "Emph" : "Element:Emph",
1782 "Filename" : "Element:Filename",
1783 "Firstname" : "Element:Firstname",
1784 "Fname" : "Element:Fname",
1785 "GuiButton" : "Element:GuiButton",
1786 "GuiMenu" : "Element:GuiMenu",
1787 "GuiMenuItem" : "Element:GuiMenuItem",
1788 "ISSN" : "Element:ISSN",
1789 "Issue-day" : "Element:Issue-day",
1790 "Issue-months" : "Element:Issue-months",
1791 "Issue-number" : "Element:Issue-number",
1792 "KeyCap" : "Element:KeyCap",
1793 "KeyCombo" : "Element:KeyCombo",
1794 "Keyword" : "Element:Keyword",
1795 "Literal" : "Element:Literal",
1796 "MenuChoice" : "Element:MenuChoice",
1797 "Month" : "Element:Month",
1798 "Orgdiv" : "Element:Orgdiv",
1799 "Orgname" : "Element:Orgname",
1800 "Postcode" : "Element:Postcode",
1801 "SS-Code" : "Element:SS-Code",
1802 "SS-Title" : "Element:SS-Title",
1803 "State" : "Element:State",
1804 "Street" : "Element:Street",
1805 "Surname" : "Element:Surname",
1806 "Volume" : "Element:Volume",
1807 "Year" : "Element:Year"
1811 def revert_flexnames(document):
1812 if document.backend == "latex":
1813 flexlist = flex_insets
1815 flexlist = flex_elements
1817 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
1820 i = find_token(document.body, "\\begin_inset Flex", i)
1823 m = rx.match(document.body[i])
1825 document.warning("Illegal flex inset: " + document.body[i])
1829 if style in flexlist:
1830 document.body[i] = "\\begin_inset Flex " + flexlist[style]
1834 def convert_mathdots(document):
1835 " Load mathdots automatically "
1836 i = find_token(document.header, "\\use_mhchem" , 0)
1838 i = find_token(document.header, "\\use_esint" , 0)
1840 document.warning("Malformed LyX document: Can't find \\use_mhchem.")
1842 j = find_token(document.preamble, "\\usepackage{mathdots}", 0)
1844 document.header.insert(i + 1, "\\use_mathdots 0")
1846 document.header.insert(i + 1, "\\use_mathdots 2")
1847 del document.preamble[j]
1850 def revert_mathdots(document):
1851 " Load mathdots if used in the document "
1853 mathdots = find_token(document.header, "\\use_mathdots" , 0)
1855 document.warning("No \\use_mathdots line. Assuming auto.")
1857 val = get_value(document.header, "\\use_mathdots", mathdots)
1858 del document.header[mathdots]
1862 document.warning("Invalid \\use_mathdots value: " + val + ". Assuming auto.")
1863 # probably usedots has not been changed, but be safe.
1871 add_to_preamble(document, ["\\usepackage{mathdots}"])
1874 # so we are in the auto case. we want to load mathdots if \iddots is used.
1877 i = find_token(document.body, '\\begin_inset Formula', i)
1880 j = find_end_of_inset(document.body, i)
1882 document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
1885 code = "\n".join(document.body[i:j])
1886 if code.find("\\iddots") != -1:
1887 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}"])
1892 def convert_rule(document):
1893 " Convert \\lyxline to CommandInset line. "
1896 inset = ['\\begin_inset CommandInset line',
1897 'LatexCommand rule',
1901 '\\end_inset', '', '']
1903 # if paragraphs are indented, we may have to unindent to get the
1904 # line to be full-width.
1905 indent = get_value(document.header, "\\paragraph_separation", 0)
1906 have_indent = (indent == "indent")
1909 i = find_token(document.body, "\\lyxline" , i)
1913 # we need to find out if this line follows other content
1914 # in its paragraph. find its layout....
1915 lastlay = find_token_backwards(document.body, "\\begin_layout", i)
1917 document.warning("Can't find layout for line at " + str(i))
1918 # do the best we can.
1919 document.body[i:i+1] = inset
1923 # ...and look for other content before it.
1925 for line in document.body[lastlay + 1:i]:
1926 # is it empty or a paragraph option?
1927 if not line or line[0] == '\\':
1933 document.body[i:i+1] = inset
1935 # we need to unindent, lest the line be too long
1936 document.body.insert(lastlay + 1, "\\noindent")
1939 # so our line is in the middle of a paragraph
1940 # we need to add a new line, lest this line follow the
1941 # other content on that line and run off the side of the page
1942 document.body[i:i+1] = inset
1943 document.body[i:i] = ["\\begin_inset Newline newline", "\\end_inset", ""]
1947 def revert_rule(document):
1948 " Revert line insets to Tex code "
1951 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
1955 j = find_token(document.body, "\\end_inset" , i)
1957 document.warning("Malformed LyX document: Can't find end of line inset.")
1959 # determine the optional offset
1960 offset = get_quoted_value(document.body, 'offset', i, j)
1962 offset = '[' + offset + ']'
1963 # determine the width
1964 width = get_quoted_value(document.body, 'width', i, j, "100col%")
1965 width = latex_length(width)[1]
1966 # determine the height
1967 height = get_quoted_value(document.body, 'height', i, j, "1pt")
1968 height = latex_length(height)[1]
1969 # output the \rule command
1970 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
1971 document.body[i:j + 1] = put_cmd_in_ert(subst)
1972 i += len(subst) - (j - i)
1975 def revert_diagram(document):
1976 " Add the feyn package if \\Diagram is used in math "
1979 i = find_token(document.body, '\\begin_inset Formula', i)
1982 j = find_end_of_inset(document.body, i)
1984 document.warning("Malformed LyX document: Can't find end of Formula inset.")
1986 lines = "\n".join(document.body[i:j])
1987 if lines.find("\\Diagram") == -1:
1990 add_to_preamble(document, ["\\usepackage{feyn}"])
1991 # only need to do it once!
1994 chapters = ("amsbook", "book", "docbook-book", "elsart", "extbook", "extreport",
1995 "jbook", "jreport", "jsbook", "literate-book", "literate-report", "memoir",
1996 "mwbk", "mwrep", "recipebook", "report", "scrbook", "scrreprt", "svmono",
1997 "svmult", "tbook", "treport", "tufte-book")
1999 def convert_bibtex_clearpage(document):
2000 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2002 if document.textclass not in chapters:
2005 i = find_token(document.header, '\\papersides', 0)
2008 document.warning("Malformed LyX document: Can't find papersides definition.")
2009 document.warning("Assuming single sided.")
2012 val = get_value(document.header, "\\papersides", i)
2017 if sides != 1 and sides != 2:
2018 document.warning("Invalid papersides value: " + val)
2019 document.warning("Assuming single sided.")
2024 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2028 k = find_end_of_inset(document.body, j)
2030 document.warning("Can't find end of Bibliography inset at line " + str(j))
2034 # only act if there is the option "bibtotoc"
2035 val = get_value(document.body, 'options', j, k)
2037 document.warning("Can't find options for bibliography inset at line " + str(j))
2041 if val.find("bibtotoc") == -1:
2045 # so we want to insert a new page right before the paragraph that
2046 # this bibliography thing is in.
2047 lay = find_token_backwards(document.body, "\\begin_layout", j)
2049 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2056 cmd = "cleardoublepage"
2057 subst = ['\\begin_layout Standard',
2058 '\\begin_inset Newpage ' + cmd,
2059 '\\end_inset', '', '',
2061 document.body[lay:lay] = subst
2065 def check_passthru(document):
2066 tc = document.textclass
2067 ok = (tc == "literate-article" or tc == "literate-book" or tc == "literate-report")
2069 mods = document.get_module_list()
2071 if mod == "sweave" or mod == "noweb":
2077 def convert_passthru(document):
2078 " http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161298.html "
2079 if not check_passthru:
2082 rx = re.compile("\\\\begin_layout \s*(\w+)")
2084 for lay in ["Chunk", "Scrap"]:
2086 beg = find_token(document.body, "\\begin_layout " + lay, beg)
2089 end = find_end_of_layout(document.body, beg)
2091 document.warning("Can't find end of layout at line " + str(beg))
2095 # we are now going to replace newline insets within this layout
2096 # by new instances of this layout. so we have repeated layouts
2097 # instead of newlines.
2099 # if the paragraph has any customization, however, we do not want to
2100 # do the replacement.
2101 if document.body[beg + 1].startswith("\\"):
2107 ns = find_token(document.body, "\\begin_inset Newline newline", ns, end)
2110 ne = find_end_of_inset(document.body, ns)
2111 if ne == -1 or ne > end:
2112 document.warning("Can't find end of inset at line " + str(nb))
2115 if document.body[ne + 1] == "":
2117 subst = ["\\end_layout", "", "\\begin_layout " + lay]
2118 document.body[ns:ne + 1] = subst
2119 # now we need to adjust end, in particular, but might as well
2120 # do ns properly, too
2121 newlines = (ne - ns) - len(subst)
2125 # ok, we now want to find out if the next layout is the
2126 # same as this one. if so, we will insert an extra copy of it
2128 next = find_token(document.body, "\\begin_layout", end)
2130 m = rx.match(document.body[next])
2132 nextlay = m.group(1)
2134 subst = ["\\begin_layout " + lay, "", "\\end_layout", ""]
2135 document.body[next:next] = subst
2139 beg += 4 # for the extra layout
2142 def revert_passthru(document):
2143 " http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161298.html "
2144 if not check_passthru:
2146 rx = re.compile("\\\\begin_layout \s*(\w+)")
2148 for lay in ["Chunk", "Scrap"]:
2150 beg = find_token(document.body, "\\begin_layout " + lay, beg)
2153 end = find_end_of_layout(document.body, beg)
2155 document.warning("Can't find end of layout at line " + str(beg))
2159 # we now want to find out if the next layout is the
2160 # same as this one. but we will need to do this over and
2163 next = find_token(document.body, "\\begin_layout", end)
2166 m = rx.match(document.body[next])
2169 nextlay = m.group(1)
2172 # so it is the same layout again. we now want to know if it is empty.
2173 # but first let's check and make sure there is no content between the
2174 # two layouts. i'm not sure if that can happen or not.
2175 for l in range(end + 1, next):
2176 document.warning("c'" + document.body[l] + "'")
2177 if document.body[l] != "":
2178 document.warning("Found content between adjacent " + lay + " layouts!")
2180 nextend = find_end_of_layout(document.body, next)
2182 document.warning("Can't find end of layout at line " + str(next))
2185 for l in range(next + 1, nextend):
2186 document.warning("e'" + document.body[l] + "'")
2187 if document.body[l] != "":
2191 # empty layouts just get removed
2192 # should we check if it's before yet another such layout?
2193 del document.body[next : nextend + 1]
2194 # and we do not want to check again. we know the next layout
2195 # should be another Chunk and should be left as is.
2198 # if it's not empty, then we want to insert a newline in place
2199 # of the layout switch
2200 subst = ["\\begin_inset Newline newline", "\\end_inset", ""]
2201 document.body[end : next + 1] = subst
2202 # and now we have to find the end of the new, larger layout
2203 newend = find_end_of_layout(document.body, beg)
2205 document.warning("Can't find end of new layout at line " + str(beg))
2211 def revert_multirowOffset(document):
2212 " Revert multirow cells with offset in tables to TeX-code"
2213 # this routine is the same as the revert_multirow routine except that
2214 # it checks additionally for the offset
2216 # first, let's find out if we need to do anything
2217 i = find_token(document.body, '<cell multirow="3" mroffset=', 0)
2221 add_to_preamble(document, ["\\usepackage{multirow}"])
2223 rgx = re.compile(r'mroffset="[^"]+?"')
2227 # find begin/end of table
2228 begin_table = find_token(document.body, '<lyxtabular version=', begin_table)
2229 if begin_table == -1:
2231 end_table = find_end_of(document.body, begin_table, '<lyxtabular', '</lyxtabular>')
2233 document.warning("Malformed LyX document: Could not find end of table.")
2236 # does this table have multirow?
2237 i = find_token(document.body, '<cell multirow="3"', begin_table, end_table)
2239 begin_table = end_table
2242 # store the number of rows and columns
2243 numrows = get_option_value(document.body[begin_table], "rows")
2244 numcols = get_option_value(document.body[begin_table], "columns")
2246 numrows = int(numrows)
2247 numcols = int(numcols)
2249 document.warning("Unable to determine rows and columns!")
2250 begin_table = end_table
2255 # collect info on rows and columns of this table.
2256 begin_row = begin_table
2257 for row in range(numrows):
2258 begin_row = find_token(document.body, '<row>', begin_row, end_table)
2260 document.warning("Can't find row " + str(row + 1))
2262 end_row = find_end_of(document.body, begin_row, '<row>', '</row>')
2264 document.warning("Can't find end of row " + str(row + 1))
2266 begin_cell = begin_row
2267 multirows.append([])
2268 for column in range(numcols):
2269 begin_cell = find_token(document.body, '<cell ', begin_cell, end_row)
2270 if begin_cell == -1:
2271 document.warning("Can't find column " + str(column + 1) + \
2272 "in row " + str(row + 1))
2275 # this will fail if someone puts "</cell>" in a cell, but
2276 # that seems fairly unlikely.
2277 end_cell = find_end_of(document.body, begin_cell, '<cell', '</cell>')
2279 document.warning("Can't find end of column " + str(column + 1) + \
2280 "in row " + str(row + 1))
2282 multirows[row].append([begin_cell, end_cell, 0])
2283 if document.body[begin_cell].find('multirow="3" mroffset=') != -1:
2284 multirows[row][column][2] = 3 # begin multirow
2285 mrstarts.append([row, column])
2286 elif document.body[begin_cell].find('multirow="4"') != -1:
2287 multirows[row][column][2] = 4 # in multirow
2288 begin_cell = end_cell
2290 # end of table info collection
2292 # work from the back to avoid messing up numbering
2298 col_width = get_option_value(document.body[begin_table + 2 + col], "width")
2299 # "0pt" means that no width is specified
2300 if not col_width or col_width == "0pt":
2302 # determine the number of cells that are part of the multirow
2304 for r in range(row + 1, numrows):
2305 if multirows[r][col][2] != 4:
2308 # take the opportunity to revert this line
2309 lineno = multirows[r][col][0]
2310 document.body[lineno] = document.body[lineno].\
2311 replace(' multirow="4" ', ' ').\
2312 replace('valignment="middle"', 'valignment="top"').\
2313 replace(' topline="true" ', ' ')
2314 # remove bottom line of previous multirow-part cell
2315 lineno = multirows[r-1][col][0]
2316 document.body[lineno] = document.body[lineno].replace(' bottomline="true" ', ' ')
2317 # revert beginning cell
2318 bcell = multirows[row][col][0]
2319 ecell = multirows[row][col][1]
2320 offset = get_option_value(document.body[bcell], "mroffset")
2321 document.body[bcell] = document.body[bcell].\
2322 replace(' multirow="3" ', ' ').\
2323 replace('valignment="middle"', 'valignment="top"')
2324 # remove mroffset option
2325 document.body[bcell] = rgx.sub('', document.body[bcell])
2327 blay = find_token(document.body, "\\begin_layout", bcell, ecell)
2329 document.warning("Can't find layout for cell!")
2331 bend = find_end_of_layout(document.body, blay)
2333 document.warning("Can't find end of layout for cell!")
2335 # do the later one first, so as not to mess up the numbering
2336 # we are wrapping the whole cell in this ert
2337 # so before the end of the layout...
2338 document.body[bend:bend] = put_cmd_in_ert("}")
2339 # ...and after the beginning
2340 document.body[blay + 1:blay + 1] = \
2341 put_cmd_in_ert("\\multirow{" + str(nummrs) + "}{" + col_width + "}[" \
2344 # on to the next table
2345 begin_table = end_table
2348 def revert_script(document):
2349 " Convert subscript/superscript inset to TeX code "
2351 foundsubscript = False
2353 i = find_token(document.body, '\\begin_inset script', i)
2356 z = find_end_of_inset(document.body, i)
2358 document.warning("Malformed LyX document: Can't find end of script inset.")
2361 blay = find_token(document.body, "\\begin_layout", i, z)
2363 document.warning("Malformed LyX document: Can't find layout in script inset.")
2367 if check_token(document.body[i], "\\begin_inset script subscript"):
2368 subst = '\\textsubscript{'
2369 foundsubscript = True
2370 elif check_token(document.body[i], "\\begin_inset script superscript"):
2371 subst = '\\textsuperscript{'
2373 document.warning("Malformed LyX document: Unknown type of script inset.")
2376 bend = find_end_of_layout(document.body, blay)
2377 if bend == -1 or bend > z:
2378 document.warning("Malformed LyX document: Can't find end of layout in script inset.")
2381 # remove the \end_layout \end_inset pair
2382 document.body[bend:z + 1] = put_cmd_in_ert("}")
2383 document.body[i:blay + 1] = put_cmd_in_ert(subst)
2385 # these classes provide a \textsubscript command:
2386 # FIXME: Would be nice if we could use the information of the .layout file here
2387 classes = ["memoir", "scrartcl", "scrbook", "scrlttr2", "scrreprt"]
2388 if foundsubscript and find_token_exact(classes, document.textclass, 0) == -1:
2389 add_to_preamble(document, ['\\usepackage{subscript}'])
2392 def convert_use_xetex(document):
2393 " convert \\use_xetex to \\use_non_tex_fonts "
2394 i = find_token(document.header, "\\use_xetex", 0)
2396 document.header.insert(-1, "\\use_non_tex_fonts 0")
2398 val = get_value(document.header, "\\use_xetex", 0)
2399 document.header[i] = "\\use_non_tex_fonts " + val
2402 def revert_use_xetex(document):
2403 " revert \\use_non_tex_fonts to \\use_xetex "
2405 i = find_token(document.header, "\\use_non_tex_fonts", 0)
2407 document.warning("Malformed document. No \\use_non_tex_fonts param!")
2410 val = get_value(document.header, "\\use_non_tex_fonts", 0)
2411 document.header[i] = "\\use_xetex " + val
2414 def revert_labeling(document):
2415 koma = ("scrartcl", "scrarticle-beamer", "scrbook", "scrlettr",
2416 "scrlttr2", "scrreprt")
2417 if document.textclass in koma:
2421 i = find_token_exact(document.body, "\\begin_layout Labeling", i)
2424 document.body[i] = "\\begin_layout List"
2427 def revert_langpack(document):
2428 " revert \\language_package parameter "
2430 i = find_token(document.header, "\\language_package", 0)
2432 document.warning("Malformed document. No \\language_package param!")
2435 del document.header[i]
2438 def convert_langpack(document):
2439 " Add \\language_package parameter "
2440 i = find_token(document.header, "\language" , 0)
2442 document.warning("Malformed document. No \\language defined!")
2445 document.header.insert(i + 1, "\\language_package default")
2448 def revert_tabularwidth(document):
2451 i = find_token(document.body, "\\begin_inset Tabular", i)
2454 j = find_end_of_inset(document.body, i)
2456 document.warning("Unable to find end of Tabular inset at line " + str(i))
2460 features = find_token(document.body, "<features", i, j)
2462 document.warning("Can't find any features in Tabular inset at line " + str(i))
2465 if document.body[features].find('alignment="tabularwidth"') != -1:
2466 remove_option(document.body, features, 'tabularwidth')
2468 def revert_html_css_as_file(document):
2469 if not del_token(document.header, '\\html_css_as_file', 0):
2470 document.warning("Malformed LyX document: Missing \\html_css_as_file.")
2477 supported_versions = ["2.0.0","2.0"]
2478 convert = [[346, []],
2484 [352, [convert_splitindex]],
2491 [359, [convert_nomencl_width]],
2501 [369, [convert_author_id]],
2503 [371, [convert_mhchem]],
2505 [373, [merge_gbrief]],
2511 [379, [convert_math_output]],
2521 [389, [convert_html_quotes]],
2525 [393, [convert_optarg]],
2526 [394, [convert_use_makebox]],
2529 [397, [remove_Nameref]],
2531 [399, [convert_mathdots]],
2532 [400, [convert_rule]],
2534 [402, [convert_bibtex_clearpage]],
2535 [403, [convert_flexnames]],
2536 [404, [convert_prettyref]],
2538 [406, [convert_passthru]],
2541 [409, [convert_use_xetex]],
2543 [411, [convert_langpack]],
2548 revert = [[412, [revert_html_css_as_file]],
2549 [411, [revert_tabularwidth]],
2550 [410, [revert_langpack]],
2551 [409, [revert_labeling]],
2552 [408, [revert_use_xetex]],
2553 [407, [revert_script]],
2554 [406, [revert_multirowOffset]],
2555 [405, [revert_passthru]],
2557 [403, [revert_refstyle]],
2558 [402, [revert_flexnames]],
2560 [400, [revert_diagram]],
2561 [399, [revert_rule]],
2562 [398, [revert_mathdots]],
2563 [397, [revert_mathrsfs]],
2565 [395, [revert_nameref]],
2566 [394, [revert_DIN_C_pagesizes]],
2567 [393, [revert_makebox]],
2568 [392, [revert_argument]],
2570 [390, [revert_align_decimal, revert_IEEEtran]],
2571 [389, [revert_output_sync]],
2572 [388, [revert_html_quotes]],
2573 [387, [revert_pagesizes]],
2574 [386, [revert_math_scale]],
2575 [385, [revert_lyx_version]],
2576 [384, [revert_shadedboxcolor]],
2577 [383, [revert_fontcolor]],
2578 [382, [revert_turkmen]],
2579 [381, [revert_notefontcolor]],
2580 [380, [revert_equalspacing_xymatrix]],
2581 [379, [revert_inset_preview]],
2582 [378, [revert_math_output]],
2584 [376, [revert_multirow]],
2585 [375, [revert_includeall]],
2586 [374, [revert_includeonly]],
2587 [373, [revert_html_options]],
2588 [372, [revert_gbrief]],
2589 [371, [revert_fontenc]],
2590 [370, [revert_mhchem]],
2591 [369, [revert_suppress_date]],
2592 [368, [revert_author_id]],
2593 [367, [revert_hspace_glue_lengths]],
2594 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2595 [365, [revert_percent_skip_lengths]],
2596 [364, [revert_paragraph_indentation]],
2597 [363, [revert_branch_filename]],
2598 [362, [revert_longtable_align]],
2599 [361, [revert_applemac]],
2601 [359, [revert_nomencl_cwidth]],
2602 [358, [revert_nomencl_width]],
2603 [357, [revert_custom_processors]],
2604 [356, [revert_ulinelatex]],
2606 [354, [revert_strikeout]],
2607 [353, [revert_printindexall]],
2608 [352, [revert_subindex]],
2609 [351, [revert_splitindex]],
2610 [350, [revert_backgroundcolor]],
2611 [349, [revert_outputformat]],
2612 [348, [revert_xetex]],
2613 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2614 [346, [revert_tabularvalign]],
2615 [345, [revert_swiss]]
2619 if __name__ == "__main__":