1 # -*- coding: utf-8 -*-
2 # This file is part of lyx2lyx
3 # -*- coding: utf-8 -*-
4 # Copyright (C) 2010 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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, get_value, get_value_string
28 ####################################################################
29 # Private helper functions
31 def remove_option(document, m, option):
32 l = document.body[m].find(option)
34 val = document.body[m][l:].split('"')[1]
35 document.body[m] = document.body[m][:l - 1] + document.body[m][l+len(option + '="' + val + '"'):]
38 def find_end_of_inset(lines, i):
39 " Find end of inset, where lines[i] is included."
40 return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
43 # Note that text can be either a list of lines or a single line.
44 def add_to_preamble(document, text):
45 """ Add text to the preamble if it is not already there.
46 Only the first line is checked!"""
48 if not type(text) is list:
49 # split on \n just in case
50 # it'll give us the one element list we want
51 # if there's no \n, too
52 text = text.split('\n')
54 if find_token(document.preamble, text[0], 0) != -1:
57 document.preamble.extend(text)
60 def insert_to_preamble(index, document, text):
61 """ Insert text to the preamble at a given line"""
63 document.preamble.insert(index, text)
66 def read_unicodesymbols():
67 " Read the unicodesymbols list of unicode characters and corresponding commands."
68 pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
69 fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
71 # Two backslashes, followed by some non-word character, and then a character
72 # in brackets. The idea is to check for constructs like: \"{u}, which is how
73 # they are written in the unicodesymbols file; but they can also be written
74 # as: \"u or even \" u.
75 r = re.compile(r'\\\\(\W)\{(\w)\}')
76 for line in fp.readlines():
77 if line[0] != '#' and line.strip() != "":
78 line=line.replace(' "',' ') # remove all quotation marks with spaces before
79 line=line.replace('" ',' ') # remove all quotation marks with spaces after
80 line=line.replace(r'\"','"') # replace \" by " (for characters with diaeresis)
82 [ucs4,command,dead] = line.split(None,2)
83 if command[0:1] != "\\":
85 spec_chars.append([command, unichr(eval(ucs4))])
91 # If the character is a double-quote, then we need to escape it, too,
92 # since it is done that way in the LyX file.
93 if m.group(1) == "\"":
96 command += m.group(1) + m.group(2)
97 commandbl += m.group(1) + ' ' + m.group(2)
98 spec_chars.append([command, unichr(eval(ucs4))])
99 spec_chars.append([commandbl, unichr(eval(ucs4))])
104 unicode_reps = read_unicodesymbols()
107 # DO NOT USE THIS ROUTINE ANY MORE. Better yet, replace the uses that
108 # have been made of it with uses of put_cmd_in_ert.
109 def old_put_cmd_in_ert(string):
110 for rep in unicode_reps:
111 string = string.replace(rep[1], rep[0].replace('\\\\', '\\'))
112 string = string.replace('\\', "\\backslash\n")
113 string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n" \
114 + string + "\n\\end_layout\n\\end_inset"
118 # This routine wraps some content in an ERT inset.
120 # NOTE: The function accepts either a single string or a LIST of strings as
121 # argument. But it returns a LIST of strings, split on \n, so that it does
122 # not have embedded newlines.
124 # This is how lyx2lyx represents a LyX document: as a list of strings,
125 # each representing a line of a LyX file. Embedded newlines confuse
128 # A call to this routine will often go something like this:
129 # i = find_token('\\begin_inset FunkyInset', ...)
131 # j = find_end_of_inset(document.body, i)
132 # content = ...extract content from insets
133 # # that could be as simple as:
134 # # content = lyx2latex(document[i:j + 1])
135 # ert = put_cmd_in_ert(content)
136 # document.body[i:j] = ert
137 # Now, before we continue, we need to reset i appropriately. Normally,
140 # That puts us right after the ERT we just inserted.
142 def put_cmd_in_ert(arg):
143 ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
144 # Despite the warnings just given, it will be faster for us to work
145 # with a single string internally. That way, we only go through the
146 # unicode_reps loop once.
147 if type(arg) is list:
151 for rep in unicode_reps:
152 s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
153 s = s.replace('\\', "\\backslash\n")
154 ret += s.splitlines()
155 ret += ["\\end_layout", "\\end_inset"]
159 def lyx2latex(document, lines):
160 'Convert some LyX stuff into corresponding LaTeX stuff, as best we can.'
161 # clean up multiline stuff
167 for curline in range(len(lines)):
168 line = lines[curline]
169 if line.startswith("\\begin_inset Note Note"):
170 # We want to skip LyX notes, so remember where the inset ends
171 note_end = find_end_of_inset(lines, curline + 1)
173 elif note_end >= curline:
176 elif line.startswith("\\begin_inset ERT"):
177 # We don't want to replace things inside ERT, so figure out
178 # where the end of the inset is.
179 ert_end = find_end_of_inset(lines, curline + 1)
181 elif line.startswith("\\begin_inset Formula"):
183 elif line.startswith("\\begin_inset Quotes"):
184 # For now, we do a very basic reversion. Someone who understands
185 # quotes is welcome to fix it up.
186 qtype = line[20:].strip()
200 elif line.startswith("\\begin_inset space"):
201 line = line[18:].strip()
202 if line.startswith("\\hspace"):
203 # Account for both \hspace and \hspace*
206 elif line == "\\space{}":
208 elif line == "\\thinspace{}":
211 # The LyX length is in line[8:], after the \length keyword
212 # latex_length returns "bool,length"
213 length = latex_length(line[8:]).split(",")[1]
214 line = hspace + "{" + length + "}"
216 elif line.isspace() or \
217 line.startswith("\\begin_layout") or \
218 line.startswith("\\end_layout") or \
219 line.startswith("\\begin_inset") or \
220 line.startswith("\\end_inset") or \
221 line.startswith("\\lang") or \
222 line.strip() == "status collapsed" or \
223 line.strip() == "status open":
227 # this needs to be added to the preamble because of cases like
228 # \textmu, \textbackslash, etc.
229 add_to_preamble(document, ['% added by lyx2lyx for converted index entries',
230 '\\@ifundefined{textmu}',
231 ' {\\usepackage{textcomp}}{}'])
232 # a lossless reversion is not possible
233 # try at least to handle some common insets and settings
234 if ert_end >= curline:
235 line = line.replace(r'\backslash', '\\')
237 # No need to add "{}" after single-nonletter macros
238 line = line.replace('&', '\\&')
239 line = line.replace('#', '\\#')
240 line = line.replace('^', '\\textasciicircum{}')
241 line = line.replace('%', '\\%')
242 line = line.replace('_', '\\_')
243 line = line.replace('$', '\\$')
245 # Do the LyX text --> LaTeX conversion
246 for rep in unicode_reps:
247 line = line.replace(rep[1], rep[0] + "{}")
248 line = line.replace(r'\backslash', r'\textbackslash{}')
249 line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}')
250 line = line.replace(r'\shape italic', r'\itshape{}').replace(r'\shape smallcaps', r'\scshape{}')
251 line = line.replace(r'\shape slanted', r'\slshape{}').replace(r'\shape default', r'\upshape{}')
252 line = line.replace(r'\emph on', r'\em{}').replace(r'\emph default', r'\em{}')
253 line = line.replace(r'\noun on', r'\scshape{}').replace(r'\noun default', r'\upshape{}')
254 line = line.replace(r'\bar under', r'\underbar{').replace(r'\bar default', r'}')
255 line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}')
256 line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}')
257 line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'')
262 def latex_length(slen):
263 'Convert lengths to their LaTeX representation.'
266 # the slen has the form
267 # ValueUnit+ValueUnit-ValueUnit or
268 # ValueUnit+-ValueUnit
269 # the + and - (glue lengths) are optional
270 # the + always precedes the -
272 # Convert relative lengths to LaTeX units
273 units = {"text%":"\\textwidth", "col%":"\\columnwidth",
274 "page%":"\\paperwidth", "line%":"\\linewidth",
275 "theight%":"\\textheight", "pheight%":"\\paperheight"}
276 for unit in units.keys():
281 minus = slen.rfind("-", 1, i)
282 plus = slen.rfind("+", 0, i)
283 latex_unit = units[unit]
284 if plus == -1 and minus == -1:
286 value = str(float(value)/100)
287 end = slen[i + len(unit):]
288 slen = value + latex_unit + end
290 value = slen[plus + 1:i]
291 value = str(float(value)/100)
292 begin = slen[:plus + 1]
293 end = slen[i+len(unit):]
294 slen = begin + value + latex_unit + end
296 value = slen[minus + 1:i]
297 value = str(float(value)/100)
298 begin = slen[:minus + 1]
299 slen = begin + value + latex_unit
301 # replace + and -, but only if the - is not the first character
302 slen = slen[0] + slen[1:].replace("+", " plus ").replace("-", " minus ")
303 # handle the case where "+-1mm" was used, because LaTeX only understands
304 # "plus 1mm minus 1mm"
305 if slen.find("plus minus"):
306 lastvaluepos = slen.rfind(" ")
307 lastvalue = slen[lastvaluepos:]
308 slen = slen.replace(" ", lastvalue + " ")
310 return "False," + slen
312 return "True," + slen
315 def revert_flex_inset(document, name, LaTeXname, position):
316 " Convert flex insets to TeX code "
319 i = find_token(document.body, '\\begin_inset Flex ' + name, i)
322 z = find_end_of_inset(document.body, i)
324 document.warning("Malformed LyX document: Can't find end of Flex " + name + " inset.")
326 # remove the \end_inset
327 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
328 # we need to reset character layouts if necessary
329 j = find_token(document.body, '\\emph on', i, z)
330 k = find_token(document.body, '\\noun on', i, z)
331 l = find_token(document.body, '\\series', i, z)
332 m = find_token(document.body, '\\family', i, z)
333 n = find_token(document.body, '\\shape', i, z)
334 o = find_token(document.body, '\\color', i, z)
335 p = find_token(document.body, '\\size', i, z)
336 q = find_token(document.body, '\\bar under', i, z)
337 r = find_token(document.body, '\\uuline on', i, z)
338 s = find_token(document.body, '\\uwave on', i, z)
339 t = find_token(document.body, '\\strikeout on', i, z)
341 document.body.insert(z - 2, "\\emph default")
343 document.body.insert(z - 2, "\\noun default")
345 document.body.insert(z - 2, "\\series default")
347 document.body.insert(z - 2, "\\family default")
349 document.body.insert(z - 2, "\\shape default")
351 document.body.insert(z - 2, "\\color inherit")
353 document.body.insert(z - 2, "\\size default")
355 document.body.insert(z - 2, "\\bar default")
357 document.body.insert(z - 2, "\\uuline default")
359 document.body.insert(z - 2, "\\uwave default")
361 document.body.insert(z - 2, "\\strikeout default")
362 document.body[i:i + 4] = put_cmd_in_ert(LaTeXname + "{")
366 def revert_font_attrs(document, name, LaTeXname):
367 " Reverts font changes to TeX code "
371 i = find_token(document.body, name + ' on', i)
374 j = find_token(document.body, name + ' default', i)
375 k = find_token(document.body, name + ' on', i + 1)
376 # if there is no default set, the style ends with the layout
377 # assure hereby that we found the correct layout end
378 if j != -1 and (j < k or k == -1):
379 document.body[j:j + 1] = put_cmd_in_ert("}")
381 j = find_token(document.body, '\\end_layout', i)
382 document.body[j:j] = put_cmd_in_ert("}")
383 document.body[i:i + 1] = put_cmd_in_ert(LaTeXname + "{")
388 def revert_layout_command(document, name, LaTeXname, position):
389 " Reverts a command from a layout to TeX code "
392 i = find_token(document.body, '\\begin_layout ' + name, i)
396 # find the next layout
399 j = find_token(document.body, '\\begin_layout', j)
400 l = len(document.body)
401 # if nothing was found it was the last layout of the document
403 document.body[l - 4:l - 4] = put_cmd_in_ert("}")
405 # exclude plain layout because this can be TeX code or another inset
406 elif document.body[j] != '\\begin_layout Plain Layout':
407 document.body[j - 2:j - 2] = put_cmd_in_ert("}")
411 document.body[i] = '\\begin_layout Standard'
412 document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{")
416 ###############################################################################
418 ### Conversion and reversion routines
420 ###############################################################################
422 def revert_swiss(document):
423 " Set language german-ch to ngerman "
425 if document.language == "german-ch":
426 document.language = "ngerman"
427 i = find_token(document.header, "\\language", 0)
429 document.header[i] = "\\language ngerman"
432 j = find_token(document.body, "\\lang german-ch", j)
435 document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
439 def revert_tabularvalign(document):
440 " Revert the tabular valign option "
443 i = find_token(document.body, "\\begin_inset Tabular", i)
446 end = find_end_of_inset(document.body, i)
448 document.warning("Can't find end of inset at line " + str(i))
451 fline = find_token(document.body, "<features", i, end)
453 document.warning("Can't find features for inset at line " + str(i))
456 p = document.body[fline].find("islongtable")
458 q = document.body[fline].find("tabularvalignment")
461 # This seems wrong: It removes everything after
462 # tabularvalignment, too.
463 document.body[fline] = document.body[fline][:q - 1] + '>'
468 tabularvalignment = 'c'
469 # which valignment is specified?
470 m = document.body[fline].find('tabularvalignment="top"')
472 tabularvalignment = 't'
473 m = document.body[fline].find('tabularvalignment="bottom"')
475 tabularvalignment = 'b'
476 # delete tabularvalignment
477 q = document.body[fline].find("tabularvalignment")
480 # This seems wrong: It removes everything after
481 # tabularvalignment, too.
482 document.body[fline] = document.body[fline][:q - 1] + '>'
484 # don't add a box when centered
485 if tabularvalignment == 'c':
488 subst = ['\\end_layout', '\\end_inset']
489 document.body[end:end] = subst # just inserts those lines
490 subst = ['\\begin_inset Box Frameless',
491 'position "' + tabularvalignment +'"',
496 # we don't know the width, assume 50%
500 'height_special "totalheight"',
503 '\\begin_layout Plain Layout']
504 document.body[i:i] = subst # this just inserts the array at i
505 # since there could be a tabular inside a tabular, we cannot
510 def revert_phantom_types(document, ptype, cmd):
511 " Reverts phantom to ERT "
514 i = find_token(document.body, "\\begin_inset Phantom " + ptype, i)
517 end = find_end_of_inset(document.body, i)
519 document.warning("Can't find end of inset at line " + str(i))
522 blay = find_token(document.body, "\\begin_layout Plain Layout", i, end)
524 document.warning("Can't find layout for inset at line " + str(i))
527 bend = find_token(document.body, "\\end_layout", blay, end)
529 document.warning("Malformed LyX document: Could not find end of Phantom inset's layout.")
532 substi = ["\\begin_inset ERT", "status collapsed", "",
533 "\\begin_layout Plain Layout", "", "", "\\backslash",
534 cmd + "{", "\\end_layout", "", "\\end_inset"]
535 substj = ["\\size default", "", "\\begin_inset ERT", "status collapsed", "",
536 "\\begin_layout Plain Layout", "", "}", "\\end_layout", "", "\\end_inset"]
537 # do the later one first so as not to mess up the numbering
538 document.body[bend:end + 1] = substj
539 document.body[i:blay + 1] = substi
540 i = end + len(substi) + len(substj) - (end - bend) - (blay - i) - 2
543 def revert_phantom(document):
544 revert_phantom_types(document, "Phantom", "phantom")
546 def revert_hphantom(document):
547 revert_phantom_types(document, "HPhantom", "hphantom")
549 def revert_vphantom(document):
550 revert_phantom_types(document, "VPhantom", "vphantom")
553 def revert_xetex(document):
554 " Reverts documents that use XeTeX "
555 i = find_token(document.header, '\\use_xetex', 0)
557 document.warning("Malformed LyX document: Missing \\use_xetex.")
559 if get_value(document.header, "\\use_xetex", i) == 'false':
560 del document.header[i]
562 del document.header[i]
563 # 1.) set doc encoding to utf8-plain
564 i = find_token(document.header, "\\inputencoding", 0)
566 document.warning("Malformed LyX document: Missing \\inputencoding.")
567 document.header[i] = "\\inputencoding utf8-plain"
568 # 2.) check font settings
569 l = find_token(document.header, "\\font_roman", 0)
571 document.warning("Malformed LyX document: Missing \\font_roman.")
572 line = document.header[l]
573 l = re.compile(r'\\font_roman (.*)$')
576 l = find_token(document.header, "\\font_sans", 0)
578 document.warning("Malformed LyX document: Missing \\font_sans.")
579 line = document.header[l]
580 l = re.compile(r'\\font_sans (.*)$')
583 l = find_token(document.header, "\\font_typewriter", 0)
585 document.warning("Malformed LyX document: Missing \\font_typewriter.")
586 line = document.header[l]
587 l = re.compile(r'\\font_typewriter (.*)$')
589 typewriter = m.group(1)
590 osf = get_value(document.header, '\\font_osf', 0) == "true"
591 sf_scale = float(get_value(document.header, '\\font_sf_scale', 0))
592 tt_scale = float(get_value(document.header, '\\font_tt_scale', 0))
593 # 3.) set preamble stuff
594 pretext = '%% This document must be processed with xelatex!\n'
595 pretext += '\\usepackage{fontspec}\n'
596 if roman != "default":
597 pretext += '\\setmainfont[Mapping=tex-text]{' + roman + '}\n'
598 if sans != "default":
599 pretext += '\\setsansfont['
601 pretext += 'Scale=' + str(sf_scale / 100) + ','
602 pretext += 'Mapping=tex-text]{' + sans + '}\n'
603 if typewriter != "default":
604 pretext += '\\setmonofont'
606 pretext += '[Scale=' + str(tt_scale / 100) + ']'
607 pretext += '{' + typewriter + '}\n'
609 pretext += '\\defaultfontfeatures{Numbers=OldStyle}\n'
610 pretext += '\usepackage{xunicode}\n'
611 pretext += '\usepackage{xltxtra}\n'
612 insert_to_preamble(0, document, pretext)
613 # 4.) reset font settings
614 i = find_token(document.header, "\\font_roman", 0)
616 document.warning("Malformed LyX document: Missing \\font_roman.")
617 document.header[i] = "\\font_roman default"
618 i = find_token(document.header, "\\font_sans", 0)
620 document.warning("Malformed LyX document: Missing \\font_sans.")
621 document.header[i] = "\\font_sans default"
622 i = find_token(document.header, "\\font_typewriter", 0)
624 document.warning("Malformed LyX document: Missing \\font_typewriter.")
625 document.header[i] = "\\font_typewriter default"
626 i = find_token(document.header, "\\font_osf", 0)
628 document.warning("Malformed LyX document: Missing \\font_osf.")
629 document.header[i] = "\\font_osf false"
630 i = find_token(document.header, "\\font_sc", 0)
632 document.warning("Malformed LyX document: Missing \\font_sc.")
633 document.header[i] = "\\font_sc false"
634 i = find_token(document.header, "\\font_sf_scale", 0)
636 document.warning("Malformed LyX document: Missing \\font_sf_scale.")
637 document.header[i] = "\\font_sf_scale 100"
638 i = find_token(document.header, "\\font_tt_scale", 0)
640 document.warning("Malformed LyX document: Missing \\font_tt_scale.")
641 document.header[i] = "\\font_tt_scale 100"
644 def revert_outputformat(document):
645 " Remove default output format param "
646 i = find_token(document.header, '\\default_output_format', 0)
648 document.warning("Malformed LyX document: Missing \\default_output_format.")
650 del document.header[i]
654 val = string.atoi(s, 16)
657 return str(val / 256.0)
660 def revert_backgroundcolor(document):
661 " Reverts background color to preamble code "
662 i = find_token(document.header, "\\backgroundcolor", 0)
665 colorcode = get_value(document.header, '\\backgroundcolor', i)
666 del document.header[i]
667 # don't clutter the preamble if backgroundcolor is not set
668 if colorcode == "#ffffff":
670 red = hex2ratio(colorcode[1:3])
671 green = hex2ratio(colorcode[3:5])
672 blue = hex2ratio(colorcode[5:7])
673 insert_to_preamble(0, document,
674 '% Commands inserted by lyx2lyx to set the background color\n'
675 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
676 + '\\definecolor{page_backgroundcolor}{rgb}{'
677 + red + ',' + green + ',' + blue + '}\n'
678 + '\\pagecolor{page_backgroundcolor}\n')
681 def revert_splitindex(document):
682 " Reverts splitindex-aware documents "
683 i = find_token(document.header, '\\use_indices', 0)
685 document.warning("Malformed LyX document: Missing \\use_indices.")
687 indices = get_value(document.header, "\\use_indices", i)
689 useindices = (indices == "true")
691 preamble += "\\usepackage{splitidx}\n"
692 del document.header[i]
694 # deal with index declarations in the preamble
697 i = find_token(document.header, "\\index", i)
700 k = find_token(document.header, "\\end_index", i)
702 document.warning("Malformed LyX document: Missing \\end_index.")
705 line = document.header[i]
706 l = re.compile(r'\\index (.*)$')
709 ishortcut = get_value(document.header, '\\shortcut', i, k)
711 preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
712 del document.header[i:k + 1]
714 insert_to_preamble(0, document, preamble)
716 # deal with index insets
717 # these need to have the argument removed
720 i = find_token(document.body, "\\begin_inset Index", i)
723 line = document.body[i]
724 l = re.compile(r'\\begin_inset Index (.*)$')
727 if itype == "idx" or indices == "false":
728 document.body[i] = "\\begin_inset Index"
730 k = find_end_of_inset(document.body, i)
732 document.warning("Can't find end of index inset!")
735 content = lyx2latex(document, document.body[i:k])
737 content = content.replace('"', r'\"')
738 subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
739 document.body[i:k + 1] = subst
742 # deal with index_print insets
745 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
748 k = find_end_of_inset(document.body, i)
749 ptype = get_value(document.body, 'type', i, k).strip('"')
751 j = find_token(document.body, "type", i, k)
754 del document.body[i:k + 1]
756 subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
757 document.body[i:k + 1] = subst
761 def convert_splitindex(document):
762 " Converts index and printindex insets to splitindex-aware format "
765 i = find_token(document.body, "\\begin_inset Index", i)
768 document.body[i] = document.body[i].replace("\\begin_inset Index",
769 "\\begin_inset Index idx")
773 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
776 if document.body[i + 1].find('LatexCommand printindex') == -1:
777 document.warning("Malformed LyX document: Incomplete printindex inset.")
779 subst = ["LatexCommand printindex",
781 document.body[i + 1:i + 2] = subst
785 def revert_subindex(document):
786 " Reverts \\printsubindex CommandInset types "
787 i = find_token(document.header, '\\use_indices', 0)
789 document.warning("Malformed LyX document: Missing \\use_indices.")
791 indices = get_value(document.header, "\\use_indices", i)
792 useindices = (indices == "true")
795 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
798 k = find_end_of_inset(document.body, i)
799 ctype = get_value(document.body, 'LatexCommand', i, k)
800 if ctype != "printsubindex":
803 ptype = get_value(document.body, 'type', i, k).strip('"')
805 del document.body[i:k + 1]
807 subst = put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")
808 document.body[i:k + 1] = subst
812 def revert_printindexall(document):
813 " Reverts \\print[sub]index* CommandInset types "
814 i = find_token(document.header, '\\use_indices', 0)
816 document.warning("Malformed LyX document: Missing \\use_indices.")
818 indices = get_value(document.header, "\\use_indices", i)
819 useindices = (indices == "true")
822 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
825 k = find_end_of_inset(document.body, i)
826 ctype = get_value(document.body, 'LatexCommand', i, k)
827 if ctype != "printindex*" and ctype != "printsubindex*":
831 del document.body[i:k + 1]
833 subst = put_cmd_in_ert("\\" + ctype + "{}")
834 document.body[i:k + 1] = subst
838 def revert_strikeout(document):
839 " Reverts \\strikeout font attribute "
840 changed = revert_font_attrs(document, "\\uuline", "\\uuline")
841 changed = revert_font_attrs(document, "\\uwave", "\\uwave") or changed
842 changed = revert_font_attrs(document, "\\strikeout", "\\sout") or changed
844 insert_to_preamble(0, document,
845 '% Commands inserted by lyx2lyx for proper underlining\n'
846 + '\\PassOptionsToPackage{normalem}{ulem}\n'
847 + '\\usepackage{ulem}\n')
850 def revert_ulinelatex(document):
851 " Reverts \\uline font attribute "
852 i = find_token(document.body, '\\bar under', 0)
855 insert_to_preamble(0, document,
856 '% Commands inserted by lyx2lyx for proper underlining\n'
857 + '\\PassOptionsToPackage{normalem}{ulem}\n'
858 + '\\usepackage{ulem}\n'
859 + '\\let\\cite@rig\\cite\n'
860 + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n'
861 + ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n'
862 + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n')
865 def revert_custom_processors(document):
866 " Remove bibtex_command and index_command params "
867 i = find_token(document.header, '\\bibtex_command', 0)
869 document.warning("Malformed LyX document: Missing \\bibtex_command.")
871 del document.header[i]
872 i = find_token(document.header, '\\index_command', 0)
874 document.warning("Malformed LyX document: Missing \\index_command.")
876 del document.header[i]
879 def convert_nomencl_width(document):
880 " Add set_width param to nomencl_print "
883 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
886 document.body.insert(i + 2, "set_width \"none\"")
890 def revert_nomencl_width(document):
891 " Remove set_width param from nomencl_print "
894 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
897 j = find_end_of_inset(document.body, i)
898 l = find_token(document.body, "set_width", i, j)
900 document.warning("Can't find set_width option for nomencl_print!")
907 def revert_nomencl_cwidth(document):
908 " Remove width param from nomencl_print "
911 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
914 j = find_end_of_inset(document.body, i)
915 l = find_token(document.body, "width", i, j)
917 document.warning("Can't find width option for nomencl_print!")
920 width = get_value(document.body, "width", i, j).strip('"')
922 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
923 add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
927 def revert_applemac(document):
928 " Revert applemac encoding to auto "
929 if document.encoding != "applemac":
931 document.encoding = "auto"
932 i = find_token(document.header, "\\encoding", 0)
934 document.header[i] = "\\encoding auto"
937 def revert_longtable_align(document):
938 " Remove longtable alignment setting "
941 i = find_token(document.body, "\\begin_inset Tabular", i)
944 end = find_end_of_inset(document.body, i)
946 document.warning("Can't find end of inset at line " + str(i))
949 fline = find_token(document.body, "<features", i, end)
951 document.warning("Can't find features for inset at line " + str(i))
954 j = document.body[fline].find("longtabularalignment")
958 # FIXME Is this correct? It wipes out everything after the
960 document.body[fline] = document.body[fline][:j - 1] + '>'
961 # since there could be a tabular inside this one, we
962 # cannot jump to end.
966 def revert_branch_filename(document):
967 " Remove \\filename_suffix parameter from branches "
970 i = find_token(document.header, "\\filename_suffix", i)
973 del document.header[i]
976 def revert_paragraph_indentation(document):
977 " Revert custom paragraph indentation to preamble code "
978 i = find_token(document.header, "\\paragraph_indentation", i)
981 length = get_value(document.header, "\\paragraph_indentation", i)
982 # we need only remove the line if indentation is default
983 if length != "default":
984 # handle percent lengths
985 # latex_length returns "bool,length"
986 length = latex_length(length).split(",")[1]
987 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
988 add_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
989 del document.header[i]
992 def revert_percent_skip_lengths(document):
993 " Revert relative lengths for paragraph skip separation to preamble code "
994 i = find_token(document.header, "\\defskip", i)
997 length = get_value(document.header, "\\defskip", i)
998 # only revert when a custom length was set and when
999 # it used a percent length
1000 if length in ('smallskip', 'medskip', 'bigskip'):
1002 # handle percent lengths
1003 length = latex_length(length)
1004 # latex_length returns "bool,length"
1005 percent = length.split(",")[0]
1006 length = length.split(",")[1]
1007 if percent == "True":
1008 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1009 add_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
1010 # set defskip to medskip as default
1011 document.header[i] = "\\defskip medskip"
1014 def revert_percent_vspace_lengths(document):
1015 " Revert relative VSpace lengths to ERT "
1018 i = find_token(document.body, "\\begin_inset VSpace", i)
1021 # only revert if a custom length was set and if
1022 # it used a percent length
1023 line = document.body[i]
1024 r = re.compile(r'\\begin_inset VSpace (.*)$')
1027 if length not in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
1028 # check if the space has a star (protected space)
1029 protected = (document.body[i].rfind("*") != -1)
1031 length = length.rstrip('*')
1032 # handle percent lengths
1033 length = latex_length(length)
1034 # latex_length returns "bool,length"
1035 percent = length.split(",")[0]
1036 length = length.split(",")[1]
1037 # revert the VSpace inset to ERT
1038 if percent == "True":
1040 subst = [old_put_cmd_in_ert("\\vspace*{" + length + "}")]
1042 subst = [old_put_cmd_in_ert("\\vspace{" + length + "}")]
1043 document.body[i:i + 2] = subst
1047 def revert_percent_hspace_lengths(document):
1048 " Revert relative HSpace lengths to ERT "
1051 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1054 protected = (document.body[i].find("\\hspace*{}") != -1)
1055 # only revert if a custom length was set and if
1056 # it used a percent length
1057 length = get_value(document.body, '\\length', i + 1)
1059 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1061 # handle percent lengths
1062 length = latex_length(length)
1063 # latex_length returns "bool,length"
1064 percent = length.split(",")[0]
1065 length = length.split(",")[1]
1066 # revert the HSpace inset to ERT
1067 if percent == "True":
1069 subst = [old_put_cmd_in_ert("\\hspace*{" + length + "}")]
1071 subst = [old_put_cmd_in_ert("\\hspace{" + length + "}")]
1072 document.body[i:i + 3] = subst
1076 def revert_hspace_glue_lengths(document):
1077 " Revert HSpace glue lengths to ERT "
1080 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1083 protected = (document.body[i].find("\\hspace*{}") != -1)
1084 length = get_value(document.body, '\\length', i + 1)
1086 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1088 # only revert if the length contains a plus or minus at pos != 0
1089 glue = re.compile(r'.+[\+-]')
1090 if glue.search(length):
1091 # handle percent lengths
1092 # latex_length returns "bool,length"
1093 length = latex_length(length).split(",")[1]
1094 # revert the HSpace inset to ERT
1096 subst = [old_put_cmd_in_ert("\\hspace*{" + length + "}")]
1098 subst = [old_put_cmd_in_ert("\\hspace{" + length + "}")]
1099 document.body[i:i + 3] = subst
1102 def convert_author_id(document):
1103 " Add the author_id to the \\author definition and make sure 0 is not used"
1107 i = find_token(document.header, "\\author", i)
1111 r = re.compile(r'(\\author) (\".*\")\s?(.*)$')
1112 m = r.match(document.header[i])
1117 if m.lastindex == 3:
1119 document.header[i] = "\\author %i %s %s" % (j, name, email)
1125 k = find_token(document.body, "\\change_", k)
1129 change = document.body[k].split(' ');
1130 if len(change) == 3:
1132 author_id = int(change[1])
1134 document.body[k] = "%s %i %s" % (type, author_id + 1, time)
1137 def revert_author_id(document):
1138 " Remove the author_id from the \\author definition "
1143 i = find_token(document.header, "\\author", i)
1147 r = re.compile(r'(\\author) (\d+) (\".*\")\s?(.*)$')
1148 m = r.match(document.header[i])
1150 author_id = int(m.group(2))
1151 idmap[author_id] = j
1155 if m.lastindex == 4:
1157 document.header[i] = "\\author %s %s" % (name, email)
1163 k = find_token(document.body, "\\change_", k)
1167 change = document.body[k].split(' ');
1168 if len(change) == 3:
1170 author_id = int(change[1])
1172 document.body[k] = "%s %i %s" % (type, idmap[author_id], time)
1176 def revert_suppress_date(document):
1177 " Revert suppressing of default document date to preamble code "
1180 i = find_token(document.header, "\\suppress_date", i)
1183 # remove the preamble line and write to the preamble
1184 # when suppress_date was true
1185 date = get_value(document.header, "\\suppress_date", i)
1187 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1188 add_to_preamble(document, ["\\date{}"])
1189 del document.header[i]
1193 def revert_mhchem(document):
1194 "Revert mhchem loading to preamble code"
1199 i = find_token(document.header, "\\use_mhchem 1", 0)
1203 i = find_token(document.header, "\\use_mhchem 2", 0)
1206 if mhchem == "auto":
1207 j = find_token(document.body, "\\cf{", 0)
1211 j = find_token(document.body, "\\ce{", 0)
1215 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1216 add_to_preamble(document, ["\\PassOptionsToPackage{version=3}{mhchem}"])
1217 add_to_preamble(document, ["\\usepackage{mhchem}"])
1218 k = find_token(document.header, "\\use_mhchem", 0)
1220 document.warning("Malformed LyX document: Could not find mhchem setting.")
1222 del document.header[k]
1225 def revert_fontenc(document):
1226 " Remove fontencoding param "
1227 i = find_token(document.header, '\\fontencoding', 0)
1229 document.warning("Malformed LyX document: Missing \\fontencoding.")
1231 del document.header[i]
1234 def merge_gbrief(document):
1235 " Merge g-brief-en and g-brief-de to one class "
1237 if document.textclass != "g-brief-de":
1238 if document.textclass == "g-brief-en":
1239 document.textclass = "g-brief"
1240 document.set_textclass()
1243 obsoletedby = { "Brieftext": "Letter",
1244 "Unterschrift": "Signature",
1245 "Strasse": "Street",
1246 "Zusatz": "Addition",
1249 "RetourAdresse": "ReturnAddress",
1250 "MeinZeichen": "MyRef",
1251 "IhrZeichen": "YourRef",
1252 "IhrSchreiben": "YourMail",
1255 "Konto": "BankAccount",
1256 "Postvermerk": "PostalComment",
1257 "Adresse": "Address",
1259 "Betreff": "Reference",
1260 "Anrede": "Opening",
1266 i = find_token(document.body, "\\begin_layout", i)
1270 layout = document.body[i][14:]
1271 if layout in obsoletedby:
1272 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1276 document.textclass = "g-brief"
1277 document.set_textclass()
1280 def revert_gbrief(document):
1281 " Revert g-brief to g-brief-en "
1282 if document.textclass == "g-brief":
1283 document.textclass = "g-brief-en"
1284 document.set_textclass()
1287 def revert_html_options(document):
1288 " Remove html options "
1289 i = find_token(document.header, '\\html_use_mathml', 0)
1291 del document.header[i]
1292 i = find_token(document.header, '\\html_be_strict', 0)
1294 del document.header[i]
1297 def revert_includeonly(document):
1300 i = find_token(document.header, "\\begin_includeonly", i)
1303 j = find_end_of(document.header, i, "\\begin_includeonly", "\\end_includeonly")
1305 # this should not happen
1307 document.header[i : j + 1] = []
1310 def revert_includeall(document):
1311 " Remove maintain_unincluded_children param "
1312 i = find_token(document.header, '\\maintain_unincluded_children', 0)
1314 del document.header[i]
1317 def revert_multirow(document):
1318 " Revert multirow cells in tables to TeX-code"
1322 # cell type 3 is multirow begin cell
1323 i = find_token(document.body, '<cell multirow="3"', i)
1326 # a multirow cell was found
1328 # remove the multirow tag, set the valignment to top
1329 # and remove the bottom line
1330 document.body[i] = document.body[i].replace(' multirow="3" ', ' ')
1331 document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
1332 document.body[i] = document.body[i].replace(' bottomline="true" ', ' ')
1333 # write ERT to create the multirow cell
1334 # use 2 rows and 2cm as default with because the multirow span
1335 # and the column width is only hardly accessible
1336 subst = [old_put_cmd_in_ert("\\multirow{2}{2cm}{")]
1337 document.body[i + 4:i + 4] = subst
1338 i = find_token(document.body, "</cell>", i)
1340 document.warning("Malformed LyX document: Could not find end of tabular cell.")
1342 subst = [old_put_cmd_in_ert("}")]
1343 document.body[i - 3:i - 3] = subst
1344 # cell type 4 is multirow part cell
1345 i = find_token(document.body, '<cell multirow="4"', i)
1348 # remove the multirow tag, set the valignment to top
1349 # and remove the top line
1350 document.body[i] = document.body[i].replace(' multirow="4" ', ' ')
1351 document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
1352 document.body[i] = document.body[i].replace(' topline="true" ', ' ')
1354 if multirow == True:
1355 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1356 add_to_preamble(document, ["\\usepackage{multirow}"])
1359 def convert_math_output(document):
1360 " Convert \html_use_mathml to \html_math_output "
1361 i = find_token(document.header, "\\html_use_mathml", 0)
1364 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1365 m = rgx.match(document.header[i])
1366 newval = "0" # MathML
1370 newval = "2" # Images
1372 document.warning("Can't match " + document.header[i])
1373 document.header[i] = "\\html_math_output " + newval
1376 def revert_math_output(document):
1377 " Revert \html_math_output to \html_use_mathml "
1378 i = find_token(document.header, "\\html_math_output", 0)
1381 rgx = re.compile(r'\\html_math_output\s+(\d)')
1382 m = rgx.match(document.header[i])
1386 if val == "1" or val == "2":
1389 document.warning("Unable to match " + document.header[i])
1390 document.header[i] = "\\html_use_mathml " + newval
1394 def revert_inset_preview(document):
1395 " Dissolves the preview inset "
1400 i = find_token(document.body, "\\begin_inset Preview", i)
1403 j = find_end_of_inset(document.body, i)
1405 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1407 #If the layout is Standard we need to remove it, otherwise there
1408 #will be paragraph breaks that shouldn't be there.
1409 k = find_token(document.body, "\\begin_layout Standard", i)
1411 del document.body[i:i + 3]
1412 del document.body[j - 5:j - 2]
1415 del document.body[i]
1416 del document.body[j - 1]
1420 def revert_equalspacing_xymatrix(document):
1421 " Revert a Formula with xymatrix@! to an ERT inset "
1424 has_preamble = False
1425 has_equal_spacing = False
1428 i = find_token(document.body, "\\begin_inset Formula", i)
1431 j = find_end_of_inset(document.body, i)
1433 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1436 for curline in range(i,j):
1437 found = document.body[curline].find("\\xymatrix@!")
1442 has_equal_spacing = True
1443 content = [document.body[i][21:]]
1444 content += document.body[i + 1:j]
1445 subst = put_cmd_in_ert(content)
1446 document.body[i:j + 1] = subst
1449 for curline in range(i,j):
1450 l = document.body[curline].find("\\xymatrix")
1452 has_preamble = True;
1455 if has_equal_spacing and not has_preamble:
1456 add_to_preamble(document, ['\\usepackage[all]{xy}'])
1459 def revert_notefontcolor(document):
1460 " Reverts greyed-out note font color to preamble code "
1464 i = find_token(document.header, "\\notefontcolor", i)
1467 colorcode = get_value(document.header, '\\notefontcolor', 0)
1468 del document.header[i]
1469 # the color code is in the form #rrggbb where every character denotes a hex number
1470 # convert the string to an int
1471 red = string.atoi(colorcode[1:3],16)
1472 # we want the output "0.5" for the value "127" therefore increment here
1475 redout = float(red) / 256
1476 green = string.atoi(colorcode[3:5],16)
1479 greenout = float(green) / 256
1480 blue = string.atoi(colorcode[5:7],16)
1483 blueout = float(blue) / 256
1484 # write the preamble
1485 insert_to_preamble(0, document,
1486 '% Commands inserted by lyx2lyx to set the font color\n'
1487 '% for greyed-out notes\n'
1488 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1489 + '\\definecolor{note_fontcolor}{rgb}{'
1490 + str(redout) + ', ' + str(greenout)
1491 + ', ' + str(blueout) + '}\n'
1492 + '\\renewenvironment{lyxgreyedout}\n'
1493 + ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n')
1496 def revert_turkmen(document):
1497 "Set language Turkmen to English"
1499 if document.language == "turkmen":
1500 document.language = "english"
1501 i = find_token(document.header, "\\language", 0)
1503 document.header[i] = "\\language english"
1506 j = find_token(document.body, "\\lang turkmen", j)
1509 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1513 def revert_fontcolor(document):
1514 " Reverts font color to preamble code "
1518 i = find_token(document.header, "\\fontcolor", i)
1521 colorcode = get_value(document.header, '\\fontcolor', 0)
1522 del document.header[i]
1523 # don't clutter the preamble if backgroundcolor is not set
1524 if colorcode == "#000000":
1526 # the color code is in the form #rrggbb where every character denotes a hex number
1527 # convert the string to an int
1528 red = string.atoi(colorcode[1:3],16)
1529 # we want the output "0.5" for the value "127" therefore add here
1532 redout = float(red) / 256
1533 green = string.atoi(colorcode[3:5],16)
1536 greenout = float(green) / 256
1537 blue = string.atoi(colorcode[5:7],16)
1540 blueout = float(blue) / 256
1541 # write the preamble
1542 insert_to_preamble(0, document,
1543 '% Commands inserted by lyx2lyx to set the font color\n'
1544 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1545 + '\\definecolor{document_fontcolor}{rgb}{'
1546 + str(redout) + ', ' + str(greenout)
1547 + ', ' + str(blueout) + '}\n'
1548 + '\\color{document_fontcolor}\n')
1550 def revert_shadedboxcolor(document):
1551 " Reverts shaded box color to preamble code "
1555 i = find_token(document.header, "\\boxbgcolor", i)
1558 colorcode = get_value(document.header, '\\boxbgcolor', 0)
1559 del document.header[i]
1560 # the color code is in the form #rrggbb where every character denotes a hex number
1561 # convert the string to an int
1562 red = string.atoi(colorcode[1:3],16)
1563 # we want the output "0.5" for the value "127" therefore increment here
1566 redout = float(red) / 256
1567 green = string.atoi(colorcode[3:5],16)
1570 greenout = float(green) / 256
1571 blue = string.atoi(colorcode[5:7],16)
1574 blueout = float(blue) / 256
1575 # write the preamble
1576 insert_to_preamble(0, document,
1577 '% Commands inserted by lyx2lyx to set the color\n'
1578 '% of boxes with shaded background\n'
1579 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1580 + '\\definecolor{shadecolor}{rgb}{'
1581 + str(redout) + ', ' + str(greenout)
1582 + ', ' + str(blueout) + '}\n')
1585 def revert_lyx_version(document):
1586 " Reverts LyX Version information from Inset Info "
1587 version = "LyX version"
1589 import lyx2lyx_version
1590 version = lyx2lyx_version.version
1596 i = find_token(document.body, '\\begin_inset Info', i)
1599 j = find_end_of_inset(document.body, i + 1)
1602 document.warning("Malformed LyX document: Could not find end of Info inset.")
1608 # but we shall try to be forgiving.
1610 for k in range(i, j):
1611 if document.body[k].startswith("arg"):
1612 arg = document.body[k][3:].strip().strip('"')
1613 if document.body[k].startswith("type"):
1614 typ = document.body[k][4:].strip().strip('"')
1615 if arg != "version" or typ != "lyxinfo":
1619 # We do not actually know the version of LyX used to produce the document.
1620 # But we can use our version, since we are reverting.
1622 # Now we want to check if the line after "\end_inset" is empty. It normally
1623 # is, so we want to remove it, too.
1625 if document.body[j + 1].strip() == "":
1627 document.body[i: lastline] = s
1631 def revert_math_scale(document):
1632 " Remove math scaling and LaTeX options "
1633 i = find_token(document.header, '\\html_math_img_scale', 0)
1635 del document.header[i]
1636 i = find_token(document.header, '\\html_latex_start', 0)
1638 del document.header[i]
1639 i = find_token(document.header, '\\html_latex_end', 0)
1641 del document.header[i]
1644 def revert_pagesizes(document):
1646 " Revert page sizes to default "
1647 i = find_token(document.header, '\\papersize', 0)
1649 size = document.header[i][11:]
1650 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1651 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1652 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1653 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1654 or size == "b5j" or size == "b6j":
1655 del document.header[i]
1658 def revert_DIN_C_pagesizes(document):
1660 " Revert DIN C page sizes to default "
1661 i = find_token(document.header, '\\papersize', 0)
1663 size = document.header[i][11:]
1664 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1665 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1666 or size == "c6paper":
1667 del document.header[i]
1670 def convert_html_quotes(document):
1671 " Remove quotes around html_latex_start and html_latex_end "
1673 i = find_token(document.header, '\\html_latex_start', 0)
1675 line = document.header[i]
1676 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1679 document.header[i] = "\\html_latex_start " + m.group(1)
1681 i = find_token(document.header, '\\html_latex_end', 0)
1683 line = document.header[i]
1684 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1687 document.header[i] = "\\html_latex_end " + m.group(1)
1690 def revert_html_quotes(document):
1691 " Remove quotes around html_latex_start and html_latex_end "
1693 i = find_token(document.header, '\\html_latex_start', 0)
1695 line = document.header[i]
1696 l = re.compile(r'\\html_latex_start\s+(.*)')
1698 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1700 i = find_token(document.header, '\\html_latex_end', 0)
1702 line = document.header[i]
1703 l = re.compile(r'\\html_latex_end\s+(.*)')
1705 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1708 def revert_output_sync(document):
1709 " Remove forward search options "
1710 i = find_token(document.header, '\\output_sync_macro', 0)
1712 del document.header[i]
1713 i = find_token(document.header, '\\output_sync', 0)
1715 del document.header[i]
1718 def convert_beamer_args(document):
1719 " Convert ERT arguments in Beamer to InsetArguments "
1721 if document.textclass != "beamer" and document.textclass != "article-beamer":
1724 layouts = ("Block", "ExampleBlock", "AlertBlock")
1725 for layout in layouts:
1728 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1731 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1733 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1736 bert = find_token(document.body, '\\begin_inset ERT', blay)
1738 document.warning("Malformed Beamer LyX document: Can't find argument of " + layout + " layout.")
1741 eert = find_end_of_inset(document.body, bert)
1743 document.warning("Malformed LyX document: Can't find end of ERT.")
1747 # So the ERT inset begins at line k and goes to line l. We now wrap it in
1748 # an argument inset.
1749 # Do the end first, so as not to mess up the variables.
1750 document.body[eert + 1:eert + 1] = ['', '\\end_layout', '', '\\end_inset', '']
1751 document.body[bert:bert] = ['\\begin_inset OptArg', 'status open', '',
1752 '\\begin_layout Plain Layout']
1756 def revert_beamer_args(document):
1757 " Revert Beamer arguments to ERT "
1759 if document.textclass != "beamer" and document.textclass != "article-beamer":
1762 layouts = ("Block", "ExampleBlock", "AlertBlock")
1763 for layout in layouts:
1766 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1769 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1771 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1774 bopt = find_token(document.body, '\\begin_inset OptArg', blay)
1776 # it is legal not to have one of these
1779 eopt = find_end_of_inset(document.body, bopt)
1781 document.warning("Malformed LyX document: Can't find end of argument.")
1784 bplay = find_token(document.body, '\\begin_layout Plain Layout', blay)
1786 document.warning("Malformed LyX document: Can't find plain layout.")
1789 eplay = find_end_of(document.body, bplay, '\\begin_layout', '\\end_layout')
1791 document.warning("Malformed LyX document: Can't find end of plain layout.")
1794 # So the content of the argument inset goes from bplay + 1 to eplay - 1
1798 document.warning(str(bcont) + " " + str(eplay))
1801 # we convert the content of the argument into pure LaTeX...
1802 content = lyx2latex(document, document.body[bcont:eplay])
1803 strlist = put_cmd_in_ert(["{" + content + "}"])
1805 # now replace the optional argument with the ERT
1806 document.body[bopt:eopt + 1] = strlist
1810 def revert_align_decimal(document):
1813 l = document.body[l].find('alignment=decimal')
1816 remove_option(document, l, 'decimal_point')
1817 document.body[l].replace('decimal', 'center')
1820 def convert_optarg(document):
1821 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1824 i = find_token(document.body, '\\begin_inset OptArg', i)
1827 document.body[i] = "\\begin_inset Argument"
1831 def revert_argument(document):
1832 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1835 i = find_token(document.body, '\\begin_inset Argument', i)
1838 document.body[i] = "\\begin_inset OptArg"
1842 def revert_makebox(document):
1843 " Convert \\makebox to TeX code "
1846 # only revert frameless boxes without an inner box
1847 i = find_token(document.body, '\\begin_inset Box Frameless', i)
1849 # remove the option use_makebox
1850 revert_use_makebox(document)
1852 z = find_end_of_inset(document.body, i)
1854 document.warning("Malformed LyX document: Can't find end of box inset.")
1856 j = find_token(document.body, 'use_makebox 1', i)
1857 # assure we found the makebox of the current box
1858 if j < z and j != -1:
1859 y = find_token(document.body, "\\begin_layout", i)
1860 if y > z or y == -1:
1861 document.warning("Malformed LyX document: Can't find layout in box.")
1863 # remove the \end_layout \end_inset pair
1864 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
1865 # determine the alignment
1866 k = find_token(document.body, 'hor_pos', j - 4)
1867 align = document.body[k][9]
1868 # determine the width
1869 l = find_token(document.body, 'width "', j + 1)
1870 length = document.body[l][7:]
1871 # remove trailing '"'
1872 length = length[:-1]
1873 # latex_length returns "bool,length"
1874 length = latex_length(length).split(",")[1]
1875 subst = "\\makebox[" + length + "][" \
1877 document.body[i:y + 1] = put_cmd_in_ert(subst)
1881 def revert_use_makebox(document):
1882 " Deletes use_makebox option of boxes "
1885 # remove the option use_makebox
1886 h = find_token(document.body, 'use_makebox', 0)
1889 del document.body[h]
1893 def convert_use_makebox(document):
1894 " Adds use_makebox option for boxes "
1897 # remove the option use_makebox
1898 i = find_token(document.body, '\\begin_inset Box', i)
1901 k = find_token(document.body, 'use_parbox', i)
1903 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1905 document.body.insert(k + 1, "use_makebox 0")
1909 def revert_IEEEtran(document):
1910 " Convert IEEEtran layouts and styles to TeX code "
1911 if document.textclass != "IEEEtran":
1913 revert_flex_inset(document, "IEEE membership", "\\IEEEmembership", 0)
1914 revert_flex_inset(document, "Lowercase", "\\MakeLowercase", 0)
1915 layouts = ("Special Paper Notice", "After Title Text", "Publication ID",
1916 "Page headings", "Biography without photo")
1917 latexcmd = {"Special Paper Notice": "\\IEEEspecialpapernotice",
1918 "After Title Text": "\\IEEEaftertitletext",
1919 "Publication ID": "\\IEEEpubid"}
1920 obsoletedby = {"Page headings": "MarkBoth",
1921 "Biography without photo": "BiographyNoPhoto"}
1922 for layout in layouts:
1925 i = find_token(document.body, '\\begin_layout ' + layout, i)
1928 j = find_end_of(document.body, i, '\\begin_layout', '\\end_layout')
1930 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1933 if layout in obsoletedby:
1934 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1937 content = lyx2latex(document, document.body[i:j + 1])
1938 add_to_preamble(document, [latexcmd[layout] + "{" + content + "}"])
1939 del document.body[i:j + 1]
1942 def convert_prettyref(document):
1943 " Converts prettyref references to neutral formatted refs "
1944 re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
1945 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
1949 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
1952 j = find_end_of_inset(document.body, i)
1954 document.warning("Malformed LyX document: No end of InsetRef!")
1957 k = find_token(document.body, "LatexCommand prettyref", i)
1958 if k != -1 and k < j:
1959 document.body[k] = "LatexCommand formatted"
1961 document.header.insert(-1, "\\use_refstyle 0")
1964 def revert_refstyle(document):
1965 " Reverts neutral formatted refs to prettyref "
1966 re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
1967 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
1971 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
1974 j = find_end_of_inset(document.body, i)
1976 document.warning("Malformed LyX document: No end of InsetRef")
1979 k = find_token(document.body, "LatexCommand formatted", i)
1980 if k != -1 and k < j:
1981 document.body[k] = "LatexCommand prettyref"
1983 i = find_token(document.header, "\\use_refstyle", 0)
1985 document.header.pop(i)
1988 def revert_nameref(document):
1989 " Convert namerefs to regular references "
1990 cmds = ["Nameref", "nameref"]
1992 rx = re.compile(r'reference "(.*)"')
1995 oldcmd = "LatexCommand " + cmd
1997 # It seems better to look for this, as most of the reference
1998 # insets won't be ones we care about.
1999 i = find_token(document.body, oldcmd, i)
2004 # Make sure it is actually in an inset!
2005 # We could just check document.lines[i-1], but that relies
2006 # upon something that might easily change.
2007 # We'll look back a few lines.
2011 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2012 if stins == -1 or stins > cmdloc:
2014 endins = find_end_of_inset(document.body, stins)
2016 document.warning("Can't find end of inset at line " + stins + "!!")
2020 refline = find_token(document.body, "reference", stins)
2021 if refline == -1 or refline > endins:
2022 document.warning("Can't find reference for inset at line " + stinst + "!!")
2024 m = rx.match(document.body[refline])
2026 document.warning("Can't match reference line: " + document.body[ref])
2030 newcontent = ['\\begin_inset ERT', 'status collapsed', '', \
2031 '\\begin_layout Plain Layout', '', '\\backslash', \
2032 cmd + '{' + ref + '}', '\\end_layout', '', '\\end_inset']
2033 document.body[stins:endins + 1] = newcontent
2035 add_to_preamble(document, "\usepackage{nameref}")
2038 def remove_Nameref(document):
2039 " Convert Nameref commands to nameref commands "
2042 # It seems better to look for this, as most of the reference
2043 # insets won't be ones we care about.
2044 i = find_token(document.body, "LatexCommand Nameref" , i)
2050 # Make sure it is actually in an inset!
2051 # We could just check document.lines[i-1], but that relies
2052 # upon something that might easily change.
2053 # We'll look back a few lines.
2057 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2058 if stins == -1 or stins > cmdloc:
2060 endins = find_end_of_inset(document.body, stins)
2062 document.warning("Can't find end of inset at line " + stins + "!!")
2066 document.body[cmdloc] = "LatexCommand nameref"
2069 def revert_mathrsfs(document):
2070 " Load mathrsfs if \mathrsfs us use in the document "
2072 end = len(document.body) - 1
2074 j = document.body[i].find("\\mathscr{")
2076 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2077 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
2084 def convert_flexnames(document):
2085 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
2088 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
2090 i = find_token(document.body, "\\begin_inset Flex", i)
2093 m = rx.match(document.body[i])
2095 document.body[i] = "\\begin_inset Flex " + m.group(1)
2100 ["Alert", "CharStyle:Alert"],
2101 ["Code", "CharStyle:Code"],
2102 ["Concepts", "CharStyle:Concepts"],
2103 ["E-Mail", "CharStyle:E-Mail"],
2104 ["Emph", "CharStyle:Emph"],
2105 ["Expression", "CharStyle:Expression"],
2106 ["Initial", "CharStyle:Initial"],
2107 ["Institute", "CharStyle:Institute"],
2108 ["Meaning", "CharStyle:Meaning"],
2109 ["Noun", "CharStyle:Noun"],
2110 ["Strong", "CharStyle:Strong"],
2111 ["Structure", "CharStyle:Structure"],
2112 ["ArticleMode", "Custom:ArticleMode"],
2113 ["Endnote", "Custom:Endnote"],
2114 ["Glosse", "Custom:Glosse"],
2115 ["PresentationMode", "Custom:PresentationMode"],
2116 ["Tri-Glosse", "Custom:Tri-Glosse"]
2120 ["Abbrev", "Element:Abbrev"],
2121 ["CCC-Code", "Element:CCC-Code"],
2122 ["Citation-number", "Element:Citation-number"],
2123 ["City", "Element:City"],
2124 ["Code", "Element:Code"],
2125 ["CODEN", "Element:CODEN"],
2126 ["Country", "Element:Country"],
2127 ["Day", "Element:Day"],
2128 ["Directory", "Element:Directory"],
2129 ["Dscr", "Element:Dscr"],
2130 ["Email", "Element:Email"],
2131 ["Emph", "Element:Emph"],
2132 ["Filename", "Element:Filename"],
2133 ["Firstname", "Element:Firstname"],
2134 ["Fname", "Element:Fname"],
2135 ["GuiButton", "Element:GuiButton"],
2136 ["GuiMenu", "Element:GuiMenu"],
2137 ["GuiMenuItem", "Element:GuiMenuItem"],
2138 ["ISSN", "Element:ISSN"],
2139 ["Issue-day", "Element:Issue-day"],
2140 ["Issue-months", "Element:Issue-months"],
2141 ["Issue-number", "Element:Issue-number"],
2142 ["KeyCap", "Element:KeyCap"],
2143 ["KeyCombo", "Element:KeyCombo"],
2144 ["Keyword", "Element:Keyword"],
2145 ["Literal", "Element:Literal"],
2146 ["MenuChoice", "Element:MenuChoice"],
2147 ["Month", "Element:Month"],
2148 ["Orgdiv", "Element:Orgdiv"],
2149 ["Orgname", "Element:Orgname"],
2150 ["Postcode", "Element:Postcode"],
2151 ["SS-Code", "Element:SS-Code"],
2152 ["SS-Title", "Element:SS-Title"],
2153 ["State", "Element:State"],
2154 ["Street", "Element:Street"],
2155 ["Surname", "Element:Surname"],
2156 ["Volume", "Element:Volume"],
2157 ["Year", "Element:Year"]
2161 def revert_flexnames(document):
2162 if document.backend == "latex":
2163 flexlist = flex_insets
2165 flexlist = flex_elements
2167 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
2170 i = find_token(document.body, "\\begin_inset Flex", i)
2173 m = rx.match(document.body[i])
2175 document.warning("Illegal flex inset: " + document.body[i])
2182 document.body[i] = "\\begin_inset Flex " + f[1]
2188 def convert_mathdots(document):
2189 " Load mathdots automatically "
2191 i = find_token(document.header, "\\use_esint" , 0)
2193 document.header.insert(i + 1, "\\use_mathdots 1")
2197 def revert_mathdots(document):
2198 " Load mathdots if used in the document "
2200 ddots = re.compile(r'\\begin_inset Formula .*\\ddots', re.DOTALL)
2201 vdots = re.compile(r'\\begin_inset Formula .*\\vdots', re.DOTALL)
2202 iddots = re.compile(r'\\begin_inset Formula .*\\iddots', re.DOTALL)
2203 mathdots = find_token(document.header, "\\use_mathdots" , 0)
2204 no = find_token(document.header, "\\use_mathdots 0" , 0)
2205 auto = find_token(document.header, "\\use_mathdots 1" , 0)
2206 yes = find_token(document.header, "\\use_mathdots 2" , 0)
2208 del document.header[mathdots]
2210 i = find_token(document.body, '\\begin_inset Formula', i)
2213 j = find_end_of_inset(document.body, i)
2215 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2217 k = ddots.search("\n".join(document.body[i:j]))
2218 l = vdots.search("\n".join(document.body[i:j]))
2219 m = iddots.search("\n".join(document.body[i:j]))
2220 if (yes == -1) and ((no != -1) or (not k and not l and not m) or (auto != -1 and not m)):
2223 # use \@ifundefined to catch also the "auto" case
2224 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2225 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}\n"])
2229 def convert_rule(document):
2230 " Convert \\lyxline to CommandInset line "
2233 i = find_token(document.body, "\\lyxline" , i)
2237 j = find_token(document.body, "\\color" , i - 2)
2239 color = document.body[j] + '\n'
2242 k = find_token(document.body, "\\begin_layout Standard" , i - 4)
2243 # we need to handle the case that \lyxline is in a separate paragraph and that it is colored
2244 # the result is then an extra empty paragraph which we get by adding an empty ERT inset
2245 if k == i - 4 and j == i - 2 and document.body[i - 1] == '':
2246 layout = '\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n\n\\end_layout\n\n\\end_inset\n' \
2247 + '\\end_layout\n\n' \
2248 + '\\begin_layout Standard\n'
2249 elif k == i - 2 and document.body[i - 1] == '':
2252 layout = '\\end_layout\n\n' \
2253 + '\\begin_layout Standard\n'
2254 l = find_token(document.body, "\\begin_layout Standard" , i + 4)
2255 if l == i + 4 and document.body[i + 1] == '':
2258 layout2 = '\\end_layout\n' \
2259 + '\n\\begin_layout Standard\n'
2261 + '\\noindent\n\n' \
2263 + '\\begin_inset CommandInset line\n' \
2264 + 'LatexCommand rule\n' \
2265 + 'offset "0.5ex"\n' \
2266 + 'width "100line%"\n' \
2267 + 'height "1pt"\n' \
2268 + '\n\\end_inset\n\n\n' \
2270 document.body[i] = subst
2274 def revert_rule(document):
2275 " Revert line insets to Tex code "
2278 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
2282 j = find_token(document.body, "\\end_inset" , i)
2283 # assure we found the end_inset of the current inset
2284 if j > i + 6 or j == -1:
2285 document.warning("Malformed LyX document: Can't find end of line inset.")
2287 # determine the optional offset
2288 k = find_token(document.body, 'offset', i, j)
2290 offset = document.body[k][8:-1]
2293 # determine the width
2294 l = find_token(document.body, 'width', i, j)
2296 width = document.body[l][7:-1]
2299 # determine the height
2300 m = find_token(document.body, 'height', i, j)
2302 height = document.body[m][8:-1]
2305 # output the \rule command
2307 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
2309 subst = "\\rule{" + width + "}{" + height + "}"
2310 document.body[i:j + 1] = put_cmd_in_ert(subst)
2314 def revert_diagram(document):
2315 " Add the feyn package if \\Diagram is used in math "
2317 re_diagram = re.compile(r'\\begin_inset Formula .*\\Diagram', re.DOTALL)
2319 i = find_token(document.body, '\\begin_inset Formula', i)
2322 j = find_end_of_inset(document.body, i)
2324 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2326 m = re_diagram.search("\n".join(document.body[i:j]))
2330 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2331 add_to_preamble(document, "\\usepackage{feyn}")
2332 # only need to do it once!
2336 def convert_bibtex_clearpage(document):
2337 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2339 i = find_token(document.header, '\\papersides', 0)
2341 document.warning("Malformed LyX document: Can't find papersides definition.")
2343 sides = int(document.header[i][12])
2347 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2351 k = find_end_of_inset(document.body, j)
2353 document.warning("Can't find end of Bibliography inset at line " + str(j))
2357 # only act if there is the option "bibtotoc"
2358 m = find_token(document.body, 'options', j, k)
2360 document.warning("Can't find options for bibliography inset at line " + str(j))
2364 optline = document.body[m]
2365 idx = optline.find("bibtotoc")
2370 # so we want to insert a new page right before the paragraph that
2371 # this bibliography thing is in. we'll look for it backwards.
2374 if document.body[lay].startswith("\\begin_layout"):
2379 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2383 subst1 = '\\begin_layout Standard\n' \
2384 + '\\begin_inset Newpage clearpage\n' \
2385 + '\\end_inset\n\n\n' \
2387 subst2 = '\\begin_layout Standard\n' \
2388 + '\\begin_inset Newpage cleardoublepage\n' \
2389 + '\\end_inset\n\n\n' \
2392 document.body.insert(lay, subst1)
2393 document.warning(subst1)
2395 document.body.insert(lay, subst2)
2396 document.warning(subst2)
2405 supported_versions = ["2.0.0","2.0"]
2406 convert = [[346, []],
2412 [352, [convert_splitindex]],
2419 [359, [convert_nomencl_width]],
2429 [369, [convert_author_id]],
2433 [373, [merge_gbrief]],
2439 [379, [convert_math_output]],
2449 [389, [convert_html_quotes]],
2453 [393, [convert_optarg]],
2454 [394, [convert_use_makebox]],
2457 [397, [remove_Nameref]],
2459 [399, [convert_mathdots]],
2460 [400, [convert_rule]],
2462 [402, [convert_bibtex_clearpage]],
2463 [403, [convert_flexnames]],
2464 [404, [convert_prettyref]]
2467 revert = [[403, [revert_refstyle]],
2468 [402, [revert_flexnames]],
2470 [400, [revert_diagram]],
2471 [399, [revert_rule]],
2472 [398, [revert_mathdots]],
2473 [397, [revert_mathrsfs]],
2475 [395, [revert_nameref]],
2476 [394, [revert_DIN_C_pagesizes]],
2477 [393, [revert_makebox]],
2478 [392, [revert_argument]],
2479 [391, [revert_beamer_args]],
2480 [390, [revert_align_decimal, revert_IEEEtran]],
2481 [389, [revert_output_sync]],
2482 [388, [revert_html_quotes]],
2483 [387, [revert_pagesizes]],
2484 [386, [revert_math_scale]],
2485 [385, [revert_lyx_version]],
2486 [384, [revert_shadedboxcolor]],
2487 [383, [revert_fontcolor]],
2488 [382, [revert_turkmen]],
2489 [381, [revert_notefontcolor]],
2490 [380, [revert_equalspacing_xymatrix]],
2491 [379, [revert_inset_preview]],
2492 [378, [revert_math_output]],
2494 [376, [revert_multirow]],
2495 [375, [revert_includeall]],
2496 [374, [revert_includeonly]],
2497 [373, [revert_html_options]],
2498 [372, [revert_gbrief]],
2499 [371, [revert_fontenc]],
2500 [370, [revert_mhchem]],
2501 [369, [revert_suppress_date]],
2502 [368, [revert_author_id]],
2503 [367, [revert_hspace_glue_lengths]],
2504 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2505 [365, [revert_percent_skip_lengths]],
2506 [364, [revert_paragraph_indentation]],
2507 [363, [revert_branch_filename]],
2508 [362, [revert_longtable_align]],
2509 [361, [revert_applemac]],
2511 [359, [revert_nomencl_cwidth]],
2512 [358, [revert_nomencl_width]],
2513 [357, [revert_custom_processors]],
2514 [356, [revert_ulinelatex]],
2516 [354, [revert_strikeout]],
2517 [353, [revert_printindexall]],
2518 [352, [revert_subindex]],
2519 [351, [revert_splitindex]],
2520 [350, [revert_backgroundcolor]],
2521 [349, [revert_outputformat]],
2522 [348, [revert_xetex]],
2523 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2524 [346, [revert_tabularvalign]],
2525 [345, [revert_swiss]]
2529 if __name__ == "__main__":