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)
560 document.warning("Can't find width option for nomencl_print!")
563 width = get_quoted_value(document.body, "width", i, j)
565 insert_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
569 def revert_applemac(document):
570 " Revert applemac encoding to auto "
571 if document.encoding != "applemac":
573 document.encoding = "auto"
574 i = find_token(document.header, "\\encoding", 0)
576 document.header[i] = "\\encoding auto"
579 def revert_longtable_align(document):
580 " Remove longtable alignment setting "
583 i = find_token(document.body, "\\begin_inset Tabular", i)
586 end = find_end_of_inset(document.body, i)
588 document.warning("Can't find end of inset at line " + str(i))
591 fline = find_token(document.body, "<features", i, end)
593 document.warning("Can't find features for inset at line " + str(i))
596 j = document.body[fline].find("longtabularalignment")
600 # FIXME Is this correct? It wipes out everything after the
602 document.body[fline] = document.body[fline][:j - 1] + '>'
603 # since there could be a tabular inside this one, we
604 # cannot jump to end.
608 def revert_branch_filename(document):
609 " Remove \\filename_suffix parameter from branches "
612 i = find_token(document.header, "\\filename_suffix", i)
615 del document.header[i]
618 def revert_paragraph_indentation(document):
619 " Revert custom paragraph indentation to preamble code "
620 i = find_token(document.header, "\\paragraph_indentation", 0)
623 length = get_value(document.header, "\\paragraph_indentation", i)
624 # we need only remove the line if indentation is default
625 if length != "default":
626 # handle percent lengths
627 length = latex_length(length)[1]
628 insert_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
629 del document.header[i]
632 def revert_percent_skip_lengths(document):
633 " Revert relative lengths for paragraph skip separation to preamble code "
634 i = find_token(document.header, "\\defskip", 0)
637 length = get_value(document.header, "\\defskip", i)
638 # only revert when a custom length was set and when
639 # it used a percent length
640 if length in ('smallskip', 'medskip', 'bigskip'):
642 # handle percent lengths
643 percent, length = latex_length(length)
645 insert_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
646 # set defskip to medskip as default
647 document.header[i] = "\\defskip medskip"
650 def revert_percent_vspace_lengths(document):
651 " Revert relative VSpace lengths to ERT "
654 i = find_token(document.body, "\\begin_inset VSpace", i)
657 # only revert if a custom length was set and if
658 # it used a percent length
659 r = re.compile(r'\\begin_inset VSpace (.*)$')
660 m = r.match(document.body[i])
662 if length in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
665 # check if the space has a star (protected space)
666 protected = (document.body[i].rfind("*") != -1)
668 length = length.rstrip('*')
669 # handle percent lengths
670 percent, length = latex_length(length)
671 # revert the VSpace inset to ERT
674 subst = put_cmd_in_ert("\\vspace*{" + length + "}")
676 subst = put_cmd_in_ert("\\vspace{" + length + "}")
677 document.body[i:i + 2] = subst
681 def revert_percent_hspace_lengths(document):
682 " Revert relative HSpace lengths to ERT "
685 i = find_token_exact(document.body, "\\begin_inset space \\hspace", i)
688 j = find_end_of_inset(document.body, i)
690 document.warning("Can't find end of inset at line " + str(i))
693 # only revert if a custom length was set...
694 length = get_value(document.body, '\\length', i + 1, j)
696 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
700 if document.body[i].find("\\hspace*{}") != -1:
702 # ...and if it used a percent length
703 percent, length = latex_length(length)
704 # revert the HSpace inset to ERT
706 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
707 document.body[i:j + 1] = subst
708 # if we did a substitution, this will still be ok
712 def revert_hspace_glue_lengths(document):
713 " Revert HSpace glue lengths to ERT "
716 i = find_token_exact(document.body, "\\begin_inset space \\hspace", i)
719 j = find_end_of_inset(document.body, i)
721 document.warning("Can't find end of inset at line " + str(i))
724 length = get_value(document.body, '\\length', i + 1, j)
726 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
730 if document.body[i].find("\\hspace*{}") != -1:
732 # only revert if the length contains a plus or minus at pos != 0
733 if length.find('-',1) != -1 or length.find('+',1) != -1:
734 # handle percent lengths
735 length = latex_length(length)[1]
736 # revert the HSpace inset to ERT
737 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
738 document.body[i:j+1] = subst
742 def convert_author_id(document):
743 " Add the author_id to the \\author definition and make sure 0 is not used"
746 re_author = re.compile(r'(\\author) (\".*\")\s*(.*)$')
749 i = find_token(document.header, "\\author", i)
752 m = re_author.match(document.header[i])
756 document.header[i] = "\\author %i %s %s" % (anum, name, email)
762 i = find_token(document.body, "\\change_", i)
765 change = document.body[i].split(' ');
768 author_id = int(change[1])
770 document.body[i] = "%s %i %s" % (type, author_id + 1, time)
774 def revert_author_id(document):
775 " Remove the author_id from the \\author definition "
778 rx = re.compile(r'(\\author)\s+(-?\d+)\s+(\".*\")\s*(.*)$')
782 i = find_token(document.header, "\\author", i)
785 m = rx.match(document.header[i])
787 author_id = int(m.group(2))
788 idmap[author_id] = anum
791 document.header[i] = "\\author %s %s" % (name, email)
793 # FIXME Should this be incremented if we didn't match?
798 i = find_token(document.body, "\\change_", i)
801 change = document.body[i].split(' ');
804 author_id = int(change[1])
806 document.body[i] = "%s %i %s" % (type, idmap[author_id], time)
810 def revert_suppress_date(document):
811 " Revert suppressing of default document date to preamble code "
812 i = find_token(document.header, "\\suppress_date", 0)
815 # remove the preamble line and write to the preamble
816 # when suppress_date was true
817 date = str2bool(get_value(document.header, "\\suppress_date", i))
819 add_to_preamble(document, ["\\date{}"])
820 del document.header[i]
823 def convert_mhchem(document):
824 "Set mhchem to off for versions older than 1.6.x"
825 if document.start < 277:
826 # LyX 1.5.x and older did never load mhchem.
827 # Therefore we must switch it off: Documents that use mhchem have
828 # a manual \usepackage anyway, and documents not using mhchem but
829 # custom macros with the same names as mhchem commands might get
830 # corrupted if mhchem is automatically loaded.
833 # LyX 1.6.x did always load mhchem automatically.
835 i = find_token(document.header, "\\use_esint", 0)
838 i = find_token(document.header, "\\use_amsmath", 0)
840 document.warning("Malformed LyX document: Could not find amsmath os esint setting.")
842 document.header.insert(i + 1, "\\use_mhchem %d" % mhchem)
845 def revert_mhchem(document):
846 "Revert mhchem loading to preamble code"
849 i = find_token(document.header, "\\use_mhchem", 0)
851 document.warning("Malformed LyX document: Could not find mhchem setting.")
854 val = get_value(document.header, "\\use_mhchem", i)
859 del document.header[i]
868 i = find_token(document.body, "\\begin_inset Formula", i)
871 line = document.body[i]
872 if line.find("\\ce{") != -1 or line.find("\\cf{") != -1:
878 pre = ["\\PassOptionsToPackage{version=3}{mhchem}",
879 "\\usepackage{mhchem}"]
880 insert_to_preamble(document, pre)
883 def revert_fontenc(document):
884 " Remove fontencoding param "
885 if not del_token(document.header, '\\fontencoding', 0):
886 document.warning("Malformed LyX document: Missing \\fontencoding.")
889 def merge_gbrief(document):
890 " Merge g-brief-en and g-brief-de to one class "
892 if document.textclass != "g-brief-de":
893 if document.textclass == "g-brief-en":
894 document.textclass = "g-brief"
895 document.set_textclass()
898 obsoletedby = { "Brieftext": "Letter",
899 "Unterschrift": "Signature",
901 "Zusatz": "Addition",
904 "RetourAdresse": "ReturnAddress",
905 "MeinZeichen": "MyRef",
906 "IhrZeichen": "YourRef",
907 "IhrSchreiben": "YourMail",
910 "Konto": "BankAccount",
911 "Postvermerk": "PostalComment",
912 "Adresse": "Address",
914 "Betreff": "Reference",
921 i = find_token(document.body, "\\begin_layout", i)
925 layout = document.body[i][14:]
926 if layout in obsoletedby:
927 document.body[i] = "\\begin_layout " + obsoletedby[layout]
931 document.textclass = "g-brief"
932 document.set_textclass()
935 def revert_gbrief(document):
936 " Revert g-brief to g-brief-en "
937 if document.textclass == "g-brief":
938 document.textclass = "g-brief-en"
939 document.set_textclass()
942 def revert_html_options(document):
943 " Remove html options "
944 del_token(document.header, '\\html_use_mathml', 0)
945 del_token(document.header, '\\html_be_strict', 0)
948 def revert_includeonly(document):
951 i = find_token(document.header, "\\begin_includeonly", i)
954 j = find_end_of(document.header, i, "\\begin_includeonly", "\\end_includeonly")
956 document.warning("Unable to find end of includeonly section!!")
958 document.header[i : j + 1] = []
961 def revert_includeall(document):
962 " Remove maintain_unincluded_children param "
963 del_token(document.header, '\\maintain_unincluded_children', 0)
966 def revert_multirow(document):
967 " Revert multirow cells in tables to TeX-code"
969 # first, let's find out if we need to do anything
970 # cell type 3 is multirow begin cell
971 i = find_token(document.body, '<cell multirow="3"', 0)
975 add_to_preamble(document, ["\\usepackage{multirow}"])
979 # find begin/end of table
980 begin_table = find_token(document.body, '<lyxtabular version=', begin_table)
981 if begin_table == -1:
983 end_table = find_end_of(document.body, begin_table, '<lyxtabular', '</lyxtabular>')
985 document.warning("Malformed LyX document: Could not find end of table.")
988 # does this table have multirow?
989 i = find_token(document.body, '<cell multirow="3"', begin_table, end_table)
991 begin_table = end_table
994 # store the number of rows and columns
995 numrows = get_option_value(document.body[begin_table], "rows")
996 numcols = get_option_value(document.body[begin_table], "columns")
998 numrows = int(numrows)
999 numcols = int(numcols)
1001 document.warning("Unable to determine rows and columns!")
1002 begin_table = end_table
1007 # collect info on rows and columns of this table.
1008 begin_row = begin_table
1009 for row in range(numrows):
1010 begin_row = find_token(document.body, '<row>', begin_row, end_table)
1012 document.warning("Can't find row " + str(row + 1))
1014 end_row = find_end_of(document.body, begin_row, '<row>', '</row>')
1016 document.warning("Can't find end of row " + str(row + 1))
1018 begin_cell = begin_row
1019 multirows.append([])
1020 for column in range(numcols):
1021 begin_cell = find_token(document.body, '<cell ', begin_cell, end_row)
1022 if begin_cell == -1:
1023 document.warning("Can't find column " + str(column + 1) + \
1024 "in row " + str(row + 1))
1027 # this will fail if someone puts "</cell>" in a cell, but
1028 # that seems fairly unlikely.
1029 end_cell = find_end_of(document.body, begin_cell, '<cell', '</cell>')
1031 document.warning("Can't find end of column " + str(column + 1) + \
1032 "in row " + str(row + 1))
1034 multirows[row].append([begin_cell, end_cell, 0])
1035 if document.body[begin_cell].find('multirow="3"') != -1:
1036 multirows[row][column][2] = 3 # begin multirow
1037 mrstarts.append([row, column])
1038 elif document.body[begin_cell].find('multirow="4"') != -1:
1039 multirows[row][column][2] = 4 # in multirow
1040 begin_cell = end_cell
1042 # end of table info collection
1044 # work from the back to avoid messing up numbering
1050 col_width = get_option_value(document.body[begin_table + 2 + col], "width")
1051 # "0pt" means that no width is specified
1052 if not col_width or col_width == "0pt":
1054 # determine the number of cells that are part of the multirow
1056 for r in range(row + 1, numrows):
1057 if multirows[r][col][2] != 4:
1060 # take the opportunity to revert this line
1061 lineno = multirows[r][col][0]
1062 document.body[lineno] = document.body[lineno].\
1063 replace(' multirow="4" ', ' ').\
1064 replace('valignment="middle"', 'valignment="top"').\
1065 replace(' topline="true" ', ' ')
1066 # remove bottom line of previous multirow-part cell
1067 lineno = multirows[r-1][col][0]
1068 document.body[lineno] = document.body[lineno].replace(' bottomline="true" ', ' ')
1069 # revert beginning cell
1070 bcell = multirows[row][col][0]
1071 ecell = multirows[row][col][1]
1072 document.body[bcell] = document.body[bcell].\
1073 replace(' multirow="3" ', ' ').\
1074 replace('valignment="middle"', 'valignment="top"')
1075 blay = find_token(document.body, "\\begin_layout", bcell, ecell)
1077 document.warning("Can't find layout for cell!")
1079 bend = find_end_of_layout(document.body, blay)
1081 document.warning("Can't find end of layout for cell!")
1083 # do the later one first, so as not to mess up the numbering
1084 # we are wrapping the whole cell in this ert
1085 # so before the end of the layout...
1086 document.body[bend:bend] = put_cmd_in_ert("}")
1087 # ...and after the beginning
1088 document.body[blay + 1:blay + 1] = \
1089 put_cmd_in_ert("\\multirow{" + str(nummrs) + "}{" + col_width + "}{")
1091 begin_table = end_table
1094 def convert_math_output(document):
1095 " Convert \html_use_mathml to \html_math_output "
1096 i = find_token(document.header, "\\html_use_mathml", 0)
1099 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1100 m = rgx.match(document.header[i])
1101 newval = "0" # MathML
1103 val = str2bool(m.group(1))
1105 newval = "2" # Images
1107 document.warning("Can't match " + document.header[i])
1108 document.header[i] = "\\html_math_output " + newval
1111 def revert_math_output(document):
1112 " Revert \html_math_output to \html_use_mathml "
1113 i = find_token(document.header, "\\html_math_output", 0)
1116 rgx = re.compile(r'\\html_math_output\s+(\d)')
1117 m = rgx.match(document.header[i])
1121 if val == "1" or val == "2":
1124 document.warning("Unable to match " + document.header[i])
1125 document.header[i] = "\\html_use_mathml " + newval
1129 def revert_inset_preview(document):
1130 " Dissolves the preview inset "
1133 i = find_token(document.body, "\\begin_inset Preview", i)
1136 iend = find_end_of_inset(document.body, i)
1138 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1142 # This has several issues.
1143 # We need to do something about the layouts inside InsetPreview.
1144 # If we just leave the first one, then we have something like:
1145 # \begin_layout Standard
1147 # \begin_layout Standard
1148 # and we get a "no \end_layout" error. So something has to be done.
1149 # Ideally, we would check if it is the same as the layout we are in.
1150 # If so, we just remove it; if not, we end the active one. But it is
1151 # not easy to know what layout we are in, due to depth changes, etc,
1152 # and it is not clear to me how much work it is worth doing. In most
1153 # cases, the layout will probably be the same.
1155 # For the same reason, we have to remove the \end_layout tag at the
1156 # end of the last layout in the inset. Again, that will sometimes be
1157 # wrong, but it will usually be right. To know what to do, we would
1158 # again have to know what layout the inset is in.
1160 blay = find_token(document.body, "\\begin_layout", i, iend)
1162 document.warning("Can't find layout for preview inset!")
1163 # always do the later one first...
1164 del document.body[iend]
1165 del document.body[i]
1166 # deletions mean we do not need to reset i
1169 # This is where we would check what layout we are in.
1170 # The check for Standard is definitely wrong.
1172 # lay = document.body[blay].split(None, 1)[1]
1173 # if lay != oldlayout:
1174 # # record a boolean to tell us what to do later....
1175 # # better to do it later, since (a) it won't mess up
1176 # # the numbering and (b) we only modify at the end.
1178 # we want to delete the last \\end_layout in this inset, too.
1179 # note that this may not be the \\end_layout that goes with blay!!
1180 bend = find_end_of_layout(document.body, blay)
1182 tmp = find_token(document.body, "\\end_layout", bend + 1, iend)
1187 document.warning("Unable to find last layout in preview inset!")
1188 del document.body[iend]
1189 del document.body[i]
1190 # deletions mean we do not need to reset i
1192 # always do the later one first...
1193 del document.body[iend]
1194 del document.body[bend]
1195 del document.body[i:blay + 1]
1196 # we do not need to reset i
1199 def revert_equalspacing_xymatrix(document):
1200 " Revert a Formula with xymatrix@! to an ERT inset "
1202 has_preamble = False
1203 has_equal_spacing = False
1206 i = find_token(document.body, "\\begin_inset Formula", i)
1209 j = find_end_of_inset(document.body, i)
1211 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1215 for curline in range(i,j):
1216 found = document.body[curline].find("\\xymatrix@!")
1221 has_equal_spacing = True
1222 content = [document.body[i][21:]]
1223 content += document.body[i + 1:j]
1224 subst = put_cmd_in_ert(content)
1225 document.body[i:j + 1] = subst
1226 i += len(subst) - (j - i) + 1
1228 for curline in range(i,j):
1229 l = document.body[curline].find("\\xymatrix")
1231 has_preamble = True;
1235 if has_equal_spacing and not has_preamble:
1236 add_to_preamble(document, ['\\usepackage[all]{xy}'])
1239 def revert_notefontcolor(document):
1240 " Reverts greyed-out note font color to preamble code "
1242 i = find_token(document.header, "\\notefontcolor", 0)
1246 colorcode = get_value(document.header, '\\notefontcolor', i)
1247 del document.header[i]
1249 # are there any grey notes?
1250 if find_token(document.body, "\\begin_inset Note Greyedout", 0) == -1:
1251 # no need to do anything else, and \renewcommand will throw
1252 # an error since lyxgreyedout will not exist.
1255 # the color code is in the form #rrggbb where every character denotes a hex number
1256 red = hex2ratio(colorcode[1:3])
1257 green = hex2ratio(colorcode[3:5])
1258 blue = hex2ratio(colorcode[5:7])
1259 # write the preamble
1260 insert_to_preamble(document,
1261 [ '% for greyed-out notes',
1262 '\\@ifundefined{definecolor}{\\usepackage{color}}{}'
1263 '\\definecolor{note_fontcolor}{rgb}{%s,%s,%s}' % (red, green, blue),
1264 '\\renewenvironment{lyxgreyedout}',
1265 ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}'])
1268 def revert_turkmen(document):
1269 "Set language Turkmen to English"
1271 if document.language == "turkmen":
1272 document.language = "english"
1273 i = find_token(document.header, "\\language", 0)
1275 document.header[i] = "\\language english"
1279 j = find_token(document.body, "\\lang turkmen", j)
1282 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1286 def revert_fontcolor(document):
1287 " Reverts font color to preamble code "
1288 i = find_token(document.header, "\\fontcolor", 0)
1291 colorcode = get_value(document.header, '\\fontcolor', i)
1292 del document.header[i]
1293 # don't clutter the preamble if font color is not set
1294 if colorcode == "#000000":
1296 # the color code is in the form #rrggbb where every character denotes a hex number
1297 red = hex2ratio(colorcode[1:3])
1298 green = hex2ratio(colorcode[3:5])
1299 blue = hex2ratio(colorcode[5:7])
1300 # write the preamble
1301 insert_to_preamble(document,
1302 ['% Set the font color',
1303 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
1304 '\\definecolor{document_fontcolor}{rgb}{%s,%s,%s}' % (red, green, blue),
1305 '\\color{document_fontcolor}'])
1308 def revert_shadedboxcolor(document):
1309 " Reverts shaded box color to preamble code "
1310 i = find_token(document.header, "\\boxbgcolor", 0)
1313 colorcode = get_value(document.header, '\\boxbgcolor', i)
1314 del document.header[i]
1315 # the color code is in the form #rrggbb
1316 red = hex2ratio(colorcode[1:3])
1317 green = hex2ratio(colorcode[3:5])
1318 blue = hex2ratio(colorcode[5:7])
1319 # write the preamble
1320 insert_to_preamble(document,
1321 ['% Set the color of boxes with shaded background',
1322 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
1323 "\\definecolor{shadecolor}{rgb}{%s,%s,%s}" % (red, green, blue)])
1326 def revert_lyx_version(document):
1327 " Reverts LyX Version information from Inset Info "
1328 version = "LyX version"
1330 import lyx2lyx_version
1331 version = lyx2lyx_version.version
1337 i = find_token(document.body, '\\begin_inset Info', i)
1340 j = find_end_of_inset(document.body, i + 1)
1342 document.warning("Malformed LyX document: Could not find end of Info inset.")
1351 typ = get_quoted_value(document.body, "type", i, j)
1352 arg = get_quoted_value(document.body, "arg", i, j)
1353 if arg != "version" or typ != "lyxinfo":
1357 # We do not actually know the version of LyX used to produce the document.
1358 # But we can use our version, since we are reverting.
1360 # Now we want to check if the line after "\end_inset" is empty. It normally
1361 # is, so we want to remove it, too.
1363 if document.body[j + 1].strip() == "":
1365 document.body[i: lastline] = s
1369 def revert_math_scale(document):
1370 " Remove math scaling and LaTeX options "
1371 del_token(document.header, '\\html_math_img_scale', 0)
1372 del_token(document.header, '\\html_latex_start', 0)
1373 del_token(document.header, '\\html_latex_end', 0)
1376 def revert_pagesizes(document):
1377 " Revert page sizes to default "
1378 i = find_token(document.header, '\\papersize', 0)
1380 size = document.header[i][11:]
1381 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1382 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1383 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1384 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1385 or size == "b5j" or size == "b6j":
1386 del document.header[i]
1389 def revert_DIN_C_pagesizes(document):
1390 " Revert DIN C page sizes to default "
1391 i = find_token(document.header, '\\papersize', 0)
1393 size = document.header[i][11:]
1394 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1395 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1396 or size == "c6paper":
1397 del document.header[i]
1400 def convert_html_quotes(document):
1401 " Remove quotes around html_latex_start and html_latex_end "
1403 i = find_token(document.header, '\\html_latex_start', 0)
1405 line = document.header[i]
1406 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1409 document.header[i] = "\\html_latex_start " + m.group(1)
1411 i = find_token(document.header, '\\html_latex_end', 0)
1413 line = document.header[i]
1414 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1417 document.header[i] = "\\html_latex_end " + m.group(1)
1420 def revert_html_quotes(document):
1421 " Remove quotes around html_latex_start and html_latex_end "
1423 i = find_token(document.header, '\\html_latex_start', 0)
1425 line = document.header[i]
1426 l = re.compile(r'\\html_latex_start\s+(.*)')
1429 document.warning("Weird html_latex_start line: " + line)
1430 del document.header[i]
1432 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1434 i = find_token(document.header, '\\html_latex_end', 0)
1436 line = document.header[i]
1437 l = re.compile(r'\\html_latex_end\s+(.*)')
1440 document.warning("Weird html_latex_end line: " + line)
1441 del document.header[i]
1443 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1446 def revert_output_sync(document):
1447 " Remove forward search options "
1448 del_token(document.header, '\\output_sync_macro', 0)
1449 del_token(document.header, '\\output_sync', 0)
1452 def revert_align_decimal(document):
1455 i = find_token(document.body, "\\begin_inset Tabular", i)
1458 j = find_end_of_inset(document.body, i)
1460 document.warning("Unable to find end of Tabular inset at line " + str(i))
1463 cell = find_token(document.body, "<cell", i, j)
1465 document.warning("Can't find any cells in Tabular inset at line " + str(i))
1470 k = find_token(document.body, "<column", k, cell)
1473 if document.body[k].find('alignment="decimal"') == -1:
1476 remove_option(document.body, k, 'decimal_point')
1477 document.body[k] = \
1478 document.body[k].replace('alignment="decimal"', 'alignment="center"')
1482 def convert_optarg(document):
1483 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1486 i = find_token(document.body, '\\begin_inset OptArg', i)
1489 document.body[i] = "\\begin_inset Argument"
1493 def revert_argument(document):
1494 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1497 i = find_token(document.body, '\\begin_inset Argument', i)
1500 document.body[i] = "\\begin_inset OptArg"
1504 def revert_makebox(document):
1505 " Convert \\makebox to TeX code "
1508 i = find_token(document.body, '\\begin_inset Box', i)
1511 z = find_end_of_inset(document.body, i)
1513 document.warning("Malformed LyX document: Can't find end of box inset.")
1516 blay = find_token(document.body, "\\begin_layout", i, z)
1518 document.warning("Malformed LyX document: Can't find layout in box.")
1521 # by looking before the layout we make sure we're actually finding
1522 # an option, not text.
1523 j = find_token(document.body, 'use_makebox', i, blay)
1528 if not check_token(document.body[i], "\\begin_inset Box Frameless") \
1529 or get_value(document.body, 'use_makebox', j) != 1:
1530 del document.body[j]
1533 bend = find_end_of_layout(document.body, blay)
1534 if bend == -1 or bend > z:
1535 document.warning("Malformed LyX document: Can't find end of layout in box.")
1538 # determine the alignment
1539 align = get_quoted_value(document.body, 'hor_pos', i, blay, "c")
1540 # determine the width
1541 length = get_quoted_value(document.body, 'width', i, blay, "50col%")
1542 length = latex_length(length)[1]
1543 # remove the \end_layout \end_inset pair
1544 document.body[bend:z + 1] = put_cmd_in_ert("}")
1545 subst = "\\makebox[" + length + "][" \
1547 document.body[i:blay + 1] = put_cmd_in_ert(subst)
1551 def convert_use_makebox(document):
1552 " Adds use_makebox option for boxes "
1555 i = find_token(document.body, '\\begin_inset Box', i)
1558 # all of this is to make sure we actually find the use_parbox
1559 # that is an option for this box, not some text elsewhere.
1560 z = find_end_of_inset(document.body, i)
1562 document.warning("Can't find end of box inset!!")
1565 blay = find_token(document.body, "\\begin_layout", i, z)
1567 document.warning("Can't find layout in box inset!!")
1570 # so now we are looking for use_parbox before the box's layout
1571 k = find_token(document.body, 'use_parbox', i, blay)
1573 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1576 document.body.insert(k + 1, "use_makebox 0")
1577 i = blay + 1 # not z + 1 (box insets may be nested)
1580 def revert_IEEEtran(document):
1581 " Convert IEEEtran layouts and styles to TeX code "
1583 if document.textclass != "IEEEtran":
1586 revert_flex_inset(document.body, "IEEE membership", "\\IEEEmembership")
1587 revert_flex_inset(document.body, "Lowercase", "\\MakeLowercase")
1589 layouts = ("Special Paper Notice", "After Title Text", "Publication ID",
1590 "Page headings", "Biography without photo")
1591 latexcmd = {"Special Paper Notice": "\\IEEEspecialpapernotice",
1592 "After Title Text": "\\IEEEaftertitletext",
1593 "Publication ID": "\\IEEEpubid"}
1594 obsoletedby = {"Page headings": "MarkBoth",
1595 "Biography without photo": "BiographyNoPhoto"}
1597 for layout in layouts:
1600 i = find_token(document.body, '\\begin_layout ' + layout, i)
1603 j = find_end_of_layout(document.body, i)
1605 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1608 if layout in list(obsoletedby.keys()):
1609 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1612 content = lyx2latex(document, document.body[i:j + 1])
1613 add_to_preamble(document, [latexcmd[layout] + "{" + content + "}"])
1614 del document.body[i:j + 1]
1615 # no need to reset i
1618 def convert_prettyref(document):
1619 " Converts prettyref references to neutral formatted refs "
1620 re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
1621 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
1625 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
1628 j = find_end_of_inset(document.body, i)
1630 document.warning("Malformed LyX document: No end of InsetRef!")
1633 k = find_token(document.body, "LatexCommand prettyref", i, j)
1635 document.body[k] = "LatexCommand formatted"
1637 document.header.insert(-1, "\\use_refstyle 0")
1640 def revert_refstyle(document):
1641 " Reverts neutral formatted refs to prettyref "
1642 re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
1643 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
1647 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
1650 j = find_end_of_inset(document.body, i)
1652 document.warning("Malformed LyX document: No end of InsetRef")
1655 k = find_token(document.body, "LatexCommand formatted", i, j)
1657 document.body[k] = "LatexCommand prettyref"
1659 i = find_token(document.header, "\\use_refstyle", 0)
1661 document.header.pop(i)
1664 def revert_nameref(document):
1665 " Convert namerefs to regular references "
1666 cmds = ["Nameref", "nameref"]
1668 rx = re.compile(r'reference "(.*)"')
1671 oldcmd = "LatexCommand " + cmd
1673 # It seems better to look for this, as most of the reference
1674 # insets won't be ones we care about.
1675 i = find_token(document.body, oldcmd, i)
1680 # Make sure it is actually in an inset!
1681 # A normal line could begin with "LatexCommand nameref"!
1682 val = is_in_inset(document.body, cmdloc, \
1683 "\\begin_inset CommandInset ref")
1688 # ok, so it is in an InsetRef
1689 refline = find_token(document.body, "reference", stins, endins)
1691 document.warning("Can't find reference for inset at line " + stinst + "!!")
1693 m = rx.match(document.body[refline])
1695 document.warning("Can't match reference line: " + document.body[ref])
1699 newcontent = put_cmd_in_ert('\\' + cmd + '{' + ref + '}')
1700 document.body[stins:endins + 1] = newcontent
1703 add_to_preamble(document, ["\usepackage{nameref}"])
1706 def remove_Nameref(document):
1707 " Convert Nameref commands to nameref commands "
1710 # It seems better to look for this, as most of the reference
1711 # insets won't be ones we care about.
1712 i = find_token(document.body, "LatexCommand Nameref" , i)
1718 # Make sure it is actually in an inset!
1719 val = is_in_inset(document.body, cmdloc, \
1720 "\\begin_inset CommandInset ref")
1723 document.body[cmdloc] = "LatexCommand nameref"
1726 def revert_mathrsfs(document):
1727 " Load mathrsfs if \mathrsfs us use in the document "
1729 for line in document.body:
1730 if line.find("\\mathscr{") != -1:
1731 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
1735 def convert_flexnames(document):
1736 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
1739 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
1741 i = find_token(document.body, "\\begin_inset Flex", i)
1744 m = rx.match(document.body[i])
1746 document.body[i] = "\\begin_inset Flex " + m.group(1)
1751 "Alert" : "CharStyle:Alert",
1752 "Code" : "CharStyle:Code",
1753 "Concepts" : "CharStyle:Concepts",
1754 "E-Mail" : "CharStyle:E-Mail",
1755 "Emph" : "CharStyle:Emph",
1756 "Expression" : "CharStyle:Expression",
1757 "Initial" : "CharStyle:Initial",
1758 "Institute" : "CharStyle:Institute",
1759 "Meaning" : "CharStyle:Meaning",
1760 "Noun" : "CharStyle:Noun",
1761 "Strong" : "CharStyle:Strong",
1762 "Structure" : "CharStyle:Structure",
1763 "ArticleMode" : "Custom:ArticleMode",
1764 "Endnote" : "Custom:Endnote",
1765 "Glosse" : "Custom:Glosse",
1766 "PresentationMode" : "Custom:PresentationMode",
1767 "Tri-Glosse" : "Custom:Tri-Glosse"
1771 "Abbrev" : "Element:Abbrev",
1772 "CCC-Code" : "Element:CCC-Code",
1773 "Citation-number" : "Element:Citation-number",
1774 "City" : "Element:City",
1775 "Code" : "Element:Code",
1776 "CODEN" : "Element:CODEN",
1777 "Country" : "Element:Country",
1778 "Day" : "Element:Day",
1779 "Directory" : "Element:Directory",
1780 "Dscr" : "Element:Dscr",
1781 "Email" : "Element:Email",
1782 "Emph" : "Element:Emph",
1783 "Filename" : "Element:Filename",
1784 "Firstname" : "Element:Firstname",
1785 "Fname" : "Element:Fname",
1786 "GuiButton" : "Element:GuiButton",
1787 "GuiMenu" : "Element:GuiMenu",
1788 "GuiMenuItem" : "Element:GuiMenuItem",
1789 "ISSN" : "Element:ISSN",
1790 "Issue-day" : "Element:Issue-day",
1791 "Issue-months" : "Element:Issue-months",
1792 "Issue-number" : "Element:Issue-number",
1793 "KeyCap" : "Element:KeyCap",
1794 "KeyCombo" : "Element:KeyCombo",
1795 "Keyword" : "Element:Keyword",
1796 "Literal" : "Element:Literal",
1797 "MenuChoice" : "Element:MenuChoice",
1798 "Month" : "Element:Month",
1799 "Orgdiv" : "Element:Orgdiv",
1800 "Orgname" : "Element:Orgname",
1801 "Postcode" : "Element:Postcode",
1802 "SS-Code" : "Element:SS-Code",
1803 "SS-Title" : "Element:SS-Title",
1804 "State" : "Element:State",
1805 "Street" : "Element:Street",
1806 "Surname" : "Element:Surname",
1807 "Volume" : "Element:Volume",
1808 "Year" : "Element:Year"
1812 def revert_flexnames(document):
1813 if document.backend == "latex":
1814 flexlist = flex_insets
1816 flexlist = flex_elements
1818 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
1821 i = find_token(document.body, "\\begin_inset Flex", i)
1824 m = rx.match(document.body[i])
1826 document.warning("Illegal flex inset: " + document.body[i])
1830 if style in flexlist:
1831 document.body[i] = "\\begin_inset Flex " + flexlist[style]
1835 def convert_mathdots(document):
1836 " Load mathdots automatically "
1837 i = find_token(document.header, "\\use_mhchem" , 0)
1839 i = find_token(document.header, "\\use_esint" , 0)
1841 document.warning("Malformed LyX document: Can't find \\use_mhchem.")
1843 j = find_token(document.preamble, "\\usepackage{mathdots}", 0)
1845 document.header.insert(i + 1, "\\use_mathdots 0")
1847 document.header.insert(i + 1, "\\use_mathdots 2")
1848 del document.preamble[j]
1851 def revert_mathdots(document):
1852 " Load mathdots if used in the document "
1854 mathdots = find_token(document.header, "\\use_mathdots" , 0)
1856 document.warning("No \\use_mathdots line. Assuming auto.")
1858 val = get_value(document.header, "\\use_mathdots", mathdots)
1859 del document.header[mathdots]
1863 document.warning("Invalid \\use_mathdots value: " + val + ". Assuming auto.")
1864 # probably usedots has not been changed, but be safe.
1872 add_to_preamble(document, ["\\usepackage{mathdots}"])
1875 # so we are in the auto case. we want to load mathdots if \iddots is used.
1878 i = find_token(document.body, '\\begin_inset Formula', i)
1881 j = find_end_of_inset(document.body, i)
1883 document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
1886 code = "\n".join(document.body[i:j])
1887 if code.find("\\iddots") != -1:
1888 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}"])
1893 def convert_rule(document):
1894 " Convert \\lyxline to CommandInset line. "
1897 inset = ['\\begin_inset CommandInset line',
1898 'LatexCommand rule',
1902 '\\end_inset', '', '']
1904 # if paragraphs are indented, we may have to unindent to get the
1905 # line to be full-width.
1906 indent = get_value(document.header, "\\paragraph_separation", 0)
1907 have_indent = (indent == "indent")
1910 i = find_token(document.body, "\\lyxline" , i)
1914 # we need to find out if this line follows other content
1915 # in its paragraph. find its layout....
1916 lastlay = find_token_backwards(document.body, "\\begin_layout", i)
1918 document.warning("Can't find layout for line at " + str(i))
1919 # do the best we can.
1920 document.body[i:i+1] = inset
1924 # ...and look for other content before it.
1926 for line in document.body[lastlay + 1:i]:
1927 # is it empty or a paragraph option?
1928 if not line or line[0] == '\\':
1934 document.body[i:i+1] = inset
1936 # we need to unindent, lest the line be too long
1937 document.body.insert(lastlay + 1, "\\noindent")
1940 # so our line is in the middle of a paragraph
1941 # we need to add a new line, lest this line follow the
1942 # other content on that line and run off the side of the page
1943 document.body[i:i+1] = inset
1944 document.body[i:i] = ["\\begin_inset Newline newline", "\\end_inset", ""]
1948 def revert_rule(document):
1949 " Revert line insets to Tex code "
1952 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
1956 j = find_token(document.body, "\\end_inset" , i)
1958 document.warning("Malformed LyX document: Can't find end of line inset.")
1960 # determine the optional offset
1961 offset = get_quoted_value(document.body, 'offset', i, j)
1963 offset = '[' + offset + ']'
1964 # determine the width
1965 width = get_quoted_value(document.body, 'width', i, j, "100col%")
1966 width = latex_length(width)[1]
1967 # determine the height
1968 height = get_quoted_value(document.body, 'height', i, j, "1pt")
1969 height = latex_length(height)[1]
1970 # output the \rule command
1971 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
1972 document.body[i:j + 1] = put_cmd_in_ert(subst)
1973 i += len(subst) - (j - i)
1976 def revert_diagram(document):
1977 " Add the feyn package if \\Diagram is used in math "
1980 i = find_token(document.body, '\\begin_inset Formula', i)
1983 j = find_end_of_inset(document.body, i)
1985 document.warning("Malformed LyX document: Can't find end of Formula inset.")
1987 lines = "\n".join(document.body[i:j])
1988 if lines.find("\\Diagram") == -1:
1991 add_to_preamble(document, ["\\usepackage{feyn}"])
1992 # only need to do it once!
1995 chapters = ("amsbook", "book", "docbook-book", "elsart", "extbook", "extreport",
1996 "jbook", "jreport", "jsbook", "literate-book", "literate-report", "memoir",
1997 "mwbk", "mwrep", "recipebook", "report", "scrbook", "scrreprt", "svmono",
1998 "svmult", "tbook", "treport", "tufte-book")
2000 def convert_bibtex_clearpage(document):
2001 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2003 if document.textclass not in chapters:
2006 i = find_token(document.header, '\\papersides', 0)
2009 document.warning("Malformed LyX document: Can't find papersides definition.")
2010 document.warning("Assuming single sided.")
2013 val = get_value(document.header, "\\papersides", i)
2018 if sides != 1 and sides != 2:
2019 document.warning("Invalid papersides value: " + val)
2020 document.warning("Assuming single sided.")
2025 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2029 k = find_end_of_inset(document.body, j)
2031 document.warning("Can't find end of Bibliography inset at line " + str(j))
2035 # only act if there is the option "bibtotoc"
2036 val = get_value(document.body, 'options', j, k)
2038 document.warning("Can't find options for bibliography inset at line " + str(j))
2042 if val.find("bibtotoc") == -1:
2046 # so we want to insert a new page right before the paragraph that
2047 # this bibliography thing is in.
2048 lay = find_token_backwards(document.body, "\\begin_layout", j)
2050 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2057 cmd = "cleardoublepage"
2058 subst = ['\\begin_layout Standard',
2059 '\\begin_inset Newpage ' + cmd,
2060 '\\end_inset', '', '',
2062 document.body[lay:lay] = subst
2066 def check_passthru(document):
2067 tc = document.textclass
2068 ok = (tc == "literate-article" or tc == "literate-book" or tc == "literate-report")
2070 mods = document.get_module_list()
2072 if mod == "sweave" or mod == "noweb":
2078 def convert_passthru(document):
2079 " http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161298.html "
2080 if not check_passthru:
2083 rx = re.compile("\\\\begin_layout \s*(\w+)")
2085 for lay in ["Chunk", "Scrap"]:
2087 beg = find_token(document.body, "\\begin_layout " + lay, beg)
2090 end = find_end_of_layout(document.body, beg)
2092 document.warning("Can't find end of layout at line " + str(beg))
2096 # we are now going to replace newline insets within this layout
2097 # by new instances of this layout. so we have repeated layouts
2098 # instead of newlines.
2100 # if the paragraph has any customization, however, we do not want to
2101 # do the replacement.
2102 if document.body[beg + 1].startswith("\\"):
2108 ns = find_token(document.body, "\\begin_inset Newline newline", ns, end)
2111 ne = find_end_of_inset(document.body, ns)
2112 if ne == -1 or ne > end:
2113 document.warning("Can't find end of inset at line " + str(nb))
2116 if document.body[ne + 1] == "":
2118 subst = ["\\end_layout", "", "\\begin_layout " + lay]
2119 document.body[ns:ne + 1] = subst
2120 # now we need to adjust end, in particular, but might as well
2121 # do ns properly, too
2122 newlines = (ne - ns) - len(subst)
2126 # ok, we now want to find out if the next layout is the
2127 # same as this one. if so, we will insert an extra copy of it
2129 next = find_token(document.body, "\\begin_layout", end)
2131 m = rx.match(document.body[next])
2133 nextlay = m.group(1)
2135 subst = ["\\begin_layout " + lay, "", "\\end_layout", ""]
2136 document.body[next:next] = subst
2140 beg += 4 # for the extra layout
2143 def revert_passthru(document):
2144 " http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161298.html "
2145 if not check_passthru:
2147 rx = re.compile("\\\\begin_layout \s*(\w+)")
2149 for lay in ["Chunk", "Scrap"]:
2151 beg = find_token(document.body, "\\begin_layout " + lay, beg)
2154 end = find_end_of_layout(document.body, beg)
2156 document.warning("Can't find end of layout at line " + str(beg))
2160 # we now want to find out if the next layout is the
2161 # same as this one. but we will need to do this over and
2164 next = find_token(document.body, "\\begin_layout", end)
2167 m = rx.match(document.body[next])
2170 nextlay = m.group(1)
2173 # so it is the same layout again. we now want to know if it is empty.
2174 # but first let's check and make sure there is no content between the
2175 # two layouts. i'm not sure if that can happen or not.
2176 for l in range(end + 1, next):
2177 document.warning("c'" + document.body[l] + "'")
2178 if document.body[l] != "":
2179 document.warning("Found content between adjacent " + lay + " layouts!")
2181 nextend = find_end_of_layout(document.body, next)
2183 document.warning("Can't find end of layout at line " + str(next))
2186 for l in range(next + 1, nextend):
2187 document.warning("e'" + document.body[l] + "'")
2188 if document.body[l] != "":
2192 # empty layouts just get removed
2193 # should we check if it's before yet another such layout?
2194 del document.body[next : nextend + 1]
2195 # and we do not want to check again. we know the next layout
2196 # should be another Chunk and should be left as is.
2199 # if it's not empty, then we want to insert a newline in place
2200 # of the layout switch
2201 subst = ["\\begin_inset Newline newline", "\\end_inset", ""]
2202 document.body[end : next + 1] = subst
2203 # and now we have to find the end of the new, larger layout
2204 newend = find_end_of_layout(document.body, beg)
2206 document.warning("Can't find end of new layout at line " + str(beg))
2212 def revert_multirowOffset(document):
2213 " Revert multirow cells with offset in tables to TeX-code"
2214 # this routine is the same as the revert_multirow routine except that
2215 # it checks additionally for the offset
2217 # first, let's find out if we need to do anything
2218 i = find_token(document.body, '<cell multirow="3" mroffset=', 0)
2222 add_to_preamble(document, ["\\usepackage{multirow}"])
2224 rgx = re.compile(r'mroffset="[^"]+?"')
2228 # find begin/end of table
2229 begin_table = find_token(document.body, '<lyxtabular version=', begin_table)
2230 if begin_table == -1:
2232 end_table = find_end_of(document.body, begin_table, '<lyxtabular', '</lyxtabular>')
2234 document.warning("Malformed LyX document: Could not find end of table.")
2237 # does this table have multirow?
2238 i = find_token(document.body, '<cell multirow="3"', begin_table, end_table)
2240 begin_table = end_table
2243 # store the number of rows and columns
2244 numrows = get_option_value(document.body[begin_table], "rows")
2245 numcols = get_option_value(document.body[begin_table], "columns")
2247 numrows = int(numrows)
2248 numcols = int(numcols)
2250 document.warning("Unable to determine rows and columns!")
2251 begin_table = end_table
2256 # collect info on rows and columns of this table.
2257 begin_row = begin_table
2258 for row in range(numrows):
2259 begin_row = find_token(document.body, '<row>', begin_row, end_table)
2261 document.warning("Can't find row " + str(row + 1))
2263 end_row = find_end_of(document.body, begin_row, '<row>', '</row>')
2265 document.warning("Can't find end of row " + str(row + 1))
2267 begin_cell = begin_row
2268 multirows.append([])
2269 for column in range(numcols):
2270 begin_cell = find_token(document.body, '<cell ', begin_cell, end_row)
2271 if begin_cell == -1:
2272 document.warning("Can't find column " + str(column + 1) + \
2273 "in row " + str(row + 1))
2276 # this will fail if someone puts "</cell>" in a cell, but
2277 # that seems fairly unlikely.
2278 end_cell = find_end_of(document.body, begin_cell, '<cell', '</cell>')
2280 document.warning("Can't find end of column " + str(column + 1) + \
2281 "in row " + str(row + 1))
2283 multirows[row].append([begin_cell, end_cell, 0])
2284 if document.body[begin_cell].find('multirow="3" mroffset=') != -1:
2285 multirows[row][column][2] = 3 # begin multirow
2286 mrstarts.append([row, column])
2287 elif document.body[begin_cell].find('multirow="4"') != -1:
2288 multirows[row][column][2] = 4 # in multirow
2289 begin_cell = end_cell
2291 # end of table info collection
2293 # work from the back to avoid messing up numbering
2299 col_width = get_option_value(document.body[begin_table + 2 + col], "width")
2300 # "0pt" means that no width is specified
2301 if not col_width or col_width == "0pt":
2303 # determine the number of cells that are part of the multirow
2305 for r in range(row + 1, numrows):
2306 if multirows[r][col][2] != 4:
2309 # take the opportunity to revert this line
2310 lineno = multirows[r][col][0]
2311 document.body[lineno] = document.body[lineno].\
2312 replace(' multirow="4" ', ' ').\
2313 replace('valignment="middle"', 'valignment="top"').\
2314 replace(' topline="true" ', ' ')
2315 # remove bottom line of previous multirow-part cell
2316 lineno = multirows[r-1][col][0]
2317 document.body[lineno] = document.body[lineno].replace(' bottomline="true" ', ' ')
2318 # revert beginning cell
2319 bcell = multirows[row][col][0]
2320 ecell = multirows[row][col][1]
2321 offset = get_option_value(document.body[bcell], "mroffset")
2322 document.body[bcell] = document.body[bcell].\
2323 replace(' multirow="3" ', ' ').\
2324 replace('valignment="middle"', 'valignment="top"')
2325 # remove mroffset option
2326 document.body[bcell] = rgx.sub('', document.body[bcell])
2328 blay = find_token(document.body, "\\begin_layout", bcell, ecell)
2330 document.warning("Can't find layout for cell!")
2332 bend = find_end_of_layout(document.body, blay)
2334 document.warning("Can't find end of layout for cell!")
2336 # do the later one first, so as not to mess up the numbering
2337 # we are wrapping the whole cell in this ert
2338 # so before the end of the layout...
2339 document.body[bend:bend] = put_cmd_in_ert("}")
2340 # ...and after the beginning
2341 document.body[blay + 1:blay + 1] = \
2342 put_cmd_in_ert("\\multirow{" + str(nummrs) + "}{" + col_width + "}[" \
2345 # on to the next table
2346 begin_table = end_table
2349 def revert_script(document):
2350 " Convert subscript/superscript inset to TeX code "
2352 foundsubscript = False
2354 i = find_token(document.body, '\\begin_inset script', i)
2357 z = find_end_of_inset(document.body, i)
2359 document.warning("Malformed LyX document: Can't find end of script inset.")
2362 blay = find_token(document.body, "\\begin_layout", i, z)
2364 document.warning("Malformed LyX document: Can't find layout in script inset.")
2368 if check_token(document.body[i], "\\begin_inset script subscript"):
2369 subst = '\\textsubscript{'
2370 foundsubscript = True
2371 elif check_token(document.body[i], "\\begin_inset script superscript"):
2372 subst = '\\textsuperscript{'
2374 document.warning("Malformed LyX document: Unknown type of script inset.")
2377 bend = find_end_of_layout(document.body, blay)
2378 if bend == -1 or bend > z:
2379 document.warning("Malformed LyX document: Can't find end of layout in script inset.")
2382 # remove the \end_layout \end_inset pair
2383 document.body[bend:z + 1] = put_cmd_in_ert("}")
2384 document.body[i:blay + 1] = put_cmd_in_ert(subst)
2386 # these classes provide a \textsubscript command:
2387 # FIXME: Would be nice if we could use the information of the .layout file here
2388 classes = ["memoir", "scrartcl", "scrbook", "scrlttr2", "scrreprt"]
2389 if foundsubscript and find_token_exact(classes, document.textclass, 0) == -1:
2390 add_to_preamble(document, ['\\usepackage{subscript}'])
2393 def convert_use_xetex(document):
2394 " convert \\use_xetex to \\use_non_tex_fonts "
2395 i = find_token(document.header, "\\use_xetex", 0)
2397 document.header.insert(-1, "\\use_non_tex_fonts 0")
2399 val = get_value(document.header, "\\use_xetex", 0)
2400 document.header[i] = "\\use_non_tex_fonts " + val
2403 def revert_use_xetex(document):
2404 " revert \\use_non_tex_fonts to \\use_xetex "
2406 i = find_token(document.header, "\\use_non_tex_fonts", 0)
2408 document.warning("Malformed document. No \\use_non_tex_fonts param!")
2411 val = get_value(document.header, "\\use_non_tex_fonts", 0)
2412 document.header[i] = "\\use_xetex " + val
2415 def revert_labeling(document):
2416 koma = ("scrartcl", "scrarticle-beamer", "scrbook", "scrlettr",
2417 "scrlttr2", "scrreprt")
2418 if document.textclass in koma:
2422 i = find_token_exact(document.body, "\\begin_layout Labeling", i)
2425 document.body[i] = "\\begin_layout List"
2428 def revert_langpack(document):
2429 " revert \\language_package parameter "
2431 i = find_token(document.header, "\\language_package", 0)
2433 document.warning("Malformed document. No \\language_package param!")
2436 del document.header[i]
2439 def convert_langpack(document):
2440 " Add \\language_package parameter "
2441 i = find_token(document.header, "\language" , 0)
2443 document.warning("Malformed document. No \\language defined!")
2446 document.header.insert(i + 1, "\\language_package default")
2449 def revert_tabularwidth(document):
2452 i = find_token(document.body, "\\begin_inset Tabular", i)
2455 j = find_end_of_inset(document.body, i)
2457 document.warning("Unable to find end of Tabular inset at line " + str(i))
2461 features = find_token(document.body, "<features", i, j)
2463 document.warning("Can't find any features in Tabular inset at line " + str(i))
2466 if document.body[features].find('alignment="tabularwidth"') != -1:
2467 remove_option(document.body, features, 'tabularwidth')
2469 def revert_html_css_as_file(document):
2470 if not del_token(document.header, '\\html_css_as_file', 0):
2471 document.warning("Malformed LyX document: Missing \\html_css_as_file.")
2478 supported_versions = ["2.0.0","2.0"]
2479 convert = [[346, []],
2485 [352, [convert_splitindex]],
2492 [359, [convert_nomencl_width]],
2502 [369, [convert_author_id]],
2504 [371, [convert_mhchem]],
2506 [373, [merge_gbrief]],
2512 [379, [convert_math_output]],
2522 [389, [convert_html_quotes]],
2526 [393, [convert_optarg]],
2527 [394, [convert_use_makebox]],
2530 [397, [remove_Nameref]],
2532 [399, [convert_mathdots]],
2533 [400, [convert_rule]],
2535 [402, [convert_bibtex_clearpage]],
2536 [403, [convert_flexnames]],
2537 [404, [convert_prettyref]],
2539 [406, [convert_passthru]],
2542 [409, [convert_use_xetex]],
2544 [411, [convert_langpack]],
2549 revert = [[412, [revert_html_css_as_file]],
2550 [411, [revert_tabularwidth]],
2551 [410, [revert_langpack]],
2552 [409, [revert_labeling]],
2553 [408, [revert_use_xetex]],
2554 [407, [revert_script]],
2555 [406, [revert_multirowOffset]],
2556 [405, [revert_passthru]],
2558 [403, [revert_refstyle]],
2559 [402, [revert_flexnames]],
2561 [400, [revert_diagram]],
2562 [399, [revert_rule]],
2563 [398, [revert_mathdots]],
2564 [397, [revert_mathrsfs]],
2566 [395, [revert_nameref]],
2567 [394, [revert_DIN_C_pagesizes]],
2568 [393, [revert_makebox]],
2569 [392, [revert_argument]],
2571 [390, [revert_align_decimal, revert_IEEEtran]],
2572 [389, [revert_output_sync]],
2573 [388, [revert_html_quotes]],
2574 [387, [revert_pagesizes]],
2575 [386, [revert_math_scale]],
2576 [385, [revert_lyx_version]],
2577 [384, [revert_shadedboxcolor]],
2578 [383, [revert_fontcolor]],
2579 [382, [revert_turkmen]],
2580 [381, [revert_notefontcolor]],
2581 [380, [revert_equalspacing_xymatrix]],
2582 [379, [revert_inset_preview]],
2583 [378, [revert_math_output]],
2585 [376, [revert_multirow]],
2586 [375, [revert_includeall]],
2587 [374, [revert_includeonly]],
2588 [373, [revert_html_options]],
2589 [372, [revert_gbrief]],
2590 [371, [revert_fontenc]],
2591 [370, [revert_mhchem]],
2592 [369, [revert_suppress_date]],
2593 [368, [revert_author_id]],
2594 [367, [revert_hspace_glue_lengths]],
2595 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2596 [365, [revert_percent_skip_lengths]],
2597 [364, [revert_paragraph_indentation]],
2598 [363, [revert_branch_filename]],
2599 [362, [revert_longtable_align]],
2600 [361, [revert_applemac]],
2602 [359, [revert_nomencl_cwidth]],
2603 [358, [revert_nomencl_width]],
2604 [357, [revert_custom_processors]],
2605 [356, [revert_ulinelatex]],
2607 [354, [revert_strikeout]],
2608 [353, [revert_printindexall]],
2609 [352, [revert_subindex]],
2610 [351, [revert_splitindex]],
2611 [350, [revert_backgroundcolor]],
2612 [349, [revert_outputformat]],
2613 [348, [revert_xetex]],
2614 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2615 [346, [revert_tabularvalign]],
2616 [345, [revert_swiss]]
2620 if __name__ == "__main__":