1 # -*- coding: utf-8 -*-
2 # This file is part of lyx2lyx
3 # Copyright (C) 2011 The LyX team
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 """ Convert files to the file format generated by lyx 2.0"""
25 from parser_tools import del_complete_lines, \
26 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
488 strikeout_preamble = ['% for proper underlining',
489 r'\PassOptionsToPackage{normalem}{ulem}',
490 r'\usepackage{ulem}']
492 def convert_strikeout(document):
493 " Remove preamble code loading 'ulem' package. "
494 del_complete_lines(document.preamble,
495 ['% Added by lyx2lyx']+strikeout_preamble)
498 def revert_strikeout(document):
499 " Reverts \\strikeout font attribute "
500 changed = revert_font_attrs(document.body, "\\uuline", "\\uuline")
501 changed = revert_font_attrs(document.body, "\\uwave", "\\uwave") or changed
502 changed = revert_font_attrs(document.body, "\\strikeout", "\\sout") or changed
504 insert_to_preamble(document, strikeout_preamble)
507 ulinelatex_preamble = ['% fix underbar in citations',
508 r'\let\cite@rig\cite',
509 r'\newcommand{\b@xcite}[2][\%]{\def\def@pt{\%}\def\pas@pt{#1}',
510 r' \mbox{\ifx\def@pt\pas@pt\cite@rig{#2}\else\cite@rig[#1]{#2}\fi}}',
511 r'\renewcommand{\underbar}[1]{{\let\cite\b@xcite\uline{#1}}}']
513 def convert_ulinelatex(document):
514 " Remove preamble code for \\uline font attribute. "
515 del_complete_lines(document.preamble,
516 ['% Added by lyx2lyx']+ulinelatex_preamble)
518 def revert_ulinelatex(document):
519 " Add preamble code for \\uline font attribute in citations. "
520 i = find_token(document.body, '\\bar under', 0)
524 document.preamble.index(r'\usepackage{ulem}')
526 insert_to_preamble(document, strikeout_preamble)
527 insert_to_preamble(document, ulinelatex_preamble)
530 def revert_custom_processors(document):
531 " Remove bibtex_command and index_command params "
533 if not del_token(document.header, '\\bibtex_command', 0):
534 document.warning("Malformed LyX document: Missing \\bibtex_command.")
536 if not del_token(document.header, '\\index_command', 0):
537 document.warning("Malformed LyX document: Missing \\index_command.")
540 def convert_nomencl_width(document):
541 " Add set_width param to nomencl_print "
544 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
547 document.body.insert(i + 2, "set_width \"none\"")
551 def revert_nomencl_width(document):
552 " Remove set_width param from nomencl_print "
555 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
558 j = find_end_of_inset(document.body, i)
559 if not del_token(document.body, "set_width", i, j):
560 document.warning("Can't find set_width option for nomencl_print!")
564 def revert_nomencl_cwidth(document):
565 " Remove width param from nomencl_print "
568 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
571 j = find_end_of_inset(document.body, i)
572 l = find_token(document.body, "width", i, j)
576 width = get_quoted_value(document.body, "width", i, j)
578 insert_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
582 def revert_applemac(document):
583 " Revert applemac encoding to auto "
584 if document.encoding != "applemac":
586 document.encoding = "auto"
587 i = find_token(document.header, "\\encoding", 0)
589 document.header[i] = "\\encoding auto"
592 def revert_longtable_align(document):
593 " Remove longtable alignment setting "
596 i = find_token(document.body, "\\begin_inset Tabular", i)
599 end = find_end_of_inset(document.body, i)
601 document.warning("Can't find end of inset at line " + str(i))
604 fline = find_token(document.body, "<features", i, end)
606 document.warning("Can't find features for inset at line " + str(i))
609 j = document.body[fline].find("longtabularalignment")
613 # FIXME Is this correct? It wipes out everything after the
615 document.body[fline] = document.body[fline][:j - 1] + '>'
616 # since there could be a tabular inside this one, we
617 # cannot jump to end.
621 def revert_branch_filename(document):
622 " Remove \\filename_suffix parameter from branches "
625 i = find_token(document.header, "\\filename_suffix", i)
628 del document.header[i]
631 def revert_paragraph_indentation(document):
632 " Revert custom paragraph indentation to preamble code "
633 i = find_token(document.header, "\\paragraph_indentation", 0)
636 length = get_value(document.header, "\\paragraph_indentation", i)
637 # we need only remove the line if indentation is default
638 if length != "default":
639 # handle percent lengths
640 length = latex_length(length)[1]
641 insert_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
642 del document.header[i]
645 def revert_percent_skip_lengths(document):
646 " Revert relative lengths for paragraph skip separation to preamble code "
647 i = find_token(document.header, "\\defskip", 0)
650 length = get_value(document.header, "\\defskip", i)
651 # only revert when a custom length was set and when
652 # it used a percent length
653 if length in ('smallskip', 'medskip', 'bigskip'):
655 # handle percent lengths
656 percent, length = latex_length(length)
658 insert_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
659 # set defskip to medskip as default
660 document.header[i] = "\\defskip medskip"
663 def revert_percent_vspace_lengths(document):
664 " Revert relative VSpace lengths to ERT "
667 i = find_token(document.body, "\\begin_inset VSpace", i)
670 # only revert if a custom length was set and if
671 # it used a percent length
672 r = re.compile(r'\\begin_inset VSpace (.*)$')
673 m = r.match(document.body[i])
675 if length in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
678 # check if the space has a star (protected space)
679 protected = (document.body[i].rfind("*") != -1)
681 length = length.rstrip('*')
682 # handle percent lengths
683 percent, length = latex_length(length)
684 # revert the VSpace inset to ERT
687 subst = put_cmd_in_ert("\\vspace*{" + length + "}")
689 subst = put_cmd_in_ert("\\vspace{" + length + "}")
690 document.body[i:i + 2] = subst
694 def revert_percent_hspace_lengths(document):
695 " Revert relative HSpace lengths to ERT "
698 i = find_token_exact(document.body, "\\begin_inset space \\hspace", i)
701 j = find_end_of_inset(document.body, i)
703 document.warning("Can't find end of inset at line " + str(i))
706 # only revert if a custom length was set...
707 length = get_value(document.body, '\\length', i + 1, j)
709 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
713 if document.body[i].find("\\hspace*{}") != -1:
715 # ...and if it used a percent length
716 percent, length = latex_length(length)
717 # revert the HSpace inset to ERT
719 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
720 document.body[i:j + 1] = subst
721 # if we did a substitution, this will still be ok
725 def revert_hspace_glue_lengths(document):
726 " Revert HSpace glue lengths to ERT "
729 i = find_token_exact(document.body, "\\begin_inset space \\hspace", i)
732 j = find_end_of_inset(document.body, i)
734 document.warning("Can't find end of inset at line " + str(i))
737 length = get_value(document.body, '\\length', i + 1, j)
739 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
743 if document.body[i].find("\\hspace*{}") != -1:
745 # only revert if the length contains a plus or minus at pos != 0
746 if length.find('-',1) != -1 or length.find('+',1) != -1:
747 # handle percent lengths
748 length = latex_length(length)[1]
749 # revert the HSpace inset to ERT
750 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
751 document.body[i:j+1] = subst
755 def convert_author_id(document):
756 " Add the author_id to the \\author definition and make sure 0 is not used"
759 re_author = re.compile(r'(\\author) (\".*\")\s*(.*)$')
762 i = find_token(document.header, "\\author", i)
765 m = re_author.match(document.header[i])
769 document.header[i] = "\\author %i %s %s" % (anum, name, email)
775 i = find_token(document.body, "\\change_", i)
778 change = document.body[i].split(' ');
781 author_id = int(change[1])
783 document.body[i] = "%s %i %s" % (type, author_id + 1, time)
787 def revert_author_id(document):
788 " Remove the author_id from the \\author definition "
791 rx = re.compile(r'(\\author)\s+(-?\d+)\s+(\".*\")\s*(.*)$')
795 i = find_token(document.header, "\\author", i)
798 m = rx.match(document.header[i])
800 author_id = int(m.group(2))
801 idmap[author_id] = anum
804 document.header[i] = "\\author %s %s" % (name, email)
806 # FIXME Should this be incremented if we didn't match?
811 i = find_token(document.body, "\\change_", i)
814 change = document.body[i].split(' ');
817 author_id = int(change[1])
819 document.body[i] = "%s %i %s" % (type, idmap[author_id], time)
823 def revert_suppress_date(document):
824 " Revert suppressing of default document date to preamble code "
825 i = find_token(document.header, "\\suppress_date", 0)
828 # remove the preamble line and write to the preamble
829 # when suppress_date was true
830 date = str2bool(get_value(document.header, "\\suppress_date", i))
832 add_to_preamble(document, ["\\date{}"])
833 del document.header[i]
836 mhchem_preamble = [r"\PassOptionsToPackage{version=3}{mhchem}",
837 r"\usepackage{mhchem}"]
839 def convert_mhchem(document):
840 "Set mhchem to off for versions older than 1.6.x"
841 if document.initial_format < 277:
842 # LyX 1.5.x and older did never load mhchem.
843 # Therefore we must switch it off: Documents that use mhchem have
844 # a manual \usepackage anyway, and documents not using mhchem but
845 # custom macros with the same names as mhchem commands might get
846 # corrupted if mhchem is automatically loaded.
849 # LyX 1.6.x did always load mhchem automatically.
851 i = find_token(document.header, "\\use_esint", 0)
854 i = find_token(document.header, "\\use_amsmath", 0)
856 document.warning("Malformed LyX document: "
857 "Could not find amsmath or esint setting.")
859 document.header.insert(i + 1, "\\use_mhchem %d" % mhchem)
860 # remove LyX-inserted preamble
862 del_complete_lines(document.preamble,
863 ['% Added by lyx2lyx']+mhchem_preamble)
866 def revert_mhchem(document):
867 "Revert mhchem loading to preamble code."
869 mhchem = get_value(document.header, "\\use_mhchem", delete=True)
873 document.warning("Malformed LyX document: "
874 "Could not find mhchem setting.")
876 # mhchem in {0: "off", 1: "auto", 2: "on"}
878 if mhchem == 1: # "auto"
880 while i != 1 and mhchem == 1:
881 i = find_token(document.body, "\\begin_inset Formula", i)
882 j = find_end_of_inset(document.body, i)
885 if (True for line in document.body[i:j]
886 if r"\ce{" in line or r"\cf{" in line):
892 and find_token(document.preamble, r"\usepackage{mhchem}") == -1):
893 insert_to_preamble(document, mhchem_preamble)
896 def revert_fontenc(document):
897 " Remove fontencoding param "
898 if not del_token(document.header, '\\fontencoding', 0):
899 document.warning("Malformed LyX document: Missing \\fontencoding.")
902 def merge_gbrief(document):
903 " Merge g-brief-en and g-brief-de to one class "
905 if document.textclass != "g-brief-de":
906 if document.textclass == "g-brief-en":
907 document.textclass = "g-brief"
908 document.set_textclass()
911 obsoletedby = { "Brieftext": "Letter",
912 "Unterschrift": "Signature",
914 "Zusatz": "Addition",
917 "RetourAdresse": "ReturnAddress",
918 "MeinZeichen": "MyRef",
919 "IhrZeichen": "YourRef",
920 "IhrSchreiben": "YourMail",
923 "Konto": "BankAccount",
924 "Postvermerk": "PostalComment",
925 "Adresse": "Address",
927 "Betreff": "Reference",
934 i = find_token(document.body, "\\begin_layout", i)
938 layout = document.body[i][14:]
939 if layout in obsoletedby:
940 document.body[i] = "\\begin_layout " + obsoletedby[layout]
944 document.textclass = "g-brief"
945 document.set_textclass()
948 def revert_gbrief(document):
949 " Revert g-brief to g-brief-en "
950 if document.textclass == "g-brief":
951 document.textclass = "g-brief-en"
952 document.set_textclass()
955 def revert_html_options(document):
956 " Remove html options "
957 del_token(document.header, '\\html_use_mathml', 0)
958 del_token(document.header, '\\html_be_strict', 0)
961 def revert_includeonly(document):
964 i = find_token(document.header, "\\begin_includeonly", i)
967 j = find_end_of(document.header, i, "\\begin_includeonly", "\\end_includeonly")
969 document.warning("Unable to find end of includeonly section!!")
971 document.header[i : j + 1] = []
974 def revert_includeall(document):
975 " Remove maintain_unincluded_children param "
976 del_token(document.header, '\\maintain_unincluded_children', 0)
979 def revert_multirow(document):
980 " Revert multirow cells in tables to TeX-code"
982 # first, let's find out if we need to do anything
983 # cell type 3 is multirow begin cell
984 i = find_token(document.body, '<cell multirow="3"', 0)
988 add_to_preamble(document, ["\\usepackage{multirow}"])
992 # find begin/end of table
993 begin_table = find_token(document.body, '<lyxtabular version=', begin_table)
994 if begin_table == -1:
996 end_table = find_end_of(document.body, begin_table, '<lyxtabular', '</lyxtabular>')
998 document.warning("Malformed LyX document: Could not find end of table.")
1001 # does this table have multirow?
1002 i = find_token(document.body, '<cell multirow="3"', begin_table, end_table)
1004 begin_table = end_table
1007 # store the number of rows and columns
1008 numrows = get_option_value(document.body[begin_table], "rows")
1009 numcols = get_option_value(document.body[begin_table], "columns")
1011 numrows = int(numrows)
1012 numcols = int(numcols)
1014 document.warning("Unable to determine rows and columns!")
1015 begin_table = end_table
1020 # collect info on rows and columns of this table.
1021 begin_row = begin_table
1022 for row in range(numrows):
1023 begin_row = find_token(document.body, '<row>', begin_row, end_table)
1025 document.warning("Can't find row " + str(row + 1))
1027 end_row = find_end_of(document.body, begin_row, '<row>', '</row>')
1029 document.warning("Can't find end of row " + str(row + 1))
1031 begin_cell = begin_row
1032 multirows.append([])
1033 for column in range(numcols):
1034 begin_cell = find_token(document.body, '<cell ', begin_cell, end_row)
1035 if begin_cell == -1:
1036 document.warning("Can't find column " + str(column + 1) + \
1037 "in row " + str(row + 1))
1040 # this will fail if someone puts "</cell>" in a cell, but
1041 # that seems fairly unlikely.
1042 end_cell = find_end_of(document.body, begin_cell, '<cell', '</cell>')
1044 document.warning("Can't find end of column " + str(column + 1) + \
1045 "in row " + str(row + 1))
1047 multirows[row].append([begin_cell, end_cell, 0])
1048 if document.body[begin_cell].find('multirow="3"') != -1:
1049 multirows[row][column][2] = 3 # begin multirow
1050 mrstarts.append([row, column])
1051 elif document.body[begin_cell].find('multirow="4"') != -1:
1052 multirows[row][column][2] = 4 # in multirow
1053 begin_cell = end_cell
1055 # end of table info collection
1057 # work from the back to avoid messing up numbering
1063 col_width = get_option_value(document.body[begin_table + 2 + col], "width")
1064 # "0pt" means that no width is specified
1065 if not col_width or col_width == "0pt":
1067 # determine the number of cells that are part of the multirow
1069 for r in range(row + 1, numrows):
1070 if multirows[r][col][2] != 4:
1073 # take the opportunity to revert this line
1074 lineno = multirows[r][col][0]
1075 document.body[lineno] = document.body[lineno].\
1076 replace(' multirow="4" ', ' ').\
1077 replace('valignment="middle"', 'valignment="top"').\
1078 replace(' topline="true" ', ' ')
1079 # remove bottom line of previous multirow-part cell
1080 lineno = multirows[r-1][col][0]
1081 document.body[lineno] = document.body[lineno].replace(' bottomline="true" ', ' ')
1082 # revert beginning cell
1083 bcell = multirows[row][col][0]
1084 ecell = multirows[row][col][1]
1085 document.body[bcell] = document.body[bcell].\
1086 replace(' multirow="3" ', ' ').\
1087 replace('valignment="middle"', 'valignment="top"')
1088 blay = find_token(document.body, "\\begin_layout", bcell, ecell)
1090 document.warning("Can't find layout for cell!")
1092 bend = find_end_of_layout(document.body, blay)
1094 document.warning("Can't find end of layout for cell!")
1096 # do the later one first, so as not to mess up the numbering
1097 # we are wrapping the whole cell in this ert
1098 # so before the end of the layout...
1099 document.body[bend:bend] = put_cmd_in_ert("}")
1100 # ...and after the beginning
1101 document.body[blay + 1:blay + 1] = \
1102 put_cmd_in_ert("\\multirow{" + str(nummrs) + "}{" + col_width + "}{")
1104 begin_table = end_table
1107 def convert_math_output(document):
1108 " Convert \html_use_mathml to \html_math_output "
1109 i = find_token(document.header, "\\html_use_mathml", 0)
1112 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1113 m = rgx.match(document.header[i])
1114 newval = "0" # MathML
1116 val = str2bool(m.group(1))
1118 newval = "2" # Images
1120 document.warning("Can't match " + document.header[i])
1121 document.header[i] = "\\html_math_output " + newval
1124 def revert_math_output(document):
1125 " Revert \html_math_output to \html_use_mathml "
1126 i = find_token(document.header, "\\html_math_output", 0)
1129 rgx = re.compile(r'\\html_math_output\s+(\d)')
1130 m = rgx.match(document.header[i])
1134 if val == "1" or val == "2":
1137 document.warning("Unable to match " + document.header[i])
1138 document.header[i] = "\\html_use_mathml " + newval
1142 def revert_inset_preview(document):
1143 " Dissolves the preview inset "
1146 i = find_token(document.body, "\\begin_inset Preview", i)
1149 iend = find_end_of_inset(document.body, i)
1151 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1155 # This has several issues.
1156 # We need to do something about the layouts inside InsetPreview.
1157 # If we just leave the first one, then we have something like:
1158 # \begin_layout Standard
1160 # \begin_layout Standard
1161 # and we get a "no \end_layout" error. So something has to be done.
1162 # Ideally, we would check if it is the same as the layout we are in.
1163 # If so, we just remove it; if not, we end the active one. But it is
1164 # not easy to know what layout we are in, due to depth changes, etc,
1165 # and it is not clear to me how much work it is worth doing. In most
1166 # cases, the layout will probably be the same.
1168 # For the same reason, we have to remove the \end_layout tag at the
1169 # end of the last layout in the inset. Again, that will sometimes be
1170 # wrong, but it will usually be right. To know what to do, we would
1171 # again have to know what layout the inset is in.
1173 blay = find_token(document.body, "\\begin_layout", i, iend)
1175 document.warning("Can't find layout for preview inset!")
1176 # always do the later one first...
1177 del document.body[iend]
1178 del document.body[i]
1179 # deletions mean we do not need to reset i
1182 # This is where we would check what layout we are in.
1183 # The check for Standard is definitely wrong.
1185 # lay = document.body[blay].split(None, 1)[1]
1186 # if lay != oldlayout:
1187 # # record a boolean to tell us what to do later....
1188 # # better to do it later, since (a) it won't mess up
1189 # # the numbering and (b) we only modify at the end.
1191 # we want to delete the last \\end_layout in this inset, too.
1192 # note that this may not be the \\end_layout that goes with blay!!
1193 bend = find_end_of_layout(document.body, blay)
1195 tmp = find_token(document.body, "\\end_layout", bend + 1, iend)
1200 document.warning("Unable to find last layout in preview inset!")
1201 del document.body[iend]
1202 del document.body[i]
1203 # deletions mean we do not need to reset i
1205 # always do the later one first...
1206 del document.body[iend]
1207 del document.body[bend]
1208 del document.body[i:blay + 1]
1209 # we do not need to reset i
1212 def revert_equalspacing_xymatrix(document):
1213 " Revert a Formula with xymatrix@! to an ERT inset "
1215 has_preamble = False
1216 has_equal_spacing = False
1219 i = find_token(document.body, "\\begin_inset Formula", i)
1222 j = find_end_of_inset(document.body, i)
1224 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1228 for curline in range(i,j):
1229 found = document.body[curline].find("\\xymatrix@!")
1234 has_equal_spacing = True
1235 content = [document.body[i][21:]]
1236 content += document.body[i + 1:j]
1237 subst = put_cmd_in_ert(content)
1238 document.body[i:j + 1] = subst
1239 i += len(subst) - (j - i) + 1
1241 for curline in range(i,j):
1242 l = document.body[curline].find("\\xymatrix")
1244 has_preamble = True;
1248 if has_equal_spacing and not has_preamble:
1249 add_to_preamble(document, ['\\usepackage[all]{xy}'])
1252 def revert_notefontcolor(document):
1253 " Reverts greyed-out note font color to preamble code "
1255 i = find_token(document.header, "\\notefontcolor", 0)
1259 colorcode = get_value(document.header, '\\notefontcolor', i)
1260 del document.header[i]
1262 # are there any grey notes?
1263 if find_token(document.body, "\\begin_inset Note Greyedout", 0) == -1:
1264 # no need to do anything else, and \renewcommand will throw
1265 # an error since lyxgreyedout will not exist.
1268 # the color code is in the form #rrggbb where every character denotes a hex number
1269 red = hex2ratio(colorcode[1:3])
1270 green = hex2ratio(colorcode[3:5])
1271 blue = hex2ratio(colorcode[5:7])
1272 # write the preamble
1273 insert_to_preamble(document,
1274 [ '% for greyed-out notes',
1275 '\\@ifundefined{definecolor}{\\usepackage{color}}{}'
1276 '\\definecolor{note_fontcolor}{rgb}{%s,%s,%s}' % (red, green, blue),
1277 '\\renewenvironment{lyxgreyedout}',
1278 ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}'])
1281 def revert_turkmen(document):
1282 "Set language Turkmen to English"
1284 if document.language == "turkmen":
1285 document.language = "english"
1286 i = find_token(document.header, "\\language", 0)
1288 document.header[i] = "\\language english"
1292 j = find_token(document.body, "\\lang turkmen", j)
1295 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1299 def revert_fontcolor(document):
1300 " Reverts font color to preamble code "
1301 i = find_token(document.header, "\\fontcolor", 0)
1304 colorcode = get_value(document.header, '\\fontcolor', i)
1305 del document.header[i]
1306 # don't clutter the preamble if font color is not set
1307 if colorcode == "#000000":
1309 # the color code is in the form #rrggbb where every character denotes a hex number
1310 red = hex2ratio(colorcode[1:3])
1311 green = hex2ratio(colorcode[3:5])
1312 blue = hex2ratio(colorcode[5:7])
1313 # write the preamble
1314 insert_to_preamble(document,
1315 ['% Set the font color',
1316 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
1317 '\\definecolor{document_fontcolor}{rgb}{%s,%s,%s}' % (red, green, blue),
1318 '\\color{document_fontcolor}'])
1321 def revert_shadedboxcolor(document):
1322 " Reverts shaded box color to preamble code "
1323 i = find_token(document.header, "\\boxbgcolor", 0)
1326 colorcode = get_value(document.header, '\\boxbgcolor', i)
1327 del document.header[i]
1328 # the color code is in the form #rrggbb
1329 red = hex2ratio(colorcode[1:3])
1330 green = hex2ratio(colorcode[3:5])
1331 blue = hex2ratio(colorcode[5:7])
1332 # write the preamble
1333 insert_to_preamble(document,
1334 ['% Set the color of boxes with shaded background',
1335 '\\@ifundefined{definecolor}{\\usepackage{color}}{}',
1336 "\\definecolor{shadecolor}{rgb}{%s,%s,%s}" % (red, green, blue)])
1339 def revert_lyx_version(document):
1340 " Reverts LyX Version information from Inset Info "
1341 version = "LyX version"
1343 import lyx2lyx_version
1344 version = lyx2lyx_version.version
1350 i = find_token(document.body, '\\begin_inset Info', i)
1353 j = find_end_of_inset(document.body, i + 1)
1355 document.warning("Malformed LyX document: Could not find end of Info inset.")
1364 typ = get_quoted_value(document.body, "type", i, j)
1365 arg = get_quoted_value(document.body, "arg", i, j)
1366 if arg != "version" or typ != "lyxinfo":
1370 # We do not actually know the version of LyX used to produce the document.
1371 # But we can use our version, since we are reverting.
1373 # Now we want to check if the line after "\end_inset" is empty. It normally
1374 # is, so we want to remove it, too.
1376 if document.body[j + 1].strip() == "":
1378 document.body[i: lastline] = s
1382 def revert_math_scale(document):
1383 " Remove math scaling and LaTeX options "
1384 del_token(document.header, '\\html_math_img_scale', 0)
1385 del_token(document.header, '\\html_latex_start', 0)
1386 del_token(document.header, '\\html_latex_end', 0)
1389 def revert_pagesizes(document):
1390 " Revert page sizes to default "
1391 i = find_token(document.header, '\\papersize', 0)
1393 size = document.header[i][11:]
1394 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1395 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1396 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1397 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1398 or size == "b5j" or size == "b6j":
1399 del document.header[i]
1402 def revert_DIN_C_pagesizes(document):
1403 " Revert DIN C page sizes to default "
1404 i = find_token(document.header, '\\papersize', 0)
1406 size = document.header[i][11:]
1407 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1408 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1409 or size == "c6paper":
1410 del document.header[i]
1413 def convert_html_quotes(document):
1414 " Remove quotes around html_latex_start and html_latex_end "
1416 i = find_token(document.header, '\\html_latex_start', 0)
1418 line = document.header[i]
1419 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1422 document.header[i] = "\\html_latex_start " + m.group(1)
1424 i = find_token(document.header, '\\html_latex_end', 0)
1426 line = document.header[i]
1427 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1430 document.header[i] = "\\html_latex_end " + m.group(1)
1433 def revert_html_quotes(document):
1434 " Remove quotes around html_latex_start and html_latex_end "
1436 i = find_token(document.header, '\\html_latex_start', 0)
1438 line = document.header[i]
1439 l = re.compile(r'\\html_latex_start\s+(.*)')
1442 document.warning("Weird html_latex_start line: " + line)
1443 del document.header[i]
1445 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1447 i = find_token(document.header, '\\html_latex_end', 0)
1449 line = document.header[i]
1450 l = re.compile(r'\\html_latex_end\s+(.*)')
1453 document.warning("Weird html_latex_end line: " + line)
1454 del document.header[i]
1456 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1459 def revert_output_sync(document):
1460 " Remove forward search options "
1461 del_token(document.header, '\\output_sync_macro', 0)
1462 del_token(document.header, '\\output_sync', 0)
1465 def revert_align_decimal(document):
1468 i = find_token(document.body, "\\begin_inset Tabular", i)
1471 j = find_end_of_inset(document.body, i)
1473 document.warning("Unable to find end of Tabular inset at line " + str(i))
1476 cell = find_token(document.body, "<cell", i, j)
1478 document.warning("Can't find any cells in Tabular inset at line " + str(i))
1483 k = find_token(document.body, "<column", k, cell)
1486 if document.body[k].find('alignment="decimal"') == -1:
1489 remove_option(document.body, k, 'decimal_point')
1490 document.body[k] = \
1491 document.body[k].replace('alignment="decimal"', 'alignment="center"')
1495 def convert_optarg(document):
1496 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1499 i = find_token(document.body, '\\begin_inset OptArg', i)
1502 document.body[i] = "\\begin_inset Argument"
1506 def revert_argument(document):
1507 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1510 i = find_token(document.body, '\\begin_inset Argument', i)
1513 document.body[i] = "\\begin_inset OptArg"
1517 def revert_makebox(document):
1518 " Convert \\makebox to TeX code "
1521 i = find_token(document.body, '\\begin_inset Box', i)
1524 z = find_end_of_inset(document.body, i)
1526 document.warning("Malformed LyX document: Can't find end of box inset.")
1529 blay = find_token(document.body, "\\begin_layout", i, z)
1531 document.warning("Malformed LyX document: Can't find layout in box.")
1534 j = find_token(document.body, 'use_makebox', i)
1535 if j == -1 or j != i +6:
1536 document.warning("Malformed LyX document: Can't find use_makebox statement in box.")
1539 # delete use_makebox
1540 if not check_token(document.body[i], "\\begin_inset Box Frameless") \
1541 or get_value(document.body, 'use_makebox', j) != 1:
1542 del document.body[j]
1545 bend = find_end_of_layout(document.body, blay)
1546 if bend == -1 or bend > z:
1547 document.warning("Malformed LyX document: Can't find end of layout in box.")
1550 # determine the alignment
1551 align = get_quoted_value(document.body, 'hor_pos', i, blay, "c")
1552 # determine the width
1553 length = get_quoted_value(document.body, 'width', i, blay, "50col%")
1554 length = latex_length(length)[1]
1555 # remove the \end_layout \end_inset pair
1556 document.body[bend:z + 1] = put_cmd_in_ert("}")
1557 subst = "\\makebox[" + length + "][" \
1559 document.body[i:blay + 1] = put_cmd_in_ert(subst)
1563 def convert_use_makebox(document):
1564 " Adds use_makebox option for boxes "
1567 i = find_token(document.body, '\\begin_inset Box', i)
1570 k = find_token(document.body, 'use_parbox', i)
1571 if k == -1 or k != i + 5:
1572 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1576 document.body.insert(k + 1, "use_makebox 0")
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 stins, endins = is_in_inset(document.body, cmdloc,
1683 "\\begin_inset CommandInset ref")
1686 # ok, so it is in an InsetRef
1687 refline = find_token(document.body, "reference", stins, endins)
1689 document.warning("Can't find reference for inset at line " + stinst + "!!")
1691 m = rx.match(document.body[refline])
1693 document.warning("Can't match reference line: " + document.body[ref])
1697 newcontent = put_cmd_in_ert('\\' + cmd + '{' + ref + '}')
1698 document.body[stins:endins + 1] = newcontent
1701 add_to_preamble(document, ["\\usepackage{nameref}"])
1704 def remove_Nameref(document):
1705 " Convert Nameref commands to nameref commands "
1708 # It seems better to look for this, as most of the reference
1709 # insets won't be ones we care about.
1710 i = find_token(document.body, "LatexCommand Nameref" , i)
1715 # Make sure it is actually in an inset!
1716 val = is_in_inset(document.body, cmdloc,
1717 "\\begin_inset CommandInset ref", default=False)
1720 document.body[cmdloc] = "LatexCommand nameref"
1723 def revert_mathrsfs(document):
1724 " Load mathrsfs if \mathrsfs us use in the document "
1726 for line in document.body:
1727 if line.find("\\mathscr{") != -1:
1728 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
1732 def convert_flexnames(document):
1733 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
1736 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
1738 i = find_token(document.body, "\\begin_inset Flex", i)
1741 m = rx.match(document.body[i])
1743 document.body[i] = "\\begin_inset Flex " + m.group(1)
1748 "Alert" : "CharStyle:Alert",
1749 "Code" : "CharStyle:Code",
1750 "Concepts" : "CharStyle:Concepts",
1751 "E-Mail" : "CharStyle:E-Mail",
1752 "Emph" : "CharStyle:Emph",
1753 "Expression" : "CharStyle:Expression",
1754 "Initial" : "CharStyle:Initial",
1755 "Institute" : "CharStyle:Institute",
1756 "Meaning" : "CharStyle:Meaning",
1757 "Noun" : "CharStyle:Noun",
1758 "Strong" : "CharStyle:Strong",
1759 "Structure" : "CharStyle:Structure",
1760 "ArticleMode" : "Custom:ArticleMode",
1761 "Endnote" : "Custom:Endnote",
1762 "Glosse" : "Custom:Glosse",
1763 "PresentationMode" : "Custom:PresentationMode",
1764 "Tri-Glosse" : "Custom:Tri-Glosse"
1768 "Abbrev" : "Element:Abbrev",
1769 "CCC-Code" : "Element:CCC-Code",
1770 "Citation-number" : "Element:Citation-number",
1771 "City" : "Element:City",
1772 "Code" : "Element:Code",
1773 "CODEN" : "Element:CODEN",
1774 "Country" : "Element:Country",
1775 "Day" : "Element:Day",
1776 "Directory" : "Element:Directory",
1777 "Dscr" : "Element:Dscr",
1778 "Email" : "Element:Email",
1779 "Emph" : "Element:Emph",
1780 "Filename" : "Element:Filename",
1781 "Firstname" : "Element:Firstname",
1782 "Fname" : "Element:Fname",
1783 "GuiButton" : "Element:GuiButton",
1784 "GuiMenu" : "Element:GuiMenu",
1785 "GuiMenuItem" : "Element:GuiMenuItem",
1786 "ISSN" : "Element:ISSN",
1787 "Issue-day" : "Element:Issue-day",
1788 "Issue-months" : "Element:Issue-months",
1789 "Issue-number" : "Element:Issue-number",
1790 "KeyCap" : "Element:KeyCap",
1791 "KeyCombo" : "Element:KeyCombo",
1792 "Keyword" : "Element:Keyword",
1793 "Literal" : "Element:Literal",
1794 "MenuChoice" : "Element:MenuChoice",
1795 "Month" : "Element:Month",
1796 "Orgdiv" : "Element:Orgdiv",
1797 "Orgname" : "Element:Orgname",
1798 "Postcode" : "Element:Postcode",
1799 "SS-Code" : "Element:SS-Code",
1800 "SS-Title" : "Element:SS-Title",
1801 "State" : "Element:State",
1802 "Street" : "Element:Street",
1803 "Surname" : "Element:Surname",
1804 "Volume" : "Element:Volume",
1805 "Year" : "Element:Year"
1809 def revert_flexnames(document):
1810 if document.backend == "latex":
1811 flexlist = flex_insets
1813 flexlist = flex_elements
1815 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
1818 i = find_token(document.body, "\\begin_inset Flex", i)
1821 m = rx.match(document.body[i])
1823 document.warning("Illegal flex inset: " + document.body[i])
1827 if style in flexlist:
1828 document.body[i] = "\\begin_inset Flex " + flexlist[style]
1832 def convert_mathdots(document):
1833 " Load mathdots automatically "
1834 i = find_token(document.header, "\\use_mhchem" , 0)
1836 i = find_token(document.header, "\\use_esint" , 0)
1838 document.warning("Malformed LyX document: Can't find \\use_mhchem.")
1840 j = find_token(document.preamble, "\\usepackage{mathdots}", 0)
1842 document.header.insert(i + 1, "\\use_mathdots 0")
1844 document.header.insert(i + 1, "\\use_mathdots 2")
1845 del document.preamble[j]
1848 def revert_mathdots(document):
1849 " Load mathdots if used in the document "
1851 mathdots = find_token(document.header, "\\use_mathdots" , 0)
1853 document.warning("No \\use_mathdots line. Assuming auto.")
1855 val = get_value(document.header, "\\use_mathdots", mathdots)
1856 del document.header[mathdots]
1860 document.warning("Invalid \\use_mathdots value: " + val + ". Assuming auto.")
1861 # probably usedots has not been changed, but be safe.
1869 add_to_preamble(document, ["\\usepackage{mathdots}"])
1872 # so we are in the auto case. we want to load mathdots if \iddots is used.
1875 i = find_token(document.body, '\\begin_inset Formula', i)
1878 j = find_end_of_inset(document.body, i)
1880 document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
1883 code = "\n".join(document.body[i:j])
1884 if code.find("\\iddots") != -1:
1885 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}"])
1890 def convert_rule(document):
1891 " Convert \\lyxline to CommandInset line. "
1894 inset = ['\\begin_inset CommandInset line',
1895 'LatexCommand rule',
1899 '\\end_inset', '', '']
1901 # if paragraphs are indented, we may have to unindent to get the
1902 # line to be full-width.
1903 indent = get_value(document.header, "\\paragraph_separation", 0)
1904 have_indent = (indent == "indent")
1907 i = find_token(document.body, "\\lyxline" , i)
1911 # we need to find out if this line follows other content
1912 # in its paragraph. find its layout....
1913 lastlay = find_token_backwards(document.body, "\\begin_layout", i)
1915 document.warning("Can't find layout for line at " + str(i))
1916 # do the best we can.
1917 document.body[i:i+1] = inset
1921 # ...and look for other content before it.
1923 for line in document.body[lastlay + 1:i]:
1924 # is it empty or a paragraph option?
1925 if not line or line[0] == '\\':
1931 document.body[i:i+1] = inset
1933 # we need to unindent, lest the line be too long
1934 document.body.insert(lastlay + 1, "\\noindent")
1937 # so our line is in the middle of a paragraph
1938 # we need to add a new line, lest this line follow the
1939 # other content on that line and run off the side of the page
1940 document.body[i:i+1] = inset
1941 document.body[i:i] = ["\\begin_inset Newline newline", "\\end_inset", ""]
1945 def revert_rule(document):
1946 " Revert line insets to Tex code "
1949 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
1953 j = find_token(document.body, "\\end_inset" , i)
1955 document.warning("Malformed LyX document: Can't find end of line inset.")
1957 # determine the optional offset
1958 offset = get_quoted_value(document.body, 'offset', i, j)
1960 offset = '[' + offset + ']'
1961 # determine the width
1962 width = get_quoted_value(document.body, 'width', i, j, "100col%")
1963 width = latex_length(width)[1]
1964 # determine the height
1965 height = get_quoted_value(document.body, 'height', i, j, "1pt")
1966 height = latex_length(height)[1]
1967 # output the \rule command
1968 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
1969 document.body[i:j + 1] = put_cmd_in_ert(subst)
1970 i += len(subst) - (j - i)
1973 def revert_diagram(document):
1974 " Add the feyn package if \\Diagram is used in math "
1977 i = find_token(document.body, '\\begin_inset Formula', i)
1980 j = find_end_of_inset(document.body, i)
1982 document.warning("Malformed LyX document: Can't find end of Formula inset.")
1984 lines = "\n".join(document.body[i:j])
1985 if lines.find("\\Diagram") == -1:
1988 add_to_preamble(document, ["\\usepackage{feyn}"])
1989 # only need to do it once!
1992 chapters = ("amsbook", "book", "docbook-book", "elsart", "extbook", "extreport",
1993 "jbook", "jreport", "jsbook", "literate-book", "literate-report", "memoir",
1994 "mwbk", "mwrep", "recipebook", "report", "scrbook", "scrreprt", "svmono",
1995 "svmult", "tbook", "treport", "tufte-book")
1997 def convert_bibtex_clearpage(document):
1998 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2000 if document.textclass not in chapters:
2003 i = find_token(document.header, '\\papersides', 0)
2006 document.warning("Malformed LyX document: Can't find papersides definition.")
2007 document.warning("Assuming single sided.")
2010 val = get_value(document.header, "\\papersides", i)
2015 if sides != 1 and sides != 2:
2016 document.warning("Invalid papersides value: " + val)
2017 document.warning("Assuming single sided.")
2022 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2026 k = find_end_of_inset(document.body, j)
2028 document.warning("Can't find end of Bibliography inset at line " + str(j))
2032 # only act if there is the option "bibtotoc"
2033 val = get_value(document.body, 'options', j, k)
2035 document.warning("Can't find options for bibliography inset at line " + str(j))
2039 if val.find("bibtotoc") == -1:
2043 # so we want to insert a new page right before the paragraph that
2044 # this bibliography thing is in.
2045 lay = find_token_backwards(document.body, "\\begin_layout", j)
2047 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2054 cmd = "cleardoublepage"
2055 subst = ['\\begin_layout Standard',
2056 '\\begin_inset Newpage ' + cmd,
2057 '\\end_inset', '', '',
2059 document.body[lay:lay] = subst
2063 def check_passthru(document):
2064 tc = document.textclass
2065 ok = (tc == "literate-article" or tc == "literate-book" or tc == "literate-report")
2067 mods = document.get_module_list()
2069 if mod == "sweave" or mod == "noweb":
2075 def convert_passthru(document):
2076 " http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161298.html "
2077 if not check_passthru:
2080 rx = re.compile("\\\\begin_layout \s*(\w+)")
2082 for lay in ["Chunk", "Scrap"]:
2084 beg = find_token(document.body, "\\begin_layout " + lay, beg)
2087 end = find_end_of_layout(document.body, beg)
2089 document.warning("Can't find end of layout at line " + str(beg))
2093 # we are now going to replace newline insets within this layout
2094 # by new instances of this layout. so we have repeated layouts
2095 # instead of newlines.
2097 # if the paragraph has any customization, however, we do not want to
2098 # do the replacement.
2099 if document.body[beg + 1].startswith("\\"):
2105 ns = find_token(document.body, "\\begin_inset Newline newline", ns, end)
2108 ne = find_end_of_inset(document.body, ns)
2109 if ne == -1 or ne > end:
2110 document.warning("Can't find end of inset at line " + str(nb))
2113 if document.body[ne + 1] == "":
2115 subst = ["\\end_layout", "", "\\begin_layout " + lay]
2116 document.body[ns:ne + 1] = subst
2117 # now we need to adjust end, in particular, but might as well
2118 # do ns properly, too
2119 newlines = (ne - ns) - len(subst)
2123 # ok, we now want to find out if the next layout is the
2124 # same as this one. if so, we will insert an extra copy of it
2126 next = find_token(document.body, "\\begin_layout", end)
2128 m = rx.match(document.body[next])
2130 nextlay = m.group(1)
2132 subst = ["\\begin_layout " + lay, "", "\\end_layout", ""]
2133 document.body[next:next] = subst
2137 beg += 4 # for the extra layout
2140 def revert_passthru(document):
2141 " http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg161298.html "
2142 if not check_passthru:
2144 rx = re.compile("\\\\begin_layout \s*(\w+)")
2146 for lay in ["Chunk", "Scrap"]:
2148 beg = find_token(document.body, "\\begin_layout " + lay, beg)
2151 end = find_end_of_layout(document.body, beg)
2153 document.warning("Can't find end of layout at line " + str(beg))
2157 # we now want to find out if the next layout is the
2158 # same as this one. but we will need to do this over and
2161 next = find_token(document.body, "\\begin_layout", end)
2164 m = rx.match(document.body[next])
2167 nextlay = m.group(1)
2170 # so it is the same layout again. we now want to know if it is empty.
2171 # but first let's check and make sure there is no content between the
2172 # two layouts. i'm not sure if that can happen or not.
2173 for l in range(end + 1, next):
2174 if document.body[l] != "":
2175 document.warning("Found content between adjacent " + lay + " layouts!")
2177 nextend = find_end_of_layout(document.body, next)
2179 document.warning("Can't find end of layout at line " + str(next))
2182 for l in range(next + 1, nextend):
2183 if document.body[l] != "":
2187 # empty layouts just get removed
2188 # should we check if it's before yet another such layout?
2189 del document.body[next : nextend + 1]
2190 # and we do not want to check again. we know the next layout
2191 # should be another Chunk and should be left as is.
2194 # if it's not empty, then we want to insert a newline in place
2195 # of the layout switch
2196 subst = ["\\begin_inset Newline newline", "\\end_inset", ""]
2197 document.body[end : next + 1] = subst
2198 # and now we have to find the end of the new, larger layout
2199 newend = find_end_of_layout(document.body, beg)
2201 document.warning("Can't find end of new layout at line " + str(beg))
2207 def revert_multirowOffset(document):
2208 " Revert multirow cells with offset in tables to TeX-code"
2209 # this routine is the same as the revert_multirow routine except that
2210 # it checks additionally for the offset
2212 # first, let's find out if we need to do anything
2213 i = find_token(document.body, '<cell multirow="3" mroffset=', 0)
2217 add_to_preamble(document, ["\\usepackage{multirow}"])
2219 rgx = re.compile(r'mroffset="[^"]+?"')
2223 # find begin/end of table
2224 begin_table = find_token(document.body, '<lyxtabular version=', begin_table)
2225 if begin_table == -1:
2227 end_table = find_end_of(document.body, begin_table, '<lyxtabular', '</lyxtabular>')
2229 document.warning("Malformed LyX document: Could not find end of table.")
2232 # does this table have multirow?
2233 i = find_token(document.body, '<cell multirow="3"', begin_table, end_table)
2235 begin_table = end_table
2238 # store the number of rows and columns
2239 numrows = get_option_value(document.body[begin_table], "rows")
2240 numcols = get_option_value(document.body[begin_table], "columns")
2242 numrows = int(numrows)
2243 numcols = int(numcols)
2245 document.warning("Unable to determine rows and columns!")
2246 begin_table = end_table
2251 # collect info on rows and columns of this table.
2252 begin_row = begin_table
2253 for row in range(numrows):
2254 begin_row = find_token(document.body, '<row>', begin_row, end_table)
2256 document.warning("Can't find row " + str(row + 1))
2258 end_row = find_end_of(document.body, begin_row, '<row>', '</row>')
2260 document.warning("Can't find end of row " + str(row + 1))
2262 begin_cell = begin_row
2263 multirows.append([])
2264 for column in range(numcols):
2265 begin_cell = find_token(document.body, '<cell ', begin_cell, end_row)
2266 if begin_cell == -1:
2267 document.warning("Can't find column " + str(column + 1) + \
2268 "in row " + str(row + 1))
2271 # this will fail if someone puts "</cell>" in a cell, but
2272 # that seems fairly unlikely.
2273 end_cell = find_end_of(document.body, begin_cell, '<cell', '</cell>')
2275 document.warning("Can't find end of column " + str(column + 1) + \
2276 "in row " + str(row + 1))
2278 multirows[row].append([begin_cell, end_cell, 0])
2279 if document.body[begin_cell].find('multirow="3" mroffset=') != -1:
2280 multirows[row][column][2] = 3 # begin multirow
2281 mrstarts.append([row, column])
2282 elif document.body[begin_cell].find('multirow="4"') != -1:
2283 multirows[row][column][2] = 4 # in multirow
2284 begin_cell = end_cell
2286 # end of table info collection
2288 # work from the back to avoid messing up numbering
2294 col_width = get_option_value(document.body[begin_table + 2 + col], "width")
2295 # "0pt" means that no width is specified
2296 if not col_width or col_width == "0pt":
2298 # determine the number of cells that are part of the multirow
2300 for r in range(row + 1, numrows):
2301 if multirows[r][col][2] != 4:
2304 # take the opportunity to revert this line
2305 lineno = multirows[r][col][0]
2306 document.body[lineno] = document.body[lineno].\
2307 replace(' multirow="4" ', ' ').\
2308 replace('valignment="middle"', 'valignment="top"').\
2309 replace(' topline="true" ', ' ')
2310 # remove bottom line of previous multirow-part cell
2311 lineno = multirows[r-1][col][0]
2312 document.body[lineno] = document.body[lineno].replace(' bottomline="true" ', ' ')
2313 # revert beginning cell
2314 bcell = multirows[row][col][0]
2315 ecell = multirows[row][col][1]
2316 offset = get_option_value(document.body[bcell], "mroffset")
2317 document.body[bcell] = document.body[bcell].\
2318 replace(' multirow="3" ', ' ').\
2319 replace('valignment="middle"', 'valignment="top"')
2320 # remove mroffset option
2321 document.body[bcell] = rgx.sub('', document.body[bcell])
2323 blay = find_token(document.body, "\\begin_layout", bcell, ecell)
2325 document.warning("Can't find layout for cell!")
2327 bend = find_end_of_layout(document.body, blay)
2329 document.warning("Can't find end of layout for cell!")
2331 # do the later one first, so as not to mess up the numbering
2332 # we are wrapping the whole cell in this ert
2333 # so before the end of the layout...
2334 document.body[bend:bend] = put_cmd_in_ert("}")
2335 # ...and after the beginning
2336 document.body[blay + 1:blay + 1] = \
2337 put_cmd_in_ert("\\multirow{" + str(nummrs) + "}{" + col_width + "}[" \
2340 # on to the next table
2341 begin_table = end_table
2344 def revert_script(document):
2345 " Convert subscript/superscript inset to TeX code "
2347 foundsubscript = False
2349 i = find_token(document.body, '\\begin_inset script', i)
2352 z = find_end_of_inset(document.body, i)
2354 document.warning("Malformed LyX document: Can't find end of script inset.")
2357 blay = find_token(document.body, "\\begin_layout", i, z)
2359 document.warning("Malformed LyX document: Can't find layout in script inset.")
2363 if check_token(document.body[i], "\\begin_inset script subscript"):
2364 subst = '\\textsubscript{'
2365 foundsubscript = True
2366 elif check_token(document.body[i], "\\begin_inset script superscript"):
2367 subst = '\\textsuperscript{'
2369 document.warning("Malformed LyX document: Unknown type of script inset.")
2372 bend = find_end_of_layout(document.body, blay)
2373 if bend == -1 or bend > z:
2374 document.warning("Malformed LyX document: Can't find end of layout in script inset.")
2377 # remove the \end_layout \end_inset pair
2378 document.body[bend:z + 1] = put_cmd_in_ert("}")
2379 document.body[i:blay + 1] = put_cmd_in_ert(subst)
2381 # these classes provide a \textsubscript command:
2382 # FIXME: Would be nice if we could use the information of the .layout file here
2383 classes = ["memoir", "scrartcl", "scrbook", "scrlttr2", "scrreprt"]
2384 if foundsubscript and find_token_exact(classes, document.textclass, 0) == -1:
2385 add_to_preamble(document, ['\\usepackage{subscript}'])
2388 def convert_use_xetex(document):
2389 " convert \\use_xetex to \\use_non_tex_fonts "
2390 i = find_token(document.header, "\\use_xetex", 0)
2392 document.header.insert(-1, "\\use_non_tex_fonts 0")
2394 val = get_value(document.header, "\\use_xetex", 0)
2395 document.header[i] = "\\use_non_tex_fonts " + val
2398 def revert_use_xetex(document):
2399 " revert \\use_non_tex_fonts to \\use_xetex "
2401 i = find_token(document.header, "\\use_non_tex_fonts", 0)
2403 document.warning("Malformed document. No \\use_non_tex_fonts param!")
2406 val = get_value(document.header, "\\use_non_tex_fonts", 0)
2407 document.header[i] = "\\use_xetex " + val
2410 def revert_labeling(document):
2411 koma = ("scrartcl", "scrarticle-beamer", "scrbook", "scrlettr",
2412 "scrlttr2", "scrreprt")
2413 if document.textclass in koma:
2417 i = find_token_exact(document.body, "\\begin_layout Labeling", i)
2420 document.body[i] = "\\begin_layout List"
2423 def revert_langpack(document):
2424 " revert \\language_package parameter "
2426 i = find_token(document.header, "\\language_package", 0)
2428 document.warning("Malformed document. No \\language_package param!")
2431 del document.header[i]
2434 def convert_langpack(document):
2435 " Add \\language_package parameter "
2436 i = find_token(document.header, "\language" , 0)
2438 document.warning("Malformed document. No \\language defined!")
2441 document.header.insert(i + 1, "\\language_package default")
2444 def revert_tabularwidth(document):
2447 i = find_token(document.body, "\\begin_inset Tabular", i)
2450 j = find_end_of_inset(document.body, i)
2452 document.warning("Unable to find end of Tabular inset at line " + str(i))
2456 features = find_token(document.body, "<features", i, j)
2458 document.warning("Can't find any features in Tabular inset at line " + str(i))
2461 if document.body[features].find('alignment="tabularwidth"') != -1:
2462 remove_option(document.body, features, 'tabularwidth')
2464 def revert_html_css_as_file(document):
2465 if not del_token(document.header, '\\html_css_as_file', 0):
2466 document.warning("Malformed LyX document: Missing \\html_css_as_file.")
2473 supported_versions = ["2.0.0","2.0"]
2474 convert = [[346, []],
2480 [352, [convert_splitindex]],
2483 [355, [convert_strikeout]],
2485 [357, [convert_ulinelatex]],
2487 [359, [convert_nomencl_width]],
2497 [369, [convert_author_id]],
2499 [371, [convert_mhchem]],
2501 [373, [merge_gbrief]],
2507 [379, [convert_math_output]],
2517 [389, [convert_html_quotes]],
2521 [393, [convert_optarg]],
2522 [394, [convert_use_makebox]],
2525 [397, [remove_Nameref]],
2527 [399, [convert_mathdots]],
2528 [400, [convert_rule]],
2530 [402, [convert_bibtex_clearpage]],
2531 [403, [convert_flexnames]],
2532 [404, [convert_prettyref]],
2534 [406, [convert_passthru]],
2537 [409, [convert_use_xetex]],
2539 [411, [convert_langpack]],
2544 revert = [[412, [revert_html_css_as_file]],
2545 [411, [revert_tabularwidth]],
2546 [410, [revert_langpack]],
2547 [409, [revert_labeling]],
2548 [408, [revert_use_xetex]],
2549 [407, [revert_script]],
2550 [406, [revert_multirowOffset]],
2551 [405, [revert_passthru]],
2553 [403, [revert_refstyle]],
2554 [402, [revert_flexnames]],
2556 [400, [revert_diagram]],
2557 [399, [revert_rule]],
2558 [398, [revert_mathdots]],
2559 [397, [revert_mathrsfs]],
2561 [395, [revert_nameref]],
2562 [394, [revert_DIN_C_pagesizes]],
2563 [393, [revert_makebox]],
2564 [392, [revert_argument]],
2566 [390, [revert_align_decimal, revert_IEEEtran]],
2567 [389, [revert_output_sync]],
2568 [388, [revert_html_quotes]],
2569 [387, [revert_pagesizes]],
2570 [386, [revert_math_scale]],
2571 [385, [revert_lyx_version]],
2572 [384, [revert_shadedboxcolor]],
2573 [383, [revert_fontcolor]],
2574 [382, [revert_turkmen]],
2575 [381, [revert_notefontcolor]],
2576 [380, [revert_equalspacing_xymatrix]],
2577 [379, [revert_inset_preview]],
2578 [378, [revert_math_output]],
2580 [376, [revert_multirow]],
2581 [375, [revert_includeall]],
2582 [374, [revert_includeonly]],
2583 [373, [revert_html_options]],
2584 [372, [revert_gbrief]],
2585 [371, [revert_fontenc]],
2586 [370, [revert_mhchem]],
2587 [369, [revert_suppress_date]],
2588 [368, [revert_author_id]],
2589 [367, [revert_hspace_glue_lengths]],
2590 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2591 [365, [revert_percent_skip_lengths]],
2592 [364, [revert_paragraph_indentation]],
2593 [363, [revert_branch_filename]],
2594 [362, [revert_longtable_align]],
2595 [361, [revert_applemac]],
2597 [359, [revert_nomencl_cwidth]],
2598 [358, [revert_nomencl_width]],
2599 [357, [revert_custom_processors]],
2600 [356, [revert_ulinelatex]],
2602 [354, [revert_strikeout]],
2603 [353, [revert_printindexall]],
2604 [352, [revert_subindex]],
2605 [351, [revert_splitindex]],
2606 [350, [revert_backgroundcolor]],
2607 [349, [revert_outputformat]],
2608 [348, [revert_xetex]],
2609 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2610 [346, [revert_tabularvalign]],
2611 [345, [revert_swiss]]
2615 if __name__ == "__main__":