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 def find_end_of_layout(lines, i):
44 " Find end of layout, where lines[i] is included."
45 return find_end_of(lines, i, "\\begin_layout", "\\end_layout")
48 # Note that text can be either a list of lines or a single line.
49 def add_to_preamble(document, text):
50 """ Add text to the preamble if it is not already there.
51 Only the first line is checked!"""
53 if not type(text) is list:
54 # split on \n just in case
55 # it'll give us the one element list we want
56 # if there's no \n, too
57 text = text.split('\n')
59 if find_token(document.preamble, text[0], 0) != -1:
62 document.preamble.extend(text)
65 def insert_to_preamble(index, document, text):
66 """ Insert text to the preamble at a given line"""
68 document.preamble.insert(index, text)
71 def read_unicodesymbols():
72 " Read the unicodesymbols list of unicode characters and corresponding commands."
73 pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
74 fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
76 # Two backslashes, followed by some non-word character, and then a character
77 # in brackets. The idea is to check for constructs like: \"{u}, which is how
78 # they are written in the unicodesymbols file; but they can also be written
79 # as: \"u or even \" u.
80 r = re.compile(r'\\\\(\W)\{(\w)\}')
81 for line in fp.readlines():
82 if line[0] != '#' and line.strip() != "":
83 line=line.replace(' "',' ') # remove all quotation marks with spaces before
84 line=line.replace('" ',' ') # remove all quotation marks with spaces after
85 line=line.replace(r'\"','"') # replace \" by " (for characters with diaeresis)
87 [ucs4,command,dead] = line.split(None,2)
88 if command[0:1] != "\\":
90 spec_chars.append([command, unichr(eval(ucs4))])
96 # If the character is a double-quote, then we need to escape it, too,
97 # since it is done that way in the LyX file.
98 if m.group(1) == "\"":
101 command += m.group(1) + m.group(2)
102 commandbl += m.group(1) + ' ' + m.group(2)
103 spec_chars.append([command, unichr(eval(ucs4))])
104 spec_chars.append([commandbl, unichr(eval(ucs4))])
109 unicode_reps = read_unicodesymbols()
112 # DO NOT USE THIS ROUTINE ANY MORE. Better yet, replace the uses that
113 # have been made of it with uses of put_cmd_in_ert.
114 def old_put_cmd_in_ert(string):
115 for rep in unicode_reps:
116 string = string.replace(rep[1], rep[0].replace('\\\\', '\\'))
117 string = string.replace('\\', "\\backslash\n")
118 string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n" \
119 + string + "\n\\end_layout\n\\end_inset"
123 # This routine wraps some content in an ERT inset.
125 # NOTE: The function accepts either a single string or a LIST of strings as
126 # argument. But it returns a LIST of strings, split on \n, so that it does
127 # not have embedded newlines.
129 # This is how lyx2lyx represents a LyX document: as a list of strings,
130 # each representing a line of a LyX file. Embedded newlines confuse
133 # A call to this routine will often go something like this:
134 # i = find_token('\\begin_inset FunkyInset', ...)
136 # j = find_end_of_inset(document.body, i)
137 # content = ...extract content from insets
138 # # that could be as simple as:
139 # # content = lyx2latex(document[i:j + 1])
140 # ert = put_cmd_in_ert(content)
141 # document.body[i:j] = ert
142 # Now, before we continue, we need to reset i appropriately. Normally,
145 # That puts us right after the ERT we just inserted.
147 def put_cmd_in_ert(arg):
148 ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
149 # Despite the warnings just given, it will be faster for us to work
150 # with a single string internally. That way, we only go through the
151 # unicode_reps loop once.
152 if type(arg) is list:
156 for rep in unicode_reps:
157 s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
158 s = s.replace('\\', "\\backslash\n")
159 ret += s.splitlines()
160 ret += ["\\end_layout", "\\end_inset"]
164 def lyx2latex(document, lines):
165 'Convert some LyX stuff into corresponding LaTeX stuff, as best we can.'
166 # clean up multiline stuff
172 for curline in range(len(lines)):
173 line = lines[curline]
174 if line.startswith("\\begin_inset Note Note"):
175 # We want to skip LyX notes, so remember where the inset ends
176 note_end = find_end_of_inset(lines, curline + 1)
178 elif note_end >= curline:
181 elif line.startswith("\\begin_inset ERT"):
182 # We don't want to replace things inside ERT, so figure out
183 # where the end of the inset is.
184 ert_end = find_end_of_inset(lines, curline + 1)
186 elif line.startswith("\\begin_inset Formula"):
188 elif line.startswith("\\begin_inset Quotes"):
189 # For now, we do a very basic reversion. Someone who understands
190 # quotes is welcome to fix it up.
191 qtype = line[20:].strip()
205 elif line.startswith("\\begin_inset space"):
206 line = line[18:].strip()
207 if line.startswith("\\hspace"):
208 # Account for both \hspace and \hspace*
211 elif line == "\\space{}":
213 elif line == "\\thinspace{}":
216 # The LyX length is in line[8:], after the \length keyword
217 length = latex_length(line[8:])[1]
218 line = hspace + "{" + length + "}"
220 elif line.isspace() or \
221 line.startswith("\\begin_layout") or \
222 line.startswith("\\end_layout") or \
223 line.startswith("\\begin_inset") or \
224 line.startswith("\\end_inset") or \
225 line.startswith("\\lang") or \
226 line.strip() == "status collapsed" or \
227 line.strip() == "status open":
231 # this needs to be added to the preamble because of cases like
232 # \textmu, \textbackslash, etc.
233 add_to_preamble(document, ['% added by lyx2lyx for converted index entries',
234 '\\@ifundefined{textmu}',
235 ' {\\usepackage{textcomp}}{}'])
236 # a lossless reversion is not possible
237 # try at least to handle some common insets and settings
238 if ert_end >= curline:
239 line = line.replace(r'\backslash', '\\')
241 # No need to add "{}" after single-nonletter macros
242 line = line.replace('&', '\\&')
243 line = line.replace('#', '\\#')
244 line = line.replace('^', '\\textasciicircum{}')
245 line = line.replace('%', '\\%')
246 line = line.replace('_', '\\_')
247 line = line.replace('$', '\\$')
249 # Do the LyX text --> LaTeX conversion
250 for rep in unicode_reps:
251 line = line.replace(rep[1], rep[0] + "{}")
252 line = line.replace(r'\backslash', r'\textbackslash{}')
253 line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}')
254 line = line.replace(r'\shape italic', r'\itshape{}').replace(r'\shape smallcaps', r'\scshape{}')
255 line = line.replace(r'\shape slanted', r'\slshape{}').replace(r'\shape default', r'\upshape{}')
256 line = line.replace(r'\emph on', r'\em{}').replace(r'\emph default', r'\em{}')
257 line = line.replace(r'\noun on', r'\scshape{}').replace(r'\noun default', r'\upshape{}')
258 line = line.replace(r'\bar under', r'\underbar{').replace(r'\bar default', r'}')
259 line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}')
260 line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}')
261 line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'')
266 def latex_length(slen):
268 Convert lengths to their LaTeX representation. Returns (bool, length),
269 where the bool tells us if it was a percentage, and the length is the
270 LaTeX representation.
274 # the slen has the form
275 # ValueUnit+ValueUnit-ValueUnit or
276 # ValueUnit+-ValueUnit
277 # the + and - (glue lengths) are optional
278 # the + always precedes the -
280 # Convert relative lengths to LaTeX units
281 units = {"text%":"\\textwidth", "col%":"\\columnwidth",
282 "page%":"\\paperwidth", "line%":"\\linewidth",
283 "theight%":"\\textheight", "pheight%":"\\paperheight"}
284 for unit in units.keys():
289 minus = slen.rfind("-", 1, i)
290 plus = slen.rfind("+", 0, i)
291 latex_unit = units[unit]
292 if plus == -1 and minus == -1:
294 value = str(float(value)/100)
295 end = slen[i + len(unit):]
296 slen = value + latex_unit + end
298 value = slen[plus + 1:i]
299 value = str(float(value)/100)
300 begin = slen[:plus + 1]
301 end = slen[i+len(unit):]
302 slen = begin + value + latex_unit + end
304 value = slen[minus + 1:i]
305 value = str(float(value)/100)
306 begin = slen[:minus + 1]
307 slen = begin + value + latex_unit
309 # replace + and -, but only if the - is not the first character
310 slen = slen[0] + slen[1:].replace("+", " plus ").replace("-", " minus ")
311 # handle the case where "+-1mm" was used, because LaTeX only understands
312 # "plus 1mm minus 1mm"
313 if slen.find("plus minus"):
314 lastvaluepos = slen.rfind(" ")
315 lastvalue = slen[lastvaluepos:]
316 slen = slen.replace(" ", lastvalue + " ")
317 return (percent, slen)
320 def revert_flex_inset(document, name, LaTeXname, position):
321 " Convert flex insets to TeX code "
324 i = find_token(document.body, '\\begin_inset Flex ' + name, i)
327 z = find_end_of_inset(document.body, i)
329 document.warning("Malformed LyX document: Can't find end of Flex " + name + " inset.")
331 # remove the \end_inset
332 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
333 # we need to reset character layouts if necessary
334 j = find_token(document.body, '\\emph on', i, z)
335 k = find_token(document.body, '\\noun on', i, z)
336 l = find_token(document.body, '\\series', i, z)
337 m = find_token(document.body, '\\family', i, z)
338 n = find_token(document.body, '\\shape', i, z)
339 o = find_token(document.body, '\\color', i, z)
340 p = find_token(document.body, '\\size', i, z)
341 q = find_token(document.body, '\\bar under', i, z)
342 r = find_token(document.body, '\\uuline on', i, z)
343 s = find_token(document.body, '\\uwave on', i, z)
344 t = find_token(document.body, '\\strikeout on', i, z)
346 document.body.insert(z - 2, "\\emph default")
348 document.body.insert(z - 2, "\\noun default")
350 document.body.insert(z - 2, "\\series default")
352 document.body.insert(z - 2, "\\family default")
354 document.body.insert(z - 2, "\\shape default")
356 document.body.insert(z - 2, "\\color inherit")
358 document.body.insert(z - 2, "\\size default")
360 document.body.insert(z - 2, "\\bar default")
362 document.body.insert(z - 2, "\\uuline default")
364 document.body.insert(z - 2, "\\uwave default")
366 document.body.insert(z - 2, "\\strikeout default")
367 document.body[i:i + 4] = put_cmd_in_ert(LaTeXname + "{")
371 def revert_font_attrs(document, name, LaTeXname):
372 " Reverts font changes to TeX code "
376 i = find_token(document.body, name + ' on', i)
379 j = find_token(document.body, name + ' default', i)
380 k = find_token(document.body, name + ' on', i + 1)
381 # if there is no default set, the style ends with the layout
382 # assure hereby that we found the correct layout end
383 if j != -1 and (j < k or k == -1):
384 document.body[j:j + 1] = put_cmd_in_ert("}")
386 j = find_token(document.body, '\\end_layout', i)
387 document.body[j:j] = put_cmd_in_ert("}")
388 document.body[i:i + 1] = put_cmd_in_ert(LaTeXname + "{")
393 def revert_layout_command(document, name, LaTeXname, position):
394 " Reverts a command from a layout to TeX code "
397 i = find_token(document.body, '\\begin_layout ' + name, i)
401 # find the next layout
404 j = find_token(document.body, '\\begin_layout', j)
405 l = len(document.body)
406 # if nothing was found it was the last layout of the document
408 document.body[l - 4:l - 4] = put_cmd_in_ert("}")
410 # exclude plain layout because this can be TeX code or another inset
411 elif document.body[j] != '\\begin_layout Plain Layout':
412 document.body[j - 2:j - 2] = put_cmd_in_ert("}")
416 document.body[i] = '\\begin_layout Standard'
417 document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{")
421 ###############################################################################
423 ### Conversion and reversion routines
425 ###############################################################################
427 def revert_swiss(document):
428 " Set language german-ch to ngerman "
430 if document.language == "german-ch":
431 document.language = "ngerman"
432 i = find_token(document.header, "\\language", 0)
434 document.header[i] = "\\language ngerman"
437 j = find_token(document.body, "\\lang german-ch", j)
440 document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
444 def revert_tabularvalign(document):
445 " Revert the tabular valign option "
448 i = find_token(document.body, "\\begin_inset Tabular", i)
451 end = find_end_of_inset(document.body, i)
453 document.warning("Can't find end of inset at line " + str(i))
456 fline = find_token(document.body, "<features", i, end)
458 document.warning("Can't find features for inset at line " + str(i))
461 p = document.body[fline].find("islongtable")
463 q = document.body[fline].find("tabularvalignment")
466 # This seems wrong: It removes everything after
467 # tabularvalignment, too.
468 document.body[fline] = document.body[fline][:q - 1] + '>'
473 tabularvalignment = 'c'
474 # which valignment is specified?
475 m = document.body[fline].find('tabularvalignment="top"')
477 tabularvalignment = 't'
478 m = document.body[fline].find('tabularvalignment="bottom"')
480 tabularvalignment = 'b'
481 # delete tabularvalignment
482 q = document.body[fline].find("tabularvalignment")
485 # This seems wrong: It removes everything after
486 # tabularvalignment, too.
487 document.body[fline] = document.body[fline][:q - 1] + '>'
489 # don't add a box when centered
490 if tabularvalignment == 'c':
493 subst = ['\\end_layout', '\\end_inset']
494 document.body[end:end] = subst # just inserts those lines
495 subst = ['\\begin_inset Box Frameless',
496 'position "' + tabularvalignment +'"',
501 # we don't know the width, assume 50%
505 'height_special "totalheight"',
508 '\\begin_layout Plain Layout']
509 document.body[i:i] = subst # this just inserts the array at i
510 # since there could be a tabular inside a tabular, we cannot
515 def revert_phantom_types(document, ptype, cmd):
516 " Reverts phantom to ERT "
519 i = find_token(document.body, "\\begin_inset Phantom " + ptype, i)
522 end = find_end_of_inset(document.body, i)
524 document.warning("Can't find end of inset at line " + str(i))
527 blay = find_token(document.body, "\\begin_layout Plain Layout", i, end)
529 document.warning("Can't find layout for inset at line " + str(i))
532 bend = find_token(document.body, "\\end_layout", blay, end)
534 document.warning("Malformed LyX document: Could not find end of Phantom inset's layout.")
537 substi = ["\\begin_inset ERT", "status collapsed", "",
538 "\\begin_layout Plain Layout", "", "", "\\backslash",
539 cmd + "{", "\\end_layout", "", "\\end_inset"]
540 substj = ["\\size default", "", "\\begin_inset ERT", "status collapsed", "",
541 "\\begin_layout Plain Layout", "", "}", "\\end_layout", "", "\\end_inset"]
542 # do the later one first so as not to mess up the numbering
543 document.body[bend:end + 1] = substj
544 document.body[i:blay + 1] = substi
545 i = end + len(substi) + len(substj) - (end - bend) - (blay - i) - 2
548 def revert_phantom(document):
549 revert_phantom_types(document, "Phantom", "phantom")
551 def revert_hphantom(document):
552 revert_phantom_types(document, "HPhantom", "hphantom")
554 def revert_vphantom(document):
555 revert_phantom_types(document, "VPhantom", "vphantom")
558 def revert_xetex(document):
559 " Reverts documents that use XeTeX "
560 i = find_token(document.header, '\\use_xetex', 0)
562 document.warning("Malformed LyX document: Missing \\use_xetex.")
564 if get_value(document.header, "\\use_xetex", i) == 'false':
565 del document.header[i]
567 del document.header[i]
568 # 1.) set doc encoding to utf8-plain
569 i = find_token(document.header, "\\inputencoding", 0)
571 document.warning("Malformed LyX document: Missing \\inputencoding.")
572 document.header[i] = "\\inputencoding utf8-plain"
573 # 2.) check font settings
574 l = find_token(document.header, "\\font_roman", 0)
576 document.warning("Malformed LyX document: Missing \\font_roman.")
577 line = document.header[l]
578 l = re.compile(r'\\font_roman (.*)$')
581 l = find_token(document.header, "\\font_sans", 0)
583 document.warning("Malformed LyX document: Missing \\font_sans.")
584 line = document.header[l]
585 l = re.compile(r'\\font_sans (.*)$')
588 l = find_token(document.header, "\\font_typewriter", 0)
590 document.warning("Malformed LyX document: Missing \\font_typewriter.")
591 line = document.header[l]
592 l = re.compile(r'\\font_typewriter (.*)$')
594 typewriter = m.group(1)
595 osf = get_value(document.header, '\\font_osf', 0) == "true"
596 sf_scale = float(get_value(document.header, '\\font_sf_scale', 0))
597 tt_scale = float(get_value(document.header, '\\font_tt_scale', 0))
598 # 3.) set preamble stuff
599 pretext = '%% This document must be processed with xelatex!\n'
600 pretext += '\\usepackage{fontspec}\n'
601 if roman != "default":
602 pretext += '\\setmainfont[Mapping=tex-text]{' + roman + '}\n'
603 if sans != "default":
604 pretext += '\\setsansfont['
606 pretext += 'Scale=' + str(sf_scale / 100) + ','
607 pretext += 'Mapping=tex-text]{' + sans + '}\n'
608 if typewriter != "default":
609 pretext += '\\setmonofont'
611 pretext += '[Scale=' + str(tt_scale / 100) + ']'
612 pretext += '{' + typewriter + '}\n'
614 pretext += '\\defaultfontfeatures{Numbers=OldStyle}\n'
615 pretext += '\usepackage{xunicode}\n'
616 pretext += '\usepackage{xltxtra}\n'
617 insert_to_preamble(0, document, pretext)
618 # 4.) reset font settings
619 i = find_token(document.header, "\\font_roman", 0)
621 document.warning("Malformed LyX document: Missing \\font_roman.")
622 document.header[i] = "\\font_roman default"
623 i = find_token(document.header, "\\font_sans", 0)
625 document.warning("Malformed LyX document: Missing \\font_sans.")
626 document.header[i] = "\\font_sans default"
627 i = find_token(document.header, "\\font_typewriter", 0)
629 document.warning("Malformed LyX document: Missing \\font_typewriter.")
630 document.header[i] = "\\font_typewriter default"
631 i = find_token(document.header, "\\font_osf", 0)
633 document.warning("Malformed LyX document: Missing \\font_osf.")
634 document.header[i] = "\\font_osf false"
635 i = find_token(document.header, "\\font_sc", 0)
637 document.warning("Malformed LyX document: Missing \\font_sc.")
638 document.header[i] = "\\font_sc false"
639 i = find_token(document.header, "\\font_sf_scale", 0)
641 document.warning("Malformed LyX document: Missing \\font_sf_scale.")
642 document.header[i] = "\\font_sf_scale 100"
643 i = find_token(document.header, "\\font_tt_scale", 0)
645 document.warning("Malformed LyX document: Missing \\font_tt_scale.")
646 document.header[i] = "\\font_tt_scale 100"
649 def revert_outputformat(document):
650 " Remove default output format param "
651 i = find_token(document.header, '\\default_output_format', 0)
653 document.warning("Malformed LyX document: Missing \\default_output_format.")
655 del document.header[i]
659 val = string.atoi(s, 16)
662 return str(val / 256.0)
665 def revert_backgroundcolor(document):
666 " Reverts background color to preamble code "
667 i = find_token(document.header, "\\backgroundcolor", 0)
670 colorcode = get_value(document.header, '\\backgroundcolor', i)
671 del document.header[i]
672 # don't clutter the preamble if backgroundcolor is not set
673 if colorcode == "#ffffff":
675 red = hex2ratio(colorcode[1:3])
676 green = hex2ratio(colorcode[3:5])
677 blue = hex2ratio(colorcode[5:7])
678 insert_to_preamble(0, document,
679 '% Commands inserted by lyx2lyx to set the background color\n'
680 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
681 + '\\definecolor{page_backgroundcolor}{rgb}{'
682 + red + ',' + green + ',' + blue + '}\n'
683 + '\\pagecolor{page_backgroundcolor}\n')
686 def revert_splitindex(document):
687 " Reverts splitindex-aware documents "
688 i = find_token(document.header, '\\use_indices', 0)
690 document.warning("Malformed LyX document: Missing \\use_indices.")
692 indices = get_value(document.header, "\\use_indices", i)
694 useindices = (indices == "true")
696 preamble += "\\usepackage{splitidx}\n"
697 del document.header[i]
699 # deal with index declarations in the preamble
702 i = find_token(document.header, "\\index", i)
705 k = find_token(document.header, "\\end_index", i)
707 document.warning("Malformed LyX document: Missing \\end_index.")
710 line = document.header[i]
711 l = re.compile(r'\\index (.*)$')
714 ishortcut = get_value(document.header, '\\shortcut', i, k)
716 preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
717 del document.header[i:k + 1]
719 insert_to_preamble(0, document, preamble)
721 # deal with index insets
722 # these need to have the argument removed
725 i = find_token(document.body, "\\begin_inset Index", i)
728 line = document.body[i]
729 l = re.compile(r'\\begin_inset Index (.*)$')
732 if itype == "idx" or indices == "false":
733 document.body[i] = "\\begin_inset Index"
735 k = find_end_of_inset(document.body, i)
737 document.warning("Can't find end of index inset!")
740 content = lyx2latex(document, document.body[i:k])
742 content = content.replace('"', r'\"')
743 subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
744 document.body[i:k + 1] = subst
747 # deal with index_print insets
750 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
753 k = find_end_of_inset(document.body, i)
754 ptype = get_value(document.body, 'type', i, k).strip('"')
756 j = find_token(document.body, "type", i, k)
759 del document.body[i:k + 1]
761 subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
762 document.body[i:k + 1] = subst
766 def convert_splitindex(document):
767 " Converts index and printindex insets to splitindex-aware format "
770 i = find_token(document.body, "\\begin_inset Index", i)
773 document.body[i] = document.body[i].replace("\\begin_inset Index",
774 "\\begin_inset Index idx")
778 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
781 if document.body[i + 1].find('LatexCommand printindex') == -1:
782 document.warning("Malformed LyX document: Incomplete printindex inset.")
784 subst = ["LatexCommand printindex",
786 document.body[i + 1:i + 2] = subst
790 def revert_subindex(document):
791 " Reverts \\printsubindex CommandInset types "
792 i = find_token(document.header, '\\use_indices', 0)
794 document.warning("Malformed LyX document: Missing \\use_indices.")
796 indices = get_value(document.header, "\\use_indices", i)
797 useindices = (indices == "true")
800 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
803 k = find_end_of_inset(document.body, i)
804 ctype = get_value(document.body, 'LatexCommand', i, k)
805 if ctype != "printsubindex":
808 ptype = get_value(document.body, 'type', i, k).strip('"')
810 del document.body[i:k + 1]
812 subst = put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")
813 document.body[i:k + 1] = subst
817 def revert_printindexall(document):
818 " Reverts \\print[sub]index* CommandInset types "
819 i = find_token(document.header, '\\use_indices', 0)
821 document.warning("Malformed LyX document: Missing \\use_indices.")
823 indices = get_value(document.header, "\\use_indices", i)
824 useindices = (indices == "true")
827 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
830 k = find_end_of_inset(document.body, i)
831 ctype = get_value(document.body, 'LatexCommand', i, k)
832 if ctype != "printindex*" and ctype != "printsubindex*":
836 del document.body[i:k + 1]
838 subst = put_cmd_in_ert("\\" + ctype + "{}")
839 document.body[i:k + 1] = subst
843 def revert_strikeout(document):
844 " Reverts \\strikeout font attribute "
845 changed = revert_font_attrs(document, "\\uuline", "\\uuline")
846 changed = revert_font_attrs(document, "\\uwave", "\\uwave") or changed
847 changed = revert_font_attrs(document, "\\strikeout", "\\sout") or changed
849 insert_to_preamble(0, document,
850 '% Commands inserted by lyx2lyx for proper underlining\n'
851 + '\\PassOptionsToPackage{normalem}{ulem}\n'
852 + '\\usepackage{ulem}\n')
855 def revert_ulinelatex(document):
856 " Reverts \\uline font attribute "
857 i = find_token(document.body, '\\bar under', 0)
860 insert_to_preamble(0, document,
861 '% Commands inserted by lyx2lyx for proper underlining\n'
862 + '\\PassOptionsToPackage{normalem}{ulem}\n'
863 + '\\usepackage{ulem}\n'
864 + '\\let\\cite@rig\\cite\n'
865 + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n'
866 + ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n'
867 + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n')
870 def revert_custom_processors(document):
871 " Remove bibtex_command and index_command params "
872 i = find_token(document.header, '\\bibtex_command', 0)
874 document.warning("Malformed LyX document: Missing \\bibtex_command.")
876 del document.header[i]
877 i = find_token(document.header, '\\index_command', 0)
879 document.warning("Malformed LyX document: Missing \\index_command.")
881 del document.header[i]
884 def convert_nomencl_width(document):
885 " Add set_width param to nomencl_print "
888 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
891 document.body.insert(i + 2, "set_width \"none\"")
895 def revert_nomencl_width(document):
896 " Remove set_width param from nomencl_print "
899 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
902 j = find_end_of_inset(document.body, i)
903 l = find_token(document.body, "set_width", i, j)
905 document.warning("Can't find set_width option for nomencl_print!")
912 def revert_nomencl_cwidth(document):
913 " Remove width param from nomencl_print "
916 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
919 j = find_end_of_inset(document.body, i)
920 l = find_token(document.body, "width", i, j)
922 document.warning("Can't find width option for nomencl_print!")
925 width = get_value(document.body, "width", i, j).strip('"')
927 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
928 add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
932 def revert_applemac(document):
933 " Revert applemac encoding to auto "
934 if document.encoding != "applemac":
936 document.encoding = "auto"
937 i = find_token(document.header, "\\encoding", 0)
939 document.header[i] = "\\encoding auto"
942 def revert_longtable_align(document):
943 " Remove longtable alignment setting "
946 i = find_token(document.body, "\\begin_inset Tabular", i)
949 end = find_end_of_inset(document.body, i)
951 document.warning("Can't find end of inset at line " + str(i))
954 fline = find_token(document.body, "<features", i, end)
956 document.warning("Can't find features for inset at line " + str(i))
959 j = document.body[fline].find("longtabularalignment")
963 # FIXME Is this correct? It wipes out everything after the
965 document.body[fline] = document.body[fline][:j - 1] + '>'
966 # since there could be a tabular inside this one, we
967 # cannot jump to end.
971 def revert_branch_filename(document):
972 " Remove \\filename_suffix parameter from branches "
975 i = find_token(document.header, "\\filename_suffix", i)
978 del document.header[i]
981 def revert_paragraph_indentation(document):
982 " Revert custom paragraph indentation to preamble code "
983 i = find_token(document.header, "\\paragraph_indentation", 0)
986 length = get_value(document.header, "\\paragraph_indentation", i)
987 # we need only remove the line if indentation is default
988 if length != "default":
989 # handle percent lengths
990 length = latex_length(length)[1]
991 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
992 add_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
993 del document.header[i]
996 def revert_percent_skip_lengths(document):
997 " Revert relative lengths for paragraph skip separation to preamble code "
998 i = find_token(document.header, "\\defskip", 0)
1001 length = get_value(document.header, "\\defskip", i)
1002 # only revert when a custom length was set and when
1003 # it used a percent length
1004 if length in ('smallskip', 'medskip', 'bigskip'):
1006 # handle percent lengths
1007 percent, length = latex_length(length)
1008 if percent == "True":
1009 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1010 add_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
1011 # set defskip to medskip as default
1012 document.header[i] = "\\defskip medskip"
1015 def revert_percent_vspace_lengths(document):
1016 " Revert relative VSpace lengths to ERT "
1019 i = find_token(document.body, "\\begin_inset VSpace", i)
1022 # only revert if a custom length was set and if
1023 # it used a percent length
1024 r = re.compile(r'\\begin_inset VSpace (.*)$')
1025 m = r.match(document.body[i])
1027 if length in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
1030 # check if the space has a star (protected space)
1031 protected = (document.body[i].rfind("*") != -1)
1033 length = length.rstrip('*')
1034 # handle percent lengths
1035 percent, length = latex_length(length)
1036 # revert the VSpace inset to ERT
1037 if percent == "True":
1039 subst = put_cmd_in_ert("\\vspace*{" + length + "}")
1041 subst = put_cmd_in_ert("\\vspace{" + length + "}")
1042 document.body[i:i + 2] = subst
1046 def revert_percent_hspace_lengths(document):
1047 " Revert relative HSpace lengths to ERT "
1050 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1053 j = find_end_of_inset(document.body, i)
1055 document.warning("Can't find end of inset at line " + str(i))
1058 # only revert if a custom length was set...
1059 length = get_value(document.body, '\\length', i + 1, j)
1061 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1065 if document.body[i].find("\\hspace*{}") != -1:
1067 # ...and if it used a percent length
1068 percent, length = latex_length(length)
1069 # revert the HSpace inset to ERT
1070 if percent == "True":
1071 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
1072 document.body[i:j + 1] = subst
1073 # if we did a substitution, this will still be ok
1077 def revert_hspace_glue_lengths(document):
1078 " Revert HSpace glue lengths to ERT "
1081 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1084 j = find_end_of_inset(document.body, i)
1086 document.warning("Can't find end of inset at line " + str(i))
1089 length = get_value(document.body, '\\length', i + 1, j)
1091 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1095 if document.body[i].find("\\hspace*{}") != -1:
1097 # only revert if the length contains a plus or minus at pos != 0
1098 if length.find('-',1) != -1 or length.find('+',1) != -1:
1099 # handle percent lengths
1100 length = latex_length(length)[1]
1101 # revert the HSpace inset to ERT
1102 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
1103 document.body[i:j+1] = subst
1107 def convert_author_id(document):
1108 " Add the author_id to the \\author definition and make sure 0 is not used"
1111 re_author = re.compile(r'(\\author) (\".*\")\s*(.*)$')
1114 i = find_token(document.header, "\\author", i)
1117 m = re_author.match(document.header[i])
1121 document.header[i] = "\\author %i %s %s" % (anum, name, email)
1122 # FIXME Should this really be incremented if we didn't match?
1128 i = find_token(document.body, "\\change_", i)
1131 change = document.body[i].split(' ');
1132 if len(change) == 3:
1134 author_id = int(change[1])
1136 document.body[i] = "%s %i %s" % (type, author_id + 1, time)
1140 def revert_author_id(document):
1141 " Remove the author_id from the \\author definition "
1144 rx = re.compile(r'(\\author)\s+(\d+)\s+(\".*\")\s*(.*)$')
1148 i = find_token(document.header, "\\author", i)
1151 m = rx.match(document.header[i])
1153 author_id = int(m.group(2))
1154 idmap[author_id] = anum
1157 document.header[i] = "\\author %s %s" % (name, email)
1159 # FIXME Should this be incremented if we didn't match?
1164 i = find_token(document.body, "\\change_", i)
1167 change = document.body[i].split(' ');
1168 if len(change) == 3:
1170 author_id = int(change[1])
1172 document.body[i] = "%s %i %s" % (type, idmap[author_id], time)
1176 def revert_suppress_date(document):
1177 " Revert suppressing of default document date to preamble code "
1178 i = find_token(document.header, "\\suppress_date", 0)
1181 # remove the preamble line and write to the preamble
1182 # when suppress_date was true
1183 date = get_value(document.header, "\\suppress_date", i)
1185 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1186 add_to_preamble(document, ["\\date{}"])
1187 del document.header[i]
1190 def revert_mhchem(document):
1191 "Revert mhchem loading to preamble code"
1194 i = find_token(document.header, "\\use_mhchem", 0)
1196 document.warning("Malformed LyX document: Could not find mhchem setting.")
1199 val = get_value(document.header, "\\use_mhchem", i)
1204 del document.header[i]
1206 if mhchem == "auto":
1209 i = find_token(document.body, "\\begin_inset Formula", i)
1212 line = document.body[i]
1213 if line.find("\\ce{") != -1 or line.find("\\cf{") != 1:
1219 pre = ["% lyx2lyx mhchem commands",
1220 "\\PassOptionsToPackage{version=3}{mhchem}",
1221 "\\usepackage{mhchem}"]
1222 add_to_preamble(document, pre)
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 document.warning("Unable to find end of includeonly section!!")
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 # FIXME Are we sure these always have space around them?
1331 document.body[i] = document.body[i].replace(' multirow="3" ', ' ')
1332 document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
1333 document.body[i] = document.body[i].replace(' bottomline="true" ', ' ')
1334 # write ERT to create the multirow cell
1335 # use 2 rows and 2cm as default with because the multirow span
1336 # and the column width is only hardly accessible
1337 cend = find_token(document.body, "</cell>", i)
1339 document.warning("Malformed LyX document: Could not find end of tabular cell.")
1342 blay = find_token(document.body, "\\begin_layout", i, cend)
1344 document.warning("Can't find layout for cell!")
1347 bend = find_end_of_layout(document.body, blay)
1349 document.warning("Can't find end of layout for cell!")
1353 # do the later one first, so as not to mess up the numbering
1354 # we are wrapping the whole cell in this ert
1355 # so before the end of the layout...
1356 document.body[bend:bend] = put_cmd_in_ert("}")
1357 # ...and after the beginning
1358 document.body[blay+1:blay+1] = put_cmd_in_ert("\\multirow{2}{2cm}{")
1361 # cell type 4 is multirow part cell
1362 k = find_token(document.body, '<cell multirow="4"', cend)
1365 # remove the multirow tag, set the valignment to top
1366 # and remove the top line
1367 # FIXME Are we sure these always have space around them?
1368 document.body[k] = document.body[k].replace(' multirow="4" ', ' ')
1369 document.body[k] = document.body[k].replace('valignment="middle"', 'valignment="top"')
1370 document.body[k] = document.body[k].replace(' topline="true" ', ' ')
1372 # this will always be ok
1375 if multirow == True:
1376 add_to_preamble(document,
1377 ["% lyx2lyx multirow additions ", "\\usepackage{multirow}"])
1380 def convert_math_output(document):
1381 " Convert \html_use_mathml to \html_math_output "
1382 i = find_token(document.header, "\\html_use_mathml", 0)
1385 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1386 m = rgx.match(document.header[i])
1387 newval = "0" # MathML
1391 newval = "2" # Images
1393 document.warning("Can't match " + document.header[i])
1394 document.header[i] = "\\html_math_output " + newval
1397 def revert_math_output(document):
1398 " Revert \html_math_output to \html_use_mathml "
1399 i = find_token(document.header, "\\html_math_output", 0)
1402 rgx = re.compile(r'\\html_math_output\s+(\d)')
1403 m = rgx.match(document.header[i])
1407 if val == "1" or val == "2":
1410 document.warning("Unable to match " + document.header[i])
1411 document.header[i] = "\\html_use_mathml " + newval
1415 def revert_inset_preview(document):
1416 " Dissolves the preview inset "
1419 i = find_token(document.body, "\\begin_inset Preview", i)
1422 iend = find_end_of_inset(document.body, i)
1424 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1428 del document.body[iend]
1429 del document.body[i]
1431 # This does not work. The problem is that the last layout may not be
1432 # standard, in which case the material following the preview, which
1433 # might be in this same paragraph, will now be in whatever that was.
1434 # Moreover, the right action might depend upon what layout we are in,
1435 # and that is not easy to find out. It is much harder to fix that kind
1436 # of problem than to remove a paragraph break.
1437 # So I am disabling all of this for now, at least. If someone wants to
1438 # fix it, then feel free.
1440 ## If the first layout is Standard we need to remove it, otherwise there
1441 ## will be paragraph breaks that shouldn't be there.
1442 #blay = find_token(document.body, "\\begin_layout", i, iend)
1444 #document.warning("Can't find layout for preview inset!")
1445 ## always do the later one first...
1446 #del document.body[iend]
1447 #del document.body[i]
1448 ## deletions mean we do not need to reset i
1450 #lay = document.body[blay].split(None, 1)[1]
1451 #if lay != "Standard":
1452 #del document.body[iend]
1453 #del document.body[i]
1454 ## deletions mean we do not need to reset i
1457 ## we want to delete the last \\end_layout in this inset, too.
1458 ## note that this may not be the \\end_layout that goes with blay!!
1459 #bend = find_end_of_layout(document.body, blay)
1461 ##tmp = find_token(document.body, "\\end_layout", bend + 1, iend)
1467 #document.warning("Unable to find last layout in preview inset!")
1468 #del document.body[iend]
1469 #del document.body[i]
1470 ## deletions mean we do not need to reset i
1472 ## always do the later one first...
1474 #del document.body[bend]
1475 #del document.body[i:blay + 1]
1476 # we do not need to reset i
1479 def revert_equalspacing_xymatrix(document):
1480 " Revert a Formula with xymatrix@! to an ERT inset "
1482 has_preamble = False
1483 has_equal_spacing = False
1486 i = find_token(document.body, "\\begin_inset Formula", i)
1489 j = find_end_of_inset(document.body, i)
1491 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1495 for curline in range(i,j):
1496 found = document.body[curline].find("\\xymatrix@!")
1501 has_equal_spacing = True
1502 content = [document.body[i][21:]]
1503 content += document.body[i + 1:j]
1504 subst = put_cmd_in_ert(content)
1505 document.body[i:j + 1] = subst
1506 i += len(subst) - (j - i) + 1
1508 for curline in range(i,j):
1509 l = document.body[curline].find("\\xymatrix")
1511 has_preamble = True;
1515 if has_equal_spacing and not has_preamble:
1516 add_to_preamble(document, ['% lyx2lyx xymatrix addition', '\\usepackage[all]{xy}'])
1519 def revert_notefontcolor(document):
1520 " Reverts greyed-out note font color to preamble code "
1524 i = find_token(document.header, "\\notefontcolor", i)
1527 colorcode = get_value(document.header, '\\notefontcolor', 0)
1528 del document.header[i]
1529 # the color code is in the form #rrggbb where every character denotes a hex number
1530 # convert the string to an int
1531 red = string.atoi(colorcode[1:3],16)
1532 # we want the output "0.5" for the value "127" therefore increment here
1535 redout = float(red) / 256
1536 green = string.atoi(colorcode[3:5],16)
1539 greenout = float(green) / 256
1540 blue = string.atoi(colorcode[5:7],16)
1543 blueout = float(blue) / 256
1544 # write the preamble
1545 insert_to_preamble(0, document,
1546 '% Commands inserted by lyx2lyx to set the font color\n'
1547 '% for greyed-out notes\n'
1548 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1549 + '\\definecolor{note_fontcolor}{rgb}{'
1550 + str(redout) + ', ' + str(greenout)
1551 + ', ' + str(blueout) + '}\n'
1552 + '\\renewenvironment{lyxgreyedout}\n'
1553 + ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n')
1556 def revert_turkmen(document):
1557 "Set language Turkmen to English"
1559 if document.language == "turkmen":
1560 document.language = "english"
1561 i = find_token(document.header, "\\language", 0)
1563 document.header[i] = "\\language english"
1566 j = find_token(document.body, "\\lang turkmen", j)
1569 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1573 def revert_fontcolor(document):
1574 " Reverts font color to preamble code "
1578 i = find_token(document.header, "\\fontcolor", i)
1581 colorcode = get_value(document.header, '\\fontcolor', 0)
1582 del document.header[i]
1583 # don't clutter the preamble if backgroundcolor is not set
1584 if colorcode == "#000000":
1586 # the color code is in the form #rrggbb where every character denotes a hex number
1587 # convert the string to an int
1588 red = string.atoi(colorcode[1:3],16)
1589 # we want the output "0.5" for the value "127" therefore add here
1592 redout = float(red) / 256
1593 green = string.atoi(colorcode[3:5],16)
1596 greenout = float(green) / 256
1597 blue = string.atoi(colorcode[5:7],16)
1600 blueout = float(blue) / 256
1601 # write the preamble
1602 insert_to_preamble(0, document,
1603 '% Commands inserted by lyx2lyx to set the font color\n'
1604 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1605 + '\\definecolor{document_fontcolor}{rgb}{'
1606 + str(redout) + ', ' + str(greenout)
1607 + ', ' + str(blueout) + '}\n'
1608 + '\\color{document_fontcolor}\n')
1610 def revert_shadedboxcolor(document):
1611 " Reverts shaded box color to preamble code "
1615 i = find_token(document.header, "\\boxbgcolor", i)
1618 colorcode = get_value(document.header, '\\boxbgcolor', 0)
1619 del document.header[i]
1620 # the color code is in the form #rrggbb where every character denotes a hex number
1621 # convert the string to an int
1622 red = string.atoi(colorcode[1:3],16)
1623 # we want the output "0.5" for the value "127" therefore increment here
1626 redout = float(red) / 256
1627 green = string.atoi(colorcode[3:5],16)
1630 greenout = float(green) / 256
1631 blue = string.atoi(colorcode[5:7],16)
1634 blueout = float(blue) / 256
1635 # write the preamble
1636 insert_to_preamble(0, document,
1637 '% Commands inserted by lyx2lyx to set the color\n'
1638 '% of boxes with shaded background\n'
1639 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1640 + '\\definecolor{shadecolor}{rgb}{'
1641 + str(redout) + ', ' + str(greenout)
1642 + ', ' + str(blueout) + '}\n')
1645 def revert_lyx_version(document):
1646 " Reverts LyX Version information from Inset Info "
1647 version = "LyX version"
1649 import lyx2lyx_version
1650 version = lyx2lyx_version.version
1656 i = find_token(document.body, '\\begin_inset Info', i)
1659 j = find_end_of_inset(document.body, i + 1)
1662 document.warning("Malformed LyX document: Could not find end of Info inset.")
1668 # but we shall try to be forgiving.
1670 for k in range(i, j):
1671 if document.body[k].startswith("arg"):
1672 arg = document.body[k][3:].strip().strip('"')
1673 if document.body[k].startswith("type"):
1674 typ = document.body[k][4:].strip().strip('"')
1675 if arg != "version" or typ != "lyxinfo":
1679 # We do not actually know the version of LyX used to produce the document.
1680 # But we can use our version, since we are reverting.
1682 # Now we want to check if the line after "\end_inset" is empty. It normally
1683 # is, so we want to remove it, too.
1685 if document.body[j + 1].strip() == "":
1687 document.body[i: lastline] = s
1691 def revert_math_scale(document):
1692 " Remove math scaling and LaTeX options "
1693 i = find_token(document.header, '\\html_math_img_scale', 0)
1695 del document.header[i]
1696 i = find_token(document.header, '\\html_latex_start', 0)
1698 del document.header[i]
1699 i = find_token(document.header, '\\html_latex_end', 0)
1701 del document.header[i]
1704 def revert_pagesizes(document):
1706 " Revert page sizes to default "
1707 i = find_token(document.header, '\\papersize', 0)
1709 size = document.header[i][11:]
1710 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1711 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1712 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1713 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1714 or size == "b5j" or size == "b6j":
1715 del document.header[i]
1718 def revert_DIN_C_pagesizes(document):
1720 " Revert DIN C page sizes to default "
1721 i = find_token(document.header, '\\papersize', 0)
1723 size = document.header[i][11:]
1724 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1725 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1726 or size == "c6paper":
1727 del document.header[i]
1730 def convert_html_quotes(document):
1731 " Remove quotes around html_latex_start and html_latex_end "
1733 i = find_token(document.header, '\\html_latex_start', 0)
1735 line = document.header[i]
1736 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1739 document.header[i] = "\\html_latex_start " + m.group(1)
1741 i = find_token(document.header, '\\html_latex_end', 0)
1743 line = document.header[i]
1744 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1747 document.header[i] = "\\html_latex_end " + m.group(1)
1750 def revert_html_quotes(document):
1751 " Remove quotes around html_latex_start and html_latex_end "
1753 i = find_token(document.header, '\\html_latex_start', 0)
1755 line = document.header[i]
1756 l = re.compile(r'\\html_latex_start\s+(.*)')
1758 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1760 i = find_token(document.header, '\\html_latex_end', 0)
1762 line = document.header[i]
1763 l = re.compile(r'\\html_latex_end\s+(.*)')
1765 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1768 def revert_output_sync(document):
1769 " Remove forward search options "
1770 i = find_token(document.header, '\\output_sync_macro', 0)
1772 del document.header[i]
1773 i = find_token(document.header, '\\output_sync', 0)
1775 del document.header[i]
1778 def convert_beamer_args(document):
1779 " Convert ERT arguments in Beamer to InsetArguments "
1781 if document.textclass != "beamer" and document.textclass != "article-beamer":
1784 layouts = ("Block", "ExampleBlock", "AlertBlock")
1785 for layout in layouts:
1788 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1791 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1793 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1796 bert = find_token(document.body, '\\begin_inset ERT', blay)
1798 document.warning("Malformed Beamer LyX document: Can't find argument of " + layout + " layout.")
1801 eert = find_end_of_inset(document.body, bert)
1803 document.warning("Malformed LyX document: Can't find end of ERT.")
1807 # So the ERT inset begins at line k and goes to line l. We now wrap it in
1808 # an argument inset.
1809 # Do the end first, so as not to mess up the variables.
1810 document.body[eert + 1:eert + 1] = ['', '\\end_layout', '', '\\end_inset', '']
1811 document.body[bert:bert] = ['\\begin_inset OptArg', 'status open', '',
1812 '\\begin_layout Plain Layout']
1816 def revert_beamer_args(document):
1817 " Revert Beamer arguments to ERT "
1819 if document.textclass != "beamer" and document.textclass != "article-beamer":
1822 layouts = ("Block", "ExampleBlock", "AlertBlock")
1823 for layout in layouts:
1826 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1829 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1831 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1834 bopt = find_token(document.body, '\\begin_inset OptArg', blay)
1836 # it is legal not to have one of these
1839 eopt = find_end_of_inset(document.body, bopt)
1841 document.warning("Malformed LyX document: Can't find end of argument.")
1844 bplay = find_token(document.body, '\\begin_layout Plain Layout', blay)
1846 document.warning("Malformed LyX document: Can't find plain layout.")
1849 eplay = find_end_of(document.body, bplay, '\\begin_layout', '\\end_layout')
1851 document.warning("Malformed LyX document: Can't find end of plain layout.")
1854 # So the content of the argument inset goes from bplay + 1 to eplay - 1
1858 document.warning(str(bcont) + " " + str(eplay))
1861 # we convert the content of the argument into pure LaTeX...
1862 content = lyx2latex(document, document.body[bcont:eplay])
1863 strlist = put_cmd_in_ert(["{" + content + "}"])
1865 # now replace the optional argument with the ERT
1866 document.body[bopt:eopt + 1] = strlist
1870 def revert_align_decimal(document):
1873 l = document.body[l].find('alignment=decimal')
1876 remove_option(document, l, 'decimal_point')
1877 document.body[l].replace('decimal', 'center')
1880 def convert_optarg(document):
1881 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1884 i = find_token(document.body, '\\begin_inset OptArg', i)
1887 document.body[i] = "\\begin_inset Argument"
1891 def revert_argument(document):
1892 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1895 i = find_token(document.body, '\\begin_inset Argument', i)
1898 document.body[i] = "\\begin_inset OptArg"
1902 def revert_makebox(document):
1903 " Convert \\makebox to TeX code "
1906 # only revert frameless boxes without an inner box
1907 i = find_token(document.body, '\\begin_inset Box Frameless', i)
1909 # remove the option use_makebox
1910 revert_use_makebox(document)
1912 z = find_end_of_inset(document.body, i)
1914 document.warning("Malformed LyX document: Can't find end of box inset.")
1916 j = find_token(document.body, 'use_makebox 1', i)
1917 # assure we found the makebox of the current box
1918 if j < z and j != -1:
1919 y = find_token(document.body, "\\begin_layout", i)
1920 if y > z or y == -1:
1921 document.warning("Malformed LyX document: Can't find layout in box.")
1923 # remove the \end_layout \end_inset pair
1924 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
1925 # determine the alignment
1926 k = find_token(document.body, 'hor_pos', j - 4)
1927 align = document.body[k][9]
1928 # determine the width
1929 l = find_token(document.body, 'width "', j + 1)
1930 length = document.body[l][7:]
1931 # remove trailing '"'
1932 length = length[:-1]
1933 length = latex_length(length)[1]
1934 subst = "\\makebox[" + length + "][" \
1936 document.body[i:y + 1] = put_cmd_in_ert(subst)
1940 def revert_use_makebox(document):
1941 " Deletes use_makebox option of boxes "
1944 # remove the option use_makebox
1945 h = find_token(document.body, 'use_makebox', 0)
1948 del document.body[h]
1952 def convert_use_makebox(document):
1953 " Adds use_makebox option for boxes "
1956 # remove the option use_makebox
1957 i = find_token(document.body, '\\begin_inset Box', i)
1960 k = find_token(document.body, 'use_parbox', i)
1962 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1964 document.body.insert(k + 1, "use_makebox 0")
1968 def revert_IEEEtran(document):
1969 " Convert IEEEtran layouts and styles to TeX code "
1970 if document.textclass != "IEEEtran":
1972 revert_flex_inset(document, "IEEE membership", "\\IEEEmembership", 0)
1973 revert_flex_inset(document, "Lowercase", "\\MakeLowercase", 0)
1974 layouts = ("Special Paper Notice", "After Title Text", "Publication ID",
1975 "Page headings", "Biography without photo")
1976 latexcmd = {"Special Paper Notice": "\\IEEEspecialpapernotice",
1977 "After Title Text": "\\IEEEaftertitletext",
1978 "Publication ID": "\\IEEEpubid"}
1979 obsoletedby = {"Page headings": "MarkBoth",
1980 "Biography without photo": "BiographyNoPhoto"}
1981 for layout in layouts:
1984 i = find_token(document.body, '\\begin_layout ' + layout, i)
1987 j = find_end_of(document.body, i, '\\begin_layout', '\\end_layout')
1989 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1992 if layout in obsoletedby:
1993 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1996 content = lyx2latex(document, document.body[i:j + 1])
1997 add_to_preamble(document, [latexcmd[layout] + "{" + content + "}"])
1998 del document.body[i:j + 1]
2001 def convert_prettyref(document):
2002 " Converts prettyref references to neutral formatted refs "
2003 re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
2004 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
2008 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
2011 j = find_end_of_inset(document.body, i)
2013 document.warning("Malformed LyX document: No end of InsetRef!")
2016 k = find_token(document.body, "LatexCommand prettyref", i)
2017 if k != -1 and k < j:
2018 document.body[k] = "LatexCommand formatted"
2020 document.header.insert(-1, "\\use_refstyle 0")
2023 def revert_refstyle(document):
2024 " Reverts neutral formatted refs to prettyref "
2025 re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
2026 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
2030 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
2033 j = find_end_of_inset(document.body, i)
2035 document.warning("Malformed LyX document: No end of InsetRef")
2038 k = find_token(document.body, "LatexCommand formatted", i)
2039 if k != -1 and k < j:
2040 document.body[k] = "LatexCommand prettyref"
2042 i = find_token(document.header, "\\use_refstyle", 0)
2044 document.header.pop(i)
2047 def revert_nameref(document):
2048 " Convert namerefs to regular references "
2049 cmds = ["Nameref", "nameref"]
2051 rx = re.compile(r'reference "(.*)"')
2054 oldcmd = "LatexCommand " + cmd
2056 # It seems better to look for this, as most of the reference
2057 # insets won't be ones we care about.
2058 i = find_token(document.body, oldcmd, i)
2063 # Make sure it is actually in an inset!
2064 # We could just check document.lines[i-1], but that relies
2065 # upon something that might easily change.
2066 # We'll look back a few lines.
2070 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2071 if stins == -1 or stins > cmdloc:
2073 endins = find_end_of_inset(document.body, stins)
2075 document.warning("Can't find end of inset at line " + stins + "!!")
2079 refline = find_token(document.body, "reference", stins)
2080 if refline == -1 or refline > endins:
2081 document.warning("Can't find reference for inset at line " + stinst + "!!")
2083 m = rx.match(document.body[refline])
2085 document.warning("Can't match reference line: " + document.body[ref])
2089 newcontent = ['\\begin_inset ERT', 'status collapsed', '', \
2090 '\\begin_layout Plain Layout', '', '\\backslash', \
2091 cmd + '{' + ref + '}', '\\end_layout', '', '\\end_inset']
2092 document.body[stins:endins + 1] = newcontent
2094 add_to_preamble(document, "\usepackage{nameref}")
2097 def remove_Nameref(document):
2098 " Convert Nameref commands to nameref commands "
2101 # It seems better to look for this, as most of the reference
2102 # insets won't be ones we care about.
2103 i = find_token(document.body, "LatexCommand Nameref" , i)
2109 # Make sure it is actually in an inset!
2110 # We could just check document.lines[i-1], but that relies
2111 # upon something that might easily change.
2112 # We'll look back a few lines.
2116 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2117 if stins == -1 or stins > cmdloc:
2119 endins = find_end_of_inset(document.body, stins)
2121 document.warning("Can't find end of inset at line " + stins + "!!")
2125 document.body[cmdloc] = "LatexCommand nameref"
2128 def revert_mathrsfs(document):
2129 " Load mathrsfs if \mathrsfs us use in the document "
2131 end = len(document.body) - 1
2133 j = document.body[i].find("\\mathscr{")
2135 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2136 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
2143 def convert_flexnames(document):
2144 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
2147 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
2149 i = find_token(document.body, "\\begin_inset Flex", i)
2152 m = rx.match(document.body[i])
2154 document.body[i] = "\\begin_inset Flex " + m.group(1)
2159 ["Alert", "CharStyle:Alert"],
2160 ["Code", "CharStyle:Code"],
2161 ["Concepts", "CharStyle:Concepts"],
2162 ["E-Mail", "CharStyle:E-Mail"],
2163 ["Emph", "CharStyle:Emph"],
2164 ["Expression", "CharStyle:Expression"],
2165 ["Initial", "CharStyle:Initial"],
2166 ["Institute", "CharStyle:Institute"],
2167 ["Meaning", "CharStyle:Meaning"],
2168 ["Noun", "CharStyle:Noun"],
2169 ["Strong", "CharStyle:Strong"],
2170 ["Structure", "CharStyle:Structure"],
2171 ["ArticleMode", "Custom:ArticleMode"],
2172 ["Endnote", "Custom:Endnote"],
2173 ["Glosse", "Custom:Glosse"],
2174 ["PresentationMode", "Custom:PresentationMode"],
2175 ["Tri-Glosse", "Custom:Tri-Glosse"]
2179 ["Abbrev", "Element:Abbrev"],
2180 ["CCC-Code", "Element:CCC-Code"],
2181 ["Citation-number", "Element:Citation-number"],
2182 ["City", "Element:City"],
2183 ["Code", "Element:Code"],
2184 ["CODEN", "Element:CODEN"],
2185 ["Country", "Element:Country"],
2186 ["Day", "Element:Day"],
2187 ["Directory", "Element:Directory"],
2188 ["Dscr", "Element:Dscr"],
2189 ["Email", "Element:Email"],
2190 ["Emph", "Element:Emph"],
2191 ["Filename", "Element:Filename"],
2192 ["Firstname", "Element:Firstname"],
2193 ["Fname", "Element:Fname"],
2194 ["GuiButton", "Element:GuiButton"],
2195 ["GuiMenu", "Element:GuiMenu"],
2196 ["GuiMenuItem", "Element:GuiMenuItem"],
2197 ["ISSN", "Element:ISSN"],
2198 ["Issue-day", "Element:Issue-day"],
2199 ["Issue-months", "Element:Issue-months"],
2200 ["Issue-number", "Element:Issue-number"],
2201 ["KeyCap", "Element:KeyCap"],
2202 ["KeyCombo", "Element:KeyCombo"],
2203 ["Keyword", "Element:Keyword"],
2204 ["Literal", "Element:Literal"],
2205 ["MenuChoice", "Element:MenuChoice"],
2206 ["Month", "Element:Month"],
2207 ["Orgdiv", "Element:Orgdiv"],
2208 ["Orgname", "Element:Orgname"],
2209 ["Postcode", "Element:Postcode"],
2210 ["SS-Code", "Element:SS-Code"],
2211 ["SS-Title", "Element:SS-Title"],
2212 ["State", "Element:State"],
2213 ["Street", "Element:Street"],
2214 ["Surname", "Element:Surname"],
2215 ["Volume", "Element:Volume"],
2216 ["Year", "Element:Year"]
2220 def revert_flexnames(document):
2221 if document.backend == "latex":
2222 flexlist = flex_insets
2224 flexlist = flex_elements
2226 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
2229 i = find_token(document.body, "\\begin_inset Flex", i)
2232 m = rx.match(document.body[i])
2234 document.warning("Illegal flex inset: " + document.body[i])
2241 document.body[i] = "\\begin_inset Flex " + f[1]
2247 def convert_mathdots(document):
2248 " Load mathdots automatically "
2250 i = find_token(document.header, "\\use_esint" , 0)
2252 document.header.insert(i + 1, "\\use_mathdots 1")
2256 def revert_mathdots(document):
2257 " Load mathdots if used in the document "
2259 ddots = re.compile(r'\\begin_inset Formula .*\\ddots', re.DOTALL)
2260 vdots = re.compile(r'\\begin_inset Formula .*\\vdots', re.DOTALL)
2261 iddots = re.compile(r'\\begin_inset Formula .*\\iddots', re.DOTALL)
2262 mathdots = find_token(document.header, "\\use_mathdots" , 0)
2263 no = find_token(document.header, "\\use_mathdots 0" , 0)
2264 auto = find_token(document.header, "\\use_mathdots 1" , 0)
2265 yes = find_token(document.header, "\\use_mathdots 2" , 0)
2267 del document.header[mathdots]
2269 i = find_token(document.body, '\\begin_inset Formula', i)
2272 j = find_end_of_inset(document.body, i)
2274 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2276 k = ddots.search("\n".join(document.body[i:j]))
2277 l = vdots.search("\n".join(document.body[i:j]))
2278 m = iddots.search("\n".join(document.body[i:j]))
2279 if (yes == -1) and ((no != -1) or (not k and not l and not m) or (auto != -1 and not m)):
2282 # use \@ifundefined to catch also the "auto" case
2283 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2284 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}\n"])
2288 def convert_rule(document):
2289 " Convert \\lyxline to CommandInset line "
2292 i = find_token(document.body, "\\lyxline" , i)
2296 j = find_token(document.body, "\\color" , i - 2)
2298 color = document.body[j] + '\n'
2301 k = find_token(document.body, "\\begin_layout Standard" , i - 4)
2302 # we need to handle the case that \lyxline is in a separate paragraph and that it is colored
2303 # the result is then an extra empty paragraph which we get by adding an empty ERT inset
2304 if k == i - 4 and j == i - 2 and document.body[i - 1] == '':
2305 layout = '\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n\n\\end_layout\n\n\\end_inset\n' \
2306 + '\\end_layout\n\n' \
2307 + '\\begin_layout Standard\n'
2308 elif k == i - 2 and document.body[i - 1] == '':
2311 layout = '\\end_layout\n\n' \
2312 + '\\begin_layout Standard\n'
2313 l = find_token(document.body, "\\begin_layout Standard" , i + 4)
2314 if l == i + 4 and document.body[i + 1] == '':
2317 layout2 = '\\end_layout\n' \
2318 + '\n\\begin_layout Standard\n'
2320 + '\\noindent\n\n' \
2322 + '\\begin_inset CommandInset line\n' \
2323 + 'LatexCommand rule\n' \
2324 + 'offset "0.5ex"\n' \
2325 + 'width "100line%"\n' \
2326 + 'height "1pt"\n' \
2327 + '\n\\end_inset\n\n\n' \
2329 document.body[i] = subst
2333 def revert_rule(document):
2334 " Revert line insets to Tex code "
2337 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
2341 j = find_token(document.body, "\\end_inset" , i)
2342 # assure we found the end_inset of the current inset
2343 if j > i + 6 or j == -1:
2344 document.warning("Malformed LyX document: Can't find end of line inset.")
2346 # determine the optional offset
2347 k = find_token(document.body, 'offset', i, j)
2349 offset = document.body[k][8:-1]
2352 # determine the width
2353 l = find_token(document.body, 'width', i, j)
2355 width = document.body[l][7:-1]
2358 # determine the height
2359 m = find_token(document.body, 'height', i, j)
2361 height = document.body[m][8:-1]
2364 # output the \rule command
2366 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
2368 subst = "\\rule{" + width + "}{" + height + "}"
2369 document.body[i:j + 1] = put_cmd_in_ert(subst)
2373 def revert_diagram(document):
2374 " Add the feyn package if \\Diagram is used in math "
2376 re_diagram = re.compile(r'\\begin_inset Formula .*\\Diagram', re.DOTALL)
2378 i = find_token(document.body, '\\begin_inset Formula', i)
2381 j = find_end_of_inset(document.body, i)
2383 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2385 m = re_diagram.search("\n".join(document.body[i:j]))
2389 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2390 add_to_preamble(document, "\\usepackage{feyn}")
2391 # only need to do it once!
2395 def convert_bibtex_clearpage(document):
2396 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2398 i = find_token(document.header, '\\papersides', 0)
2400 document.warning("Malformed LyX document: Can't find papersides definition.")
2402 sides = int(document.header[i][12])
2406 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2410 k = find_end_of_inset(document.body, j)
2412 document.warning("Can't find end of Bibliography inset at line " + str(j))
2416 # only act if there is the option "bibtotoc"
2417 m = find_token(document.body, 'options', j, k)
2419 document.warning("Can't find options for bibliography inset at line " + str(j))
2423 optline = document.body[m]
2424 idx = optline.find("bibtotoc")
2429 # so we want to insert a new page right before the paragraph that
2430 # this bibliography thing is in. we'll look for it backwards.
2433 if document.body[lay].startswith("\\begin_layout"):
2438 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2442 subst1 = '\\begin_layout Standard\n' \
2443 + '\\begin_inset Newpage clearpage\n' \
2444 + '\\end_inset\n\n\n' \
2446 subst2 = '\\begin_layout Standard\n' \
2447 + '\\begin_inset Newpage cleardoublepage\n' \
2448 + '\\end_inset\n\n\n' \
2451 document.body.insert(lay, subst1)
2452 document.warning(subst1)
2454 document.body.insert(lay, subst2)
2455 document.warning(subst2)
2464 supported_versions = ["2.0.0","2.0"]
2465 convert = [[346, []],
2471 [352, [convert_splitindex]],
2478 [359, [convert_nomencl_width]],
2488 [369, [convert_author_id]],
2492 [373, [merge_gbrief]],
2498 [379, [convert_math_output]],
2508 [389, [convert_html_quotes]],
2512 [393, [convert_optarg]],
2513 [394, [convert_use_makebox]],
2516 [397, [remove_Nameref]],
2518 [399, [convert_mathdots]],
2519 [400, [convert_rule]],
2521 [402, [convert_bibtex_clearpage]],
2522 [403, [convert_flexnames]],
2523 [404, [convert_prettyref]]
2526 revert = [[403, [revert_refstyle]],
2527 [402, [revert_flexnames]],
2529 [400, [revert_diagram]],
2530 [399, [revert_rule]],
2531 [398, [revert_mathdots]],
2532 [397, [revert_mathrsfs]],
2534 [395, [revert_nameref]],
2535 [394, [revert_DIN_C_pagesizes]],
2536 [393, [revert_makebox]],
2537 [392, [revert_argument]],
2538 [391, [revert_beamer_args]],
2539 [390, [revert_align_decimal, revert_IEEEtran]],
2540 [389, [revert_output_sync]],
2541 [388, [revert_html_quotes]],
2542 [387, [revert_pagesizes]],
2543 [386, [revert_math_scale]],
2544 [385, [revert_lyx_version]],
2545 [384, [revert_shadedboxcolor]],
2546 [383, [revert_fontcolor]],
2547 [382, [revert_turkmen]],
2548 [381, [revert_notefontcolor]],
2549 [380, [revert_equalspacing_xymatrix]],
2550 [379, [revert_inset_preview]],
2551 [378, [revert_math_output]],
2553 [376, [revert_multirow]],
2554 [375, [revert_includeall]],
2555 [374, [revert_includeonly]],
2556 [373, [revert_html_options]],
2557 [372, [revert_gbrief]],
2558 [371, [revert_fontenc]],
2559 [370, [revert_mhchem]],
2560 [369, [revert_suppress_date]],
2561 [368, [revert_author_id]],
2562 [367, [revert_hspace_glue_lengths]],
2563 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2564 [365, [revert_percent_skip_lengths]],
2565 [364, [revert_paragraph_indentation]],
2566 [363, [revert_branch_filename]],
2567 [362, [revert_longtable_align]],
2568 [361, [revert_applemac]],
2570 [359, [revert_nomencl_cwidth]],
2571 [358, [revert_nomencl_width]],
2572 [357, [revert_custom_processors]],
2573 [356, [revert_ulinelatex]],
2575 [354, [revert_strikeout]],
2576 [353, [revert_printindexall]],
2577 [352, [revert_subindex]],
2578 [351, [revert_splitindex]],
2579 [350, [revert_backgroundcolor]],
2580 [349, [revert_outputformat]],
2581 [348, [revert_xetex]],
2582 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2583 [346, [revert_tabularvalign]],
2584 [345, [revert_swiss]]
2588 if __name__ == "__main__":