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, \
27 find_end_of_inset, find_end_of_layout, get_value, get_value_string
29 ####################################################################
30 # Private helper functions
32 def remove_option(document, m, option):
33 ''' removes option from line m. returns whether we did anything '''
34 l = document.body[m].find(option)
37 val = document.body[m][l:].split('"')[1]
38 document.body[m] = document.body[m][:l - 1] + document.body[m][l+len(option + '="' + val + '"'):]
42 # Note that text can be either a list of lines or a single line.
43 def add_to_preamble(document, text):
44 """ Add text to the preamble if it is not already there.
45 Only the first line is checked!"""
47 if not type(text) is list:
48 # split on \n just in case
49 # it'll give us the one element list we want
50 # if there's no \n, too
51 text = text.split('\n')
53 if find_token(document.preamble, text[0], 0) != -1:
56 document.preamble.extend(text)
59 # Note that text can be either a list of lines or a single line.
60 # It should really be a list.
61 def insert_to_preamble(index, document, text):
62 """ Insert text to the preamble at a given line"""
64 if not type(text) is list:
65 # split on \n just in case
66 # it'll give us the one element list we want
67 # if there's no \n, too
68 text = text.split('\n')
70 document.preamble[index:index] = text
73 def read_unicodesymbols():
74 " Read the unicodesymbols list of unicode characters and corresponding commands."
75 pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
76 fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
78 # Two backslashes, followed by some non-word character, and then a character
79 # in brackets. The idea is to check for constructs like: \"{u}, which is how
80 # they are written in the unicodesymbols file; but they can also be written
81 # as: \"u or even \" u.
82 r = re.compile(r'\\\\(\W)\{(\w)\}')
83 for line in fp.readlines():
84 if line[0] != '#' and line.strip() != "":
85 line=line.replace(' "',' ') # remove all quotation marks with spaces before
86 line=line.replace('" ',' ') # remove all quotation marks with spaces after
87 line=line.replace(r'\"','"') # replace \" by " (for characters with diaeresis)
89 [ucs4,command,dead] = line.split(None,2)
90 if command[0:1] != "\\":
92 spec_chars.append([command, unichr(eval(ucs4))])
98 # If the character is a double-quote, then we need to escape it, too,
99 # since it is done that way in the LyX file.
100 if m.group(1) == "\"":
103 command += m.group(1) + m.group(2)
104 commandbl += m.group(1) + ' ' + m.group(2)
105 spec_chars.append([command, unichr(eval(ucs4))])
106 spec_chars.append([commandbl, unichr(eval(ucs4))])
111 unicode_reps = read_unicodesymbols()
114 # DO NOT USE THIS ROUTINE ANY MORE. Better yet, replace the uses that
115 # have been made of it with uses of put_cmd_in_ert.
116 def old_put_cmd_in_ert(string):
117 for rep in unicode_reps:
118 string = string.replace(rep[1], rep[0].replace('\\\\', '\\'))
119 string = string.replace('\\', "\\backslash\n")
120 string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n" \
121 + string + "\n\\end_layout\n\\end_inset"
125 # This routine wraps some content in an ERT inset.
127 # NOTE: The function accepts either a single string or a LIST of strings as
128 # argument. But it returns a LIST of strings, split on \n, so that it does
129 # not have embedded newlines.
131 # This is how lyx2lyx represents a LyX document: as a list of strings,
132 # each representing a line of a LyX file. Embedded newlines confuse
135 # A call to this routine will often go something like this:
136 # i = find_token('\\begin_inset FunkyInset', ...)
138 # j = find_end_of_inset(document.body, i)
139 # content = ...extract content from insets
140 # # that could be as simple as:
141 # # content = lyx2latex(document[i:j + 1])
142 # ert = put_cmd_in_ert(content)
143 # document.body[i:j] = ert
144 # Now, before we continue, we need to reset i appropriately. Normally,
147 # That puts us right after the ERT we just inserted.
149 def put_cmd_in_ert(arg):
150 ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
151 # Despite the warnings just given, it will be faster for us to work
152 # with a single string internally. That way, we only go through the
153 # unicode_reps loop once.
154 if type(arg) is list:
158 for rep in unicode_reps:
159 s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
160 s = s.replace('\\', "\\backslash\n")
161 ret += s.splitlines()
162 ret += ["\\end_layout", "\\end_inset"]
166 def lyx2latex(document, lines):
167 'Convert some LyX stuff into corresponding LaTeX stuff, as best we can.'
168 # clean up multiline stuff
174 for curline in range(len(lines)):
175 line = lines[curline]
176 if line.startswith("\\begin_inset Note Note"):
177 # We want to skip LyX notes, so remember where the inset ends
178 note_end = find_end_of_inset(lines, curline + 1)
180 elif note_end >= curline:
183 elif line.startswith("\\begin_inset ERT"):
184 # We don't want to replace things inside ERT, so figure out
185 # where the end of the inset is.
186 ert_end = find_end_of_inset(lines, curline + 1)
188 elif line.startswith("\\begin_inset Formula"):
190 elif line.startswith("\\begin_inset Quotes"):
191 # For now, we do a very basic reversion. Someone who understands
192 # quotes is welcome to fix it up.
193 qtype = line[20:].strip()
207 elif line.startswith("\\begin_inset space"):
208 line = line[18:].strip()
209 if line.startswith("\\hspace"):
210 # Account for both \hspace and \hspace*
213 elif line == "\\space{}":
215 elif line == "\\thinspace{}":
218 # The LyX length is in line[8:], after the \length keyword
219 length = latex_length(line[8:])[1]
220 line = hspace + "{" + length + "}"
222 elif line.isspace() or \
223 line.startswith("\\begin_layout") or \
224 line.startswith("\\end_layout") or \
225 line.startswith("\\begin_inset") or \
226 line.startswith("\\end_inset") or \
227 line.startswith("\\lang") or \
228 line.strip() == "status collapsed" or \
229 line.strip() == "status open":
233 # this needs to be added to the preamble because of cases like
234 # \textmu, \textbackslash, etc.
235 add_to_preamble(document, ['% added by lyx2lyx for converted index entries',
236 '\\@ifundefined{textmu}',
237 ' {\\usepackage{textcomp}}{}'])
238 # a lossless reversion is not possible
239 # try at least to handle some common insets and settings
240 if ert_end >= curline:
241 line = line.replace(r'\backslash', '\\')
243 # No need to add "{}" after single-nonletter macros
244 line = line.replace('&', '\\&')
245 line = line.replace('#', '\\#')
246 line = line.replace('^', '\\textasciicircum{}')
247 line = line.replace('%', '\\%')
248 line = line.replace('_', '\\_')
249 line = line.replace('$', '\\$')
251 # Do the LyX text --> LaTeX conversion
252 for rep in unicode_reps:
253 line = line.replace(rep[1], rep[0] + "{}")
254 line = line.replace(r'\backslash', r'\textbackslash{}')
255 line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}')
256 line = line.replace(r'\shape italic', r'\itshape{}').replace(r'\shape smallcaps', r'\scshape{}')
257 line = line.replace(r'\shape slanted', r'\slshape{}').replace(r'\shape default', r'\upshape{}')
258 line = line.replace(r'\emph on', r'\em{}').replace(r'\emph default', r'\em{}')
259 line = line.replace(r'\noun on', r'\scshape{}').replace(r'\noun default', r'\upshape{}')
260 line = line.replace(r'\bar under', r'\underbar{').replace(r'\bar default', r'}')
261 line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}')
262 line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}')
263 line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'')
268 def latex_length(slen):
270 Convert lengths to their LaTeX representation. Returns (bool, length),
271 where the bool tells us if it was a percentage, and the length is the
272 LaTeX representation.
276 # the slen has the form
277 # ValueUnit+ValueUnit-ValueUnit or
278 # ValueUnit+-ValueUnit
279 # the + and - (glue lengths) are optional
280 # the + always precedes the -
282 # Convert relative lengths to LaTeX units
283 units = {"text%":"\\textwidth", "col%":"\\columnwidth",
284 "page%":"\\paperwidth", "line%":"\\linewidth",
285 "theight%":"\\textheight", "pheight%":"\\paperheight"}
286 for unit in units.keys():
291 minus = slen.rfind("-", 1, i)
292 plus = slen.rfind("+", 0, i)
293 latex_unit = units[unit]
294 if plus == -1 and minus == -1:
296 value = str(float(value)/100)
297 end = slen[i + len(unit):]
298 slen = value + latex_unit + end
300 value = slen[plus + 1:i]
301 value = str(float(value)/100)
302 begin = slen[:plus + 1]
303 end = slen[i+len(unit):]
304 slen = begin + value + latex_unit + end
306 value = slen[minus + 1:i]
307 value = str(float(value)/100)
308 begin = slen[:minus + 1]
309 slen = begin + value + latex_unit
311 # replace + and -, but only if the - is not the first character
312 slen = slen[0] + slen[1:].replace("+", " plus ").replace("-", " minus ")
313 # handle the case where "+-1mm" was used, because LaTeX only understands
314 # "plus 1mm minus 1mm"
315 if slen.find("plus minus"):
316 lastvaluepos = slen.rfind(" ")
317 lastvalue = slen[lastvaluepos:]
318 slen = slen.replace(" ", lastvalue + " ")
319 return (percent, slen)
322 def revert_flex_inset(document, name, LaTeXname, position):
323 " Convert flex insets to TeX code "
326 i = find_token(document.body, '\\begin_inset Flex ' + name, i)
329 z = find_end_of_inset(document.body, i)
331 document.warning("Malformed LyX document: Can't find end of Flex " + name + " inset.")
333 # remove the \end_inset
334 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
335 # we need to reset character layouts if necessary
336 j = find_token(document.body, '\\emph on', i, z)
337 k = find_token(document.body, '\\noun on', i, z)
338 l = find_token(document.body, '\\series', i, z)
339 m = find_token(document.body, '\\family', i, z)
340 n = find_token(document.body, '\\shape', i, z)
341 o = find_token(document.body, '\\color', i, z)
342 p = find_token(document.body, '\\size', i, z)
343 q = find_token(document.body, '\\bar under', i, z)
344 r = find_token(document.body, '\\uuline on', i, z)
345 s = find_token(document.body, '\\uwave on', i, z)
346 t = find_token(document.body, '\\strikeout on', i, z)
348 document.body.insert(z - 2, "\\emph default")
350 document.body.insert(z - 2, "\\noun default")
352 document.body.insert(z - 2, "\\series default")
354 document.body.insert(z - 2, "\\family default")
356 document.body.insert(z - 2, "\\shape default")
358 document.body.insert(z - 2, "\\color inherit")
360 document.body.insert(z - 2, "\\size default")
362 document.body.insert(z - 2, "\\bar default")
364 document.body.insert(z - 2, "\\uuline default")
366 document.body.insert(z - 2, "\\uwave default")
368 document.body.insert(z - 2, "\\strikeout default")
369 document.body[i:i + 4] = put_cmd_in_ert(LaTeXname + "{")
373 def revert_font_attrs(document, name, LaTeXname):
374 " Reverts font changes to TeX code "
378 i = find_token(document.body, name + ' on', i)
381 j = find_token(document.body, name + ' default', i)
382 k = find_token(document.body, name + ' on', i + 1)
383 # if there is no default set, the style ends with the layout
384 # assure hereby that we found the correct layout end
385 if j != -1 and (j < k or k == -1):
386 document.body[j:j + 1] = put_cmd_in_ert("}")
388 j = find_token(document.body, '\\end_layout', i)
389 document.body[j:j] = put_cmd_in_ert("}")
390 document.body[i:i + 1] = put_cmd_in_ert(LaTeXname + "{")
395 def revert_layout_command(document, name, LaTeXname, position):
396 " Reverts a command from a layout to TeX code "
399 i = find_token(document.body, '\\begin_layout ' + name, i)
403 # find the next layout
406 j = find_token(document.body, '\\begin_layout', j)
407 l = len(document.body)
408 # if nothing was found it was the last layout of the document
410 document.body[l - 4:l - 4] = put_cmd_in_ert("}")
412 # exclude plain layout because this can be TeX code or another inset
413 elif document.body[j] != '\\begin_layout Plain Layout':
414 document.body[j - 2:j - 2] = put_cmd_in_ert("}")
418 document.body[i] = '\\begin_layout Standard'
419 document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{")
424 val = string.atoi(s, 16)
427 return str(val / 256.0)
430 ###############################################################################
432 ### Conversion and reversion routines
434 ###############################################################################
436 def revert_swiss(document):
437 " Set language german-ch to ngerman "
439 if document.language == "german-ch":
440 document.language = "ngerman"
441 i = find_token(document.header, "\\language", 0)
443 document.header[i] = "\\language ngerman"
446 j = find_token(document.body, "\\lang german-ch", j)
449 document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
453 def revert_tabularvalign(document):
454 " Revert the tabular valign option "
457 i = find_token(document.body, "\\begin_inset Tabular", i)
460 end = find_end_of_inset(document.body, i)
462 document.warning("Can't find end of inset at line " + str(i))
465 fline = find_token(document.body, "<features", i, end)
467 document.warning("Can't find features for inset at line " + str(i))
470 p = document.body[fline].find("islongtable")
472 q = document.body[fline].find("tabularvalignment")
475 # This seems wrong: It removes everything after
476 # tabularvalignment, too.
477 document.body[fline] = document.body[fline][:q - 1] + '>'
482 tabularvalignment = 'c'
483 # which valignment is specified?
484 m = document.body[fline].find('tabularvalignment="top"')
486 tabularvalignment = 't'
487 m = document.body[fline].find('tabularvalignment="bottom"')
489 tabularvalignment = 'b'
490 # delete tabularvalignment
491 q = document.body[fline].find("tabularvalignment")
494 # This seems wrong: It removes everything after
495 # tabularvalignment, too.
496 document.body[fline] = document.body[fline][:q - 1] + '>'
498 # don't add a box when centered
499 if tabularvalignment == 'c':
502 subst = ['\\end_layout', '\\end_inset']
503 document.body[end:end] = subst # just inserts those lines
504 subst = ['\\begin_inset Box Frameless',
505 'position "' + tabularvalignment +'"',
510 # we don't know the width, assume 50%
514 'height_special "totalheight"',
517 '\\begin_layout Plain Layout']
518 document.body[i:i] = subst # this just inserts the array at i
519 # since there could be a tabular inside a tabular, we cannot
524 def revert_phantom_types(document, ptype, cmd):
525 " Reverts phantom to ERT "
528 i = find_token(document.body, "\\begin_inset Phantom " + ptype, i)
531 end = find_end_of_inset(document.body, i)
533 document.warning("Can't find end of inset at line " + str(i))
536 blay = find_token(document.body, "\\begin_layout Plain Layout", i, end)
538 document.warning("Can't find layout for inset at line " + str(i))
541 bend = find_token(document.body, "\\end_layout", blay, end)
543 document.warning("Malformed LyX document: Could not find end of Phantom inset's layout.")
546 substi = ["\\begin_inset ERT", "status collapsed", "",
547 "\\begin_layout Plain Layout", "", "", "\\backslash",
548 cmd + "{", "\\end_layout", "", "\\end_inset"]
549 substj = ["\\size default", "", "\\begin_inset ERT", "status collapsed", "",
550 "\\begin_layout Plain Layout", "", "}", "\\end_layout", "", "\\end_inset"]
551 # do the later one first so as not to mess up the numbering
552 document.body[bend:end + 1] = substj
553 document.body[i:blay + 1] = substi
554 i = end + len(substi) + len(substj) - (end - bend) - (blay - i) - 2
557 def revert_phantom(document):
558 revert_phantom_types(document, "Phantom", "phantom")
560 def revert_hphantom(document):
561 revert_phantom_types(document, "HPhantom", "hphantom")
563 def revert_vphantom(document):
564 revert_phantom_types(document, "VPhantom", "vphantom")
567 def revert_xetex(document):
568 " Reverts documents that use XeTeX "
569 i = find_token(document.header, '\\use_xetex', 0)
571 document.warning("Malformed LyX document: Missing \\use_xetex.")
573 if get_value(document.header, "\\use_xetex", i) == 'false':
574 del document.header[i]
576 del document.header[i]
577 # 1.) set doc encoding to utf8-plain
578 i = find_token(document.header, "\\inputencoding", 0)
580 document.warning("Malformed LyX document: Missing \\inputencoding.")
581 document.header[i] = "\\inputencoding utf8-plain"
582 # 2.) check font settings
583 l = find_token(document.header, "\\font_roman", 0)
585 document.warning("Malformed LyX document: Missing \\font_roman.")
586 line = document.header[l]
587 l = re.compile(r'\\font_roman (.*)$')
590 l = find_token(document.header, "\\font_sans", 0)
592 document.warning("Malformed LyX document: Missing \\font_sans.")
593 line = document.header[l]
594 l = re.compile(r'\\font_sans (.*)$')
597 l = find_token(document.header, "\\font_typewriter", 0)
599 document.warning("Malformed LyX document: Missing \\font_typewriter.")
600 line = document.header[l]
601 l = re.compile(r'\\font_typewriter (.*)$')
603 typewriter = m.group(1)
604 osf = get_value(document.header, '\\font_osf', 0) == "true"
605 sf_scale = float(get_value(document.header, '\\font_sf_scale', 0))
606 tt_scale = float(get_value(document.header, '\\font_tt_scale', 0))
607 # 3.) set preamble stuff
608 pretext = '%% This document must be processed with xelatex!\n'
609 pretext += '\\usepackage{fontspec}\n'
610 if roman != "default":
611 pretext += '\\setmainfont[Mapping=tex-text]{' + roman + '}\n'
612 if sans != "default":
613 pretext += '\\setsansfont['
615 pretext += 'Scale=' + str(sf_scale / 100) + ','
616 pretext += 'Mapping=tex-text]{' + sans + '}\n'
617 if typewriter != "default":
618 pretext += '\\setmonofont'
620 pretext += '[Scale=' + str(tt_scale / 100) + ']'
621 pretext += '{' + typewriter + '}\n'
623 pretext += '\\defaultfontfeatures{Numbers=OldStyle}\n'
624 pretext += '\usepackage{xunicode}\n'
625 pretext += '\usepackage{xltxtra}\n'
626 insert_to_preamble(0, document, pretext)
627 # 4.) reset font settings
628 i = find_token(document.header, "\\font_roman", 0)
630 document.warning("Malformed LyX document: Missing \\font_roman.")
631 document.header[i] = "\\font_roman default"
632 i = find_token(document.header, "\\font_sans", 0)
634 document.warning("Malformed LyX document: Missing \\font_sans.")
635 document.header[i] = "\\font_sans default"
636 i = find_token(document.header, "\\font_typewriter", 0)
638 document.warning("Malformed LyX document: Missing \\font_typewriter.")
639 document.header[i] = "\\font_typewriter default"
640 i = find_token(document.header, "\\font_osf", 0)
642 document.warning("Malformed LyX document: Missing \\font_osf.")
643 document.header[i] = "\\font_osf false"
644 i = find_token(document.header, "\\font_sc", 0)
646 document.warning("Malformed LyX document: Missing \\font_sc.")
647 document.header[i] = "\\font_sc false"
648 i = find_token(document.header, "\\font_sf_scale", 0)
650 document.warning("Malformed LyX document: Missing \\font_sf_scale.")
651 document.header[i] = "\\font_sf_scale 100"
652 i = find_token(document.header, "\\font_tt_scale", 0)
654 document.warning("Malformed LyX document: Missing \\font_tt_scale.")
655 document.header[i] = "\\font_tt_scale 100"
658 def revert_outputformat(document):
659 " Remove default output format param "
660 i = find_token(document.header, '\\default_output_format', 0)
662 document.warning("Malformed LyX document: Missing \\default_output_format.")
664 del document.header[i]
667 def revert_backgroundcolor(document):
668 " Reverts background color to preamble code "
669 i = find_token(document.header, "\\backgroundcolor", 0)
672 colorcode = get_value(document.header, '\\backgroundcolor', i)
673 del document.header[i]
674 # don't clutter the preamble if backgroundcolor is not set
675 if colorcode == "#ffffff":
677 red = hex2ratio(colorcode[1:3])
678 green = hex2ratio(colorcode[3:5])
679 blue = hex2ratio(colorcode[5:7])
680 insert_to_preamble(0, document,
681 '% Commands inserted by lyx2lyx to set the background color\n'
682 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
683 + '\\definecolor{page_backgroundcolor}{rgb}{'
684 + red + ',' + green + ',' + blue + '}\n'
685 + '\\pagecolor{page_backgroundcolor}\n')
688 def revert_splitindex(document):
689 " Reverts splitindex-aware documents "
690 i = find_token(document.header, '\\use_indices', 0)
692 document.warning("Malformed LyX document: Missing \\use_indices.")
694 indices = get_value(document.header, "\\use_indices", i)
696 useindices = (indices == "true")
698 preamble += "\\usepackage{splitidx}\n"
699 del document.header[i]
701 # deal with index declarations in the preamble
704 i = find_token(document.header, "\\index", i)
707 k = find_token(document.header, "\\end_index", i)
709 document.warning("Malformed LyX document: Missing \\end_index.")
712 line = document.header[i]
713 l = re.compile(r'\\index (.*)$')
716 ishortcut = get_value(document.header, '\\shortcut', i, k)
718 preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
719 del document.header[i:k + 1]
721 insert_to_preamble(0, document, preamble)
723 # deal with index insets
724 # these need to have the argument removed
727 i = find_token(document.body, "\\begin_inset Index", i)
730 line = document.body[i]
731 l = re.compile(r'\\begin_inset Index (.*)$')
734 if itype == "idx" or indices == "false":
735 document.body[i] = "\\begin_inset Index"
737 k = find_end_of_inset(document.body, i)
739 document.warning("Can't find end of index inset!")
742 content = lyx2latex(document, document.body[i:k])
744 content = content.replace('"', r'\"')
745 subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
746 document.body[i:k + 1] = subst
749 # deal with index_print insets
752 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
755 k = find_end_of_inset(document.body, i)
756 ptype = get_value(document.body, 'type', i, k).strip('"')
758 j = find_token(document.body, "type", i, k)
761 del document.body[i:k + 1]
763 subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
764 document.body[i:k + 1] = subst
768 def convert_splitindex(document):
769 " Converts index and printindex insets to splitindex-aware format "
772 i = find_token(document.body, "\\begin_inset Index", i)
775 document.body[i] = document.body[i].replace("\\begin_inset Index",
776 "\\begin_inset Index idx")
780 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
783 if document.body[i + 1].find('LatexCommand printindex') == -1:
784 document.warning("Malformed LyX document: Incomplete printindex inset.")
786 subst = ["LatexCommand printindex",
788 document.body[i + 1:i + 2] = subst
792 def revert_subindex(document):
793 " Reverts \\printsubindex CommandInset types "
794 i = find_token(document.header, '\\use_indices', 0)
796 document.warning("Malformed LyX document: Missing \\use_indices.")
798 indices = get_value(document.header, "\\use_indices", i)
799 useindices = (indices == "true")
802 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
805 k = find_end_of_inset(document.body, i)
806 ctype = get_value(document.body, 'LatexCommand', i, k)
807 if ctype != "printsubindex":
810 ptype = get_value(document.body, 'type', i, k).strip('"')
812 del document.body[i:k + 1]
814 subst = put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")
815 document.body[i:k + 1] = subst
819 def revert_printindexall(document):
820 " Reverts \\print[sub]index* CommandInset types "
821 i = find_token(document.header, '\\use_indices', 0)
823 document.warning("Malformed LyX document: Missing \\use_indices.")
825 indices = get_value(document.header, "\\use_indices", i)
826 useindices = (indices == "true")
829 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
832 k = find_end_of_inset(document.body, i)
833 ctype = get_value(document.body, 'LatexCommand', i, k)
834 if ctype != "printindex*" and ctype != "printsubindex*":
838 del document.body[i:k + 1]
840 subst = put_cmd_in_ert("\\" + ctype + "{}")
841 document.body[i:k + 1] = subst
845 def revert_strikeout(document):
846 " Reverts \\strikeout font attribute "
847 changed = revert_font_attrs(document, "\\uuline", "\\uuline")
848 changed = revert_font_attrs(document, "\\uwave", "\\uwave") or changed
849 changed = revert_font_attrs(document, "\\strikeout", "\\sout") or changed
851 insert_to_preamble(0, document,
852 '% Commands inserted by lyx2lyx for proper underlining\n'
853 + '\\PassOptionsToPackage{normalem}{ulem}\n'
854 + '\\usepackage{ulem}\n')
857 def revert_ulinelatex(document):
858 " Reverts \\uline font attribute "
859 i = find_token(document.body, '\\bar under', 0)
862 insert_to_preamble(0, document,
863 '% Commands inserted by lyx2lyx for proper underlining\n'
864 + '\\PassOptionsToPackage{normalem}{ulem}\n'
865 + '\\usepackage{ulem}\n'
866 + '\\let\\cite@rig\\cite\n'
867 + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n'
868 + ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n'
869 + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n')
872 def revert_custom_processors(document):
873 " Remove bibtex_command and index_command params "
874 i = find_token(document.header, '\\bibtex_command', 0)
876 document.warning("Malformed LyX document: Missing \\bibtex_command.")
878 del document.header[i]
879 i = find_token(document.header, '\\index_command', 0)
881 document.warning("Malformed LyX document: Missing \\index_command.")
883 del document.header[i]
886 def convert_nomencl_width(document):
887 " Add set_width param to nomencl_print "
890 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
893 document.body.insert(i + 2, "set_width \"none\"")
897 def revert_nomencl_width(document):
898 " Remove set_width param from nomencl_print "
901 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
904 j = find_end_of_inset(document.body, i)
905 l = find_token(document.body, "set_width", i, j)
907 document.warning("Can't find set_width option for nomencl_print!")
914 def revert_nomencl_cwidth(document):
915 " Remove width param from nomencl_print "
918 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
921 j = find_end_of_inset(document.body, i)
922 l = find_token(document.body, "width", i, j)
924 document.warning("Can't find width option for nomencl_print!")
927 width = get_value(document.body, "width", i, j).strip('"')
929 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
930 add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
934 def revert_applemac(document):
935 " Revert applemac encoding to auto "
936 if document.encoding != "applemac":
938 document.encoding = "auto"
939 i = find_token(document.header, "\\encoding", 0)
941 document.header[i] = "\\encoding auto"
944 def revert_longtable_align(document):
945 " Remove longtable alignment setting "
948 i = find_token(document.body, "\\begin_inset Tabular", i)
951 end = find_end_of_inset(document.body, i)
953 document.warning("Can't find end of inset at line " + str(i))
956 fline = find_token(document.body, "<features", i, end)
958 document.warning("Can't find features for inset at line " + str(i))
961 j = document.body[fline].find("longtabularalignment")
965 # FIXME Is this correct? It wipes out everything after the
967 document.body[fline] = document.body[fline][:j - 1] + '>'
968 # since there could be a tabular inside this one, we
969 # cannot jump to end.
973 def revert_branch_filename(document):
974 " Remove \\filename_suffix parameter from branches "
977 i = find_token(document.header, "\\filename_suffix", i)
980 del document.header[i]
983 def revert_paragraph_indentation(document):
984 " Revert custom paragraph indentation to preamble code "
985 i = find_token(document.header, "\\paragraph_indentation", 0)
988 length = get_value(document.header, "\\paragraph_indentation", i)
989 # we need only remove the line if indentation is default
990 if length != "default":
991 # handle percent lengths
992 length = latex_length(length)[1]
993 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
994 add_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
995 del document.header[i]
998 def revert_percent_skip_lengths(document):
999 " Revert relative lengths for paragraph skip separation to preamble code "
1000 i = find_token(document.header, "\\defskip", 0)
1003 length = get_value(document.header, "\\defskip", i)
1004 # only revert when a custom length was set and when
1005 # it used a percent length
1006 if length in ('smallskip', 'medskip', 'bigskip'):
1008 # handle percent lengths
1009 percent, length = latex_length(length)
1010 if percent == "True":
1011 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1012 add_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
1013 # set defskip to medskip as default
1014 document.header[i] = "\\defskip medskip"
1017 def revert_percent_vspace_lengths(document):
1018 " Revert relative VSpace lengths to ERT "
1021 i = find_token(document.body, "\\begin_inset VSpace", i)
1024 # only revert if a custom length was set and if
1025 # it used a percent length
1026 r = re.compile(r'\\begin_inset VSpace (.*)$')
1027 m = r.match(document.body[i])
1029 if length in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
1032 # check if the space has a star (protected space)
1033 protected = (document.body[i].rfind("*") != -1)
1035 length = length.rstrip('*')
1036 # handle percent lengths
1037 percent, length = latex_length(length)
1038 # revert the VSpace inset to ERT
1039 if percent == "True":
1041 subst = put_cmd_in_ert("\\vspace*{" + length + "}")
1043 subst = put_cmd_in_ert("\\vspace{" + length + "}")
1044 document.body[i:i + 2] = subst
1048 def revert_percent_hspace_lengths(document):
1049 " Revert relative HSpace lengths to ERT "
1052 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1055 j = find_end_of_inset(document.body, i)
1057 document.warning("Can't find end of inset at line " + str(i))
1060 # only revert if a custom length was set...
1061 length = get_value(document.body, '\\length', i + 1, j)
1063 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1067 if document.body[i].find("\\hspace*{}") != -1:
1069 # ...and if it used a percent length
1070 percent, length = latex_length(length)
1071 # revert the HSpace inset to ERT
1072 if percent == "True":
1073 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
1074 document.body[i:j + 1] = subst
1075 # if we did a substitution, this will still be ok
1079 def revert_hspace_glue_lengths(document):
1080 " Revert HSpace glue lengths to ERT "
1083 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1086 j = find_end_of_inset(document.body, i)
1088 document.warning("Can't find end of inset at line " + str(i))
1091 length = get_value(document.body, '\\length', i + 1, j)
1093 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1097 if document.body[i].find("\\hspace*{}") != -1:
1099 # only revert if the length contains a plus or minus at pos != 0
1100 if length.find('-',1) != -1 or length.find('+',1) != -1:
1101 # handle percent lengths
1102 length = latex_length(length)[1]
1103 # revert the HSpace inset to ERT
1104 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
1105 document.body[i:j+1] = subst
1109 def convert_author_id(document):
1110 " Add the author_id to the \\author definition and make sure 0 is not used"
1113 re_author = re.compile(r'(\\author) (\".*\")\s*(.*)$')
1116 i = find_token(document.header, "\\author", i)
1119 m = re_author.match(document.header[i])
1123 document.header[i] = "\\author %i %s %s" % (anum, name, email)
1124 # FIXME Should this really be incremented if we didn't match?
1130 i = find_token(document.body, "\\change_", i)
1133 change = document.body[i].split(' ');
1134 if len(change) == 3:
1136 author_id = int(change[1])
1138 document.body[i] = "%s %i %s" % (type, author_id + 1, time)
1142 def revert_author_id(document):
1143 " Remove the author_id from the \\author definition "
1146 rx = re.compile(r'(\\author)\s+(\d+)\s+(\".*\")\s*(.*)$')
1150 i = find_token(document.header, "\\author", i)
1153 m = rx.match(document.header[i])
1155 author_id = int(m.group(2))
1156 idmap[author_id] = anum
1159 document.header[i] = "\\author %s %s" % (name, email)
1161 # FIXME Should this be incremented if we didn't match?
1166 i = find_token(document.body, "\\change_", i)
1169 change = document.body[i].split(' ');
1170 if len(change) == 3:
1172 author_id = int(change[1])
1174 document.body[i] = "%s %i %s" % (type, idmap[author_id], time)
1178 def revert_suppress_date(document):
1179 " Revert suppressing of default document date to preamble code "
1180 i = find_token(document.header, "\\suppress_date", 0)
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]
1192 def revert_mhchem(document):
1193 "Revert mhchem loading to preamble code"
1196 i = find_token(document.header, "\\use_mhchem", 0)
1198 document.warning("Malformed LyX document: Could not find mhchem setting.")
1201 val = get_value(document.header, "\\use_mhchem", i)
1206 del document.header[i]
1208 if mhchem == "auto":
1211 i = find_token(document.body, "\\begin_inset Formula", i)
1214 line = document.body[i]
1215 if line.find("\\ce{") != -1 or line.find("\\cf{") != 1:
1221 pre = ["% lyx2lyx mhchem commands",
1222 "\\PassOptionsToPackage{version=3}{mhchem}",
1223 "\\usepackage{mhchem}"]
1224 add_to_preamble(document, pre)
1227 def revert_fontenc(document):
1228 " Remove fontencoding param "
1229 i = find_token(document.header, '\\fontencoding', 0)
1231 document.warning("Malformed LyX document: Missing \\fontencoding.")
1233 del document.header[i]
1236 def merge_gbrief(document):
1237 " Merge g-brief-en and g-brief-de to one class "
1239 if document.textclass != "g-brief-de":
1240 if document.textclass == "g-brief-en":
1241 document.textclass = "g-brief"
1242 document.set_textclass()
1245 obsoletedby = { "Brieftext": "Letter",
1246 "Unterschrift": "Signature",
1247 "Strasse": "Street",
1248 "Zusatz": "Addition",
1251 "RetourAdresse": "ReturnAddress",
1252 "MeinZeichen": "MyRef",
1253 "IhrZeichen": "YourRef",
1254 "IhrSchreiben": "YourMail",
1257 "Konto": "BankAccount",
1258 "Postvermerk": "PostalComment",
1259 "Adresse": "Address",
1261 "Betreff": "Reference",
1262 "Anrede": "Opening",
1268 i = find_token(document.body, "\\begin_layout", i)
1272 layout = document.body[i][14:]
1273 if layout in obsoletedby:
1274 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1278 document.textclass = "g-brief"
1279 document.set_textclass()
1282 def revert_gbrief(document):
1283 " Revert g-brief to g-brief-en "
1284 if document.textclass == "g-brief":
1285 document.textclass = "g-brief-en"
1286 document.set_textclass()
1289 def revert_html_options(document):
1290 " Remove html options "
1291 i = find_token(document.header, '\\html_use_mathml', 0)
1293 del document.header[i]
1294 i = find_token(document.header, '\\html_be_strict', 0)
1296 del document.header[i]
1299 def revert_includeonly(document):
1302 i = find_token(document.header, "\\begin_includeonly", i)
1305 j = find_end_of(document.header, i, "\\begin_includeonly", "\\end_includeonly")
1307 document.warning("Unable to find end of includeonly section!!")
1309 document.header[i : j + 1] = []
1312 def revert_includeall(document):
1313 " Remove maintain_unincluded_children param "
1314 i = find_token(document.header, '\\maintain_unincluded_children', 0)
1316 del document.header[i]
1319 def revert_multirow(document):
1320 " Revert multirow cells in tables to TeX-code"
1324 # cell type 3 is multirow begin cell
1325 i = find_token(document.body, '<cell multirow="3"', i)
1328 # a multirow cell was found
1330 # remove the multirow tag, set the valignment to top
1331 # and remove the bottom line
1332 # FIXME Are we sure these always have space around them?
1333 document.body[i] = document.body[i].replace(' multirow="3" ', ' ')
1334 document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
1335 document.body[i] = document.body[i].replace(' bottomline="true" ', ' ')
1336 # write ERT to create the multirow cell
1337 # use 2 rows and 2cm as default with because the multirow span
1338 # and the column width is only hardly accessible
1339 cend = find_token(document.body, "</cell>", i)
1341 document.warning("Malformed LyX document: Could not find end of tabular cell.")
1344 blay = find_token(document.body, "\\begin_layout", i, cend)
1346 document.warning("Can't find layout for cell!")
1349 bend = find_end_of_layout(document.body, blay)
1351 document.warning("Can't find end of layout for cell!")
1355 # do the later one first, so as not to mess up the numbering
1356 # we are wrapping the whole cell in this ert
1357 # so before the end of the layout...
1358 document.body[bend:bend] = put_cmd_in_ert("}")
1359 # ...and after the beginning
1360 document.body[blay+1:blay+1] = put_cmd_in_ert("\\multirow{2}{2cm}{")
1363 # cell type 4 is multirow part cell
1364 k = find_token(document.body, '<cell multirow="4"', cend)
1367 # remove the multirow tag, set the valignment to top
1368 # and remove the top line
1369 # FIXME Are we sure these always have space around them?
1370 document.body[k] = document.body[k].replace(' multirow="4" ', ' ')
1371 document.body[k] = document.body[k].replace('valignment="middle"', 'valignment="top"')
1372 document.body[k] = document.body[k].replace(' topline="true" ', ' ')
1374 # this will always be ok
1377 if multirow == True:
1378 add_to_preamble(document,
1379 ["% lyx2lyx multirow additions ", "\\usepackage{multirow}"])
1382 def convert_math_output(document):
1383 " Convert \html_use_mathml to \html_math_output "
1384 i = find_token(document.header, "\\html_use_mathml", 0)
1387 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1388 m = rgx.match(document.header[i])
1389 newval = "0" # MathML
1393 newval = "2" # Images
1395 document.warning("Can't match " + document.header[i])
1396 document.header[i] = "\\html_math_output " + newval
1399 def revert_math_output(document):
1400 " Revert \html_math_output to \html_use_mathml "
1401 i = find_token(document.header, "\\html_math_output", 0)
1404 rgx = re.compile(r'\\html_math_output\s+(\d)')
1405 m = rgx.match(document.header[i])
1409 if val == "1" or val == "2":
1412 document.warning("Unable to match " + document.header[i])
1413 document.header[i] = "\\html_use_mathml " + newval
1417 def revert_inset_preview(document):
1418 " Dissolves the preview inset "
1421 i = find_token(document.body, "\\begin_inset Preview", i)
1424 iend = find_end_of_inset(document.body, i)
1426 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1430 # This has several issues.
1431 # We need to do something about the layouts inside InsetPreview.
1432 # If we just leave the first one, then we have something like:
1433 # \begin_layout Standard
1435 # \begin_layout Standard
1436 # and we get a "no \end_layout" error. So something has to be done.
1437 # Ideally, we would check if it is the same as the layout we are in.
1438 # If so, we just remove it; if not, we end the active one. But it is
1439 # not easy to know what layout we are in, due to depth changes, etc,
1440 # and it is not clear to me how much work it is worth doing. In most
1441 # cases, the layout will probably be the same.
1443 # For the same reason, we have to remove the \end_layout tag at the
1444 # end of the last layout in the inset. Again, that will sometimes be
1445 # wrong, but it will usually be right. To know what to do, we would
1446 # again have to know what layout the inset is in.
1448 blay = find_token(document.body, "\\begin_layout", i, iend)
1450 document.warning("Can't find layout for preview inset!")
1451 # always do the later one first...
1452 del document.body[iend]
1453 del document.body[i]
1454 # deletions mean we do not need to reset i
1457 # This is where we would check what layout we are in.
1458 # The check for Standard is definitely wrong.
1460 # lay = document.body[blay].split(None, 1)[1]
1461 # if lay != oldlayout:
1462 # # record a boolean to tell us what to do later....
1463 # # better to do it later, since (a) it won't mess up
1464 # # the numbering and (b) we only modify at the end.
1466 # we want to delete the last \\end_layout in this inset, too.
1467 # note that this may not be the \\end_layout that goes with blay!!
1468 bend = find_end_of_layout(document.body, blay)
1470 tmp = find_token(document.body, "\\end_layout", bend + 1, iend)
1475 document.warning("Unable to find last layout in preview inset!")
1476 del document.body[iend]
1477 del document.body[i]
1478 # deletions mean we do not need to reset i
1480 # always do the later one first...
1481 del document.body[iend]
1482 del document.body[bend]
1483 del document.body[i:blay + 1]
1484 # we do not need to reset i
1487 def revert_equalspacing_xymatrix(document):
1488 " Revert a Formula with xymatrix@! to an ERT inset "
1490 has_preamble = False
1491 has_equal_spacing = False
1494 i = find_token(document.body, "\\begin_inset Formula", i)
1497 j = find_end_of_inset(document.body, i)
1499 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1503 for curline in range(i,j):
1504 found = document.body[curline].find("\\xymatrix@!")
1509 has_equal_spacing = True
1510 content = [document.body[i][21:]]
1511 content += document.body[i + 1:j]
1512 subst = put_cmd_in_ert(content)
1513 document.body[i:j + 1] = subst
1514 i += len(subst) - (j - i) + 1
1516 for curline in range(i,j):
1517 l = document.body[curline].find("\\xymatrix")
1519 has_preamble = True;
1523 if has_equal_spacing and not has_preamble:
1524 add_to_preamble(document, ['% lyx2lyx xymatrix addition', '\\usepackage[all]{xy}'])
1527 def revert_notefontcolor(document):
1528 " Reverts greyed-out note font color to preamble code "
1530 i = find_token(document.header, "\\notefontcolor", 0)
1533 colorcode = get_value(document.header, '\\notefontcolor', i)
1534 del document.header[i]
1535 # the color code is in the form #rrggbb where every character denotes a hex number
1536 red = hex2ratio(colorcode[1:3])
1537 green = hex2ratio(colorcode[3:5])
1538 blue = hex2ratio(colorcode[5:7])
1539 # write the preamble
1540 insert_to_preamble(0, document,
1541 ['% Commands inserted by lyx2lyx to set the font color',
1542 '% for greyed-out notes',
1543 '\\@ifundefined{definecolor}{\\usepackage{color}}{}'
1544 '\\definecolor{note_fontcolor}{rgb}{'
1545 + str(red) + ', ' + str(green)
1546 + ', ' + str(blue) + '}',
1547 '\\renewenvironment{lyxgreyedout}',
1548 ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}'])
1551 def revert_turkmen(document):
1552 "Set language Turkmen to English"
1554 if document.language == "turkmen":
1555 document.language = "english"
1556 i = find_token(document.header, "\\language", 0)
1558 document.header[i] = "\\language english"
1561 j = find_token(document.body, "\\lang turkmen", j)
1564 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1568 def revert_fontcolor(document):
1569 " Reverts font color to preamble code "
1573 i = find_token(document.header, "\\fontcolor", i)
1576 colorcode = get_value(document.header, '\\fontcolor', 0)
1577 del document.header[i]
1578 # don't clutter the preamble if backgroundcolor is not set
1579 if colorcode == "#000000":
1581 # the color code is in the form #rrggbb where every character denotes a hex number
1582 # convert the string to an int
1583 red = string.atoi(colorcode[1:3],16)
1584 # we want the output "0.5" for the value "127" therefore add here
1587 redout = float(red) / 256
1588 green = string.atoi(colorcode[3:5],16)
1591 greenout = float(green) / 256
1592 blue = string.atoi(colorcode[5:7],16)
1595 blueout = float(blue) / 256
1596 # write the preamble
1597 insert_to_preamble(0, document,
1598 '% Commands inserted by lyx2lyx to set the font color\n'
1599 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1600 + '\\definecolor{document_fontcolor}{rgb}{'
1601 + str(redout) + ', ' + str(greenout)
1602 + ', ' + str(blueout) + '}\n'
1603 + '\\color{document_fontcolor}\n')
1605 def revert_shadedboxcolor(document):
1606 " Reverts shaded box color to preamble code "
1610 i = find_token(document.header, "\\boxbgcolor", i)
1613 colorcode = get_value(document.header, '\\boxbgcolor', 0)
1614 del document.header[i]
1615 # the color code is in the form #rrggbb where every character denotes a hex number
1616 # convert the string to an int
1617 red = string.atoi(colorcode[1:3],16)
1618 # we want the output "0.5" for the value "127" therefore increment here
1621 redout = float(red) / 256
1622 green = string.atoi(colorcode[3:5],16)
1625 greenout = float(green) / 256
1626 blue = string.atoi(colorcode[5:7],16)
1629 blueout = float(blue) / 256
1630 # write the preamble
1631 insert_to_preamble(0, document,
1632 '% Commands inserted by lyx2lyx to set the color\n'
1633 '% of boxes with shaded background\n'
1634 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1635 + '\\definecolor{shadecolor}{rgb}{'
1636 + str(redout) + ', ' + str(greenout)
1637 + ', ' + str(blueout) + '}\n')
1640 def revert_lyx_version(document):
1641 " Reverts LyX Version information from Inset Info "
1642 version = "LyX version"
1644 import lyx2lyx_version
1645 version = lyx2lyx_version.version
1651 i = find_token(document.body, '\\begin_inset Info', i)
1654 j = find_end_of_inset(document.body, i + 1)
1657 document.warning("Malformed LyX document: Could not find end of Info inset.")
1663 # but we shall try to be forgiving.
1665 for k in range(i, j):
1666 if document.body[k].startswith("arg"):
1667 arg = document.body[k][3:].strip().strip('"')
1668 if document.body[k].startswith("type"):
1669 typ = document.body[k][4:].strip().strip('"')
1670 if arg != "version" or typ != "lyxinfo":
1674 # We do not actually know the version of LyX used to produce the document.
1675 # But we can use our version, since we are reverting.
1677 # Now we want to check if the line after "\end_inset" is empty. It normally
1678 # is, so we want to remove it, too.
1680 if document.body[j + 1].strip() == "":
1682 document.body[i: lastline] = s
1686 def revert_math_scale(document):
1687 " Remove math scaling and LaTeX options "
1688 i = find_token(document.header, '\\html_math_img_scale', 0)
1690 del document.header[i]
1691 i = find_token(document.header, '\\html_latex_start', 0)
1693 del document.header[i]
1694 i = find_token(document.header, '\\html_latex_end', 0)
1696 del document.header[i]
1699 def revert_pagesizes(document):
1701 " Revert page sizes to default "
1702 i = find_token(document.header, '\\papersize', 0)
1704 size = document.header[i][11:]
1705 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1706 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1707 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1708 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1709 or size == "b5j" or size == "b6j":
1710 del document.header[i]
1713 def revert_DIN_C_pagesizes(document):
1715 " Revert DIN C page sizes to default "
1716 i = find_token(document.header, '\\papersize', 0)
1718 size = document.header[i][11:]
1719 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1720 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1721 or size == "c6paper":
1722 del document.header[i]
1725 def convert_html_quotes(document):
1726 " Remove quotes around html_latex_start and html_latex_end "
1728 i = find_token(document.header, '\\html_latex_start', 0)
1730 line = document.header[i]
1731 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1734 document.header[i] = "\\html_latex_start " + m.group(1)
1736 i = find_token(document.header, '\\html_latex_end', 0)
1738 line = document.header[i]
1739 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1742 document.header[i] = "\\html_latex_end " + m.group(1)
1745 def revert_html_quotes(document):
1746 " Remove quotes around html_latex_start and html_latex_end "
1748 i = find_token(document.header, '\\html_latex_start', 0)
1750 line = document.header[i]
1751 l = re.compile(r'\\html_latex_start\s+(.*)')
1753 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1755 i = find_token(document.header, '\\html_latex_end', 0)
1757 line = document.header[i]
1758 l = re.compile(r'\\html_latex_end\s+(.*)')
1760 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1763 def revert_output_sync(document):
1764 " Remove forward search options "
1765 i = find_token(document.header, '\\output_sync_macro', 0)
1767 del document.header[i]
1768 i = find_token(document.header, '\\output_sync', 0)
1770 del document.header[i]
1773 def convert_beamer_args(document):
1774 " Convert ERT arguments in Beamer to InsetArguments "
1776 if document.textclass != "beamer" and document.textclass != "article-beamer":
1779 layouts = ("Block", "ExampleBlock", "AlertBlock")
1780 for layout in layouts:
1783 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1786 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1788 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1791 bert = find_token(document.body, '\\begin_inset ERT', blay)
1793 document.warning("Malformed Beamer LyX document: Can't find argument of " + layout + " layout.")
1796 eert = find_end_of_inset(document.body, bert)
1798 document.warning("Malformed LyX document: Can't find end of ERT.")
1802 # So the ERT inset begins at line k and goes to line l. We now wrap it in
1803 # an argument inset.
1804 # Do the end first, so as not to mess up the variables.
1805 document.body[eert + 1:eert + 1] = ['', '\\end_layout', '', '\\end_inset', '']
1806 document.body[bert:bert] = ['\\begin_inset OptArg', 'status open', '',
1807 '\\begin_layout Plain Layout']
1811 def revert_beamer_args(document):
1812 " Revert Beamer arguments to ERT "
1814 if document.textclass != "beamer" and document.textclass != "article-beamer":
1817 layouts = ("Block", "ExampleBlock", "AlertBlock")
1818 for layout in layouts:
1821 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1824 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1826 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1829 bopt = find_token(document.body, '\\begin_inset OptArg', blay)
1831 # it is legal not to have one of these
1834 eopt = find_end_of_inset(document.body, bopt)
1836 document.warning("Malformed LyX document: Can't find end of argument.")
1839 bplay = find_token(document.body, '\\begin_layout Plain Layout', blay)
1841 document.warning("Malformed LyX document: Can't find plain layout.")
1844 eplay = find_end_of(document.body, bplay, '\\begin_layout', '\\end_layout')
1846 document.warning("Malformed LyX document: Can't find end of plain layout.")
1849 # So the content of the argument inset goes from bplay + 1 to eplay - 1
1853 document.warning(str(bcont) + " " + str(eplay))
1856 # we convert the content of the argument into pure LaTeX...
1857 content = lyx2latex(document, document.body[bcont:eplay])
1858 strlist = put_cmd_in_ert(["{" + content + "}"])
1860 # now replace the optional argument with the ERT
1861 document.body[bopt:eopt + 1] = strlist
1865 def revert_align_decimal(document):
1868 l = document.body[l].find('alignment=decimal')
1871 remove_option(document, l, 'decimal_point')
1872 document.body[l].replace('decimal', 'center')
1875 def convert_optarg(document):
1876 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1879 i = find_token(document.body, '\\begin_inset OptArg', i)
1882 document.body[i] = "\\begin_inset Argument"
1886 def revert_argument(document):
1887 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1890 i = find_token(document.body, '\\begin_inset Argument', i)
1893 document.body[i] = "\\begin_inset OptArg"
1897 def revert_makebox(document):
1898 " Convert \\makebox to TeX code "
1901 # only revert frameless boxes without an inner box
1902 i = find_token(document.body, '\\begin_inset Box Frameless', i)
1904 # remove the option use_makebox
1905 revert_use_makebox(document)
1907 z = find_end_of_inset(document.body, i)
1909 document.warning("Malformed LyX document: Can't find end of box inset.")
1911 j = find_token(document.body, 'use_makebox 1', i)
1912 # assure we found the makebox of the current box
1913 if j < z and j != -1:
1914 y = find_token(document.body, "\\begin_layout", i)
1915 if y > z or y == -1:
1916 document.warning("Malformed LyX document: Can't find layout in box.")
1918 # remove the \end_layout \end_inset pair
1919 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
1920 # determine the alignment
1921 k = find_token(document.body, 'hor_pos', j - 4)
1922 align = document.body[k][9]
1923 # determine the width
1924 l = find_token(document.body, 'width "', j + 1)
1925 length = document.body[l][7:]
1926 # remove trailing '"'
1927 length = length[:-1]
1928 length = latex_length(length)[1]
1929 subst = "\\makebox[" + length + "][" \
1931 document.body[i:y + 1] = put_cmd_in_ert(subst)
1935 def revert_use_makebox(document):
1936 " Deletes use_makebox option of boxes "
1939 # remove the option use_makebox
1940 h = find_token(document.body, 'use_makebox', 0)
1943 del document.body[h]
1947 def convert_use_makebox(document):
1948 " Adds use_makebox option for boxes "
1951 # remove the option use_makebox
1952 i = find_token(document.body, '\\begin_inset Box', i)
1955 k = find_token(document.body, 'use_parbox', i)
1957 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1959 document.body.insert(k + 1, "use_makebox 0")
1963 def revert_IEEEtran(document):
1964 " Convert IEEEtran layouts and styles to TeX code "
1965 if document.textclass != "IEEEtran":
1967 revert_flex_inset(document, "IEEE membership", "\\IEEEmembership", 0)
1968 revert_flex_inset(document, "Lowercase", "\\MakeLowercase", 0)
1969 layouts = ("Special Paper Notice", "After Title Text", "Publication ID",
1970 "Page headings", "Biography without photo")
1971 latexcmd = {"Special Paper Notice": "\\IEEEspecialpapernotice",
1972 "After Title Text": "\\IEEEaftertitletext",
1973 "Publication ID": "\\IEEEpubid"}
1974 obsoletedby = {"Page headings": "MarkBoth",
1975 "Biography without photo": "BiographyNoPhoto"}
1976 for layout in layouts:
1979 i = find_token(document.body, '\\begin_layout ' + layout, i)
1982 j = find_end_of(document.body, i, '\\begin_layout', '\\end_layout')
1984 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1987 if layout in obsoletedby:
1988 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1991 content = lyx2latex(document, document.body[i:j + 1])
1992 add_to_preamble(document, [latexcmd[layout] + "{" + content + "}"])
1993 del document.body[i:j + 1]
1996 def convert_prettyref(document):
1997 " Converts prettyref references to neutral formatted refs "
1998 re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
1999 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
2003 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
2006 j = find_end_of_inset(document.body, i)
2008 document.warning("Malformed LyX document: No end of InsetRef!")
2011 k = find_token(document.body, "LatexCommand prettyref", i)
2012 if k != -1 and k < j:
2013 document.body[k] = "LatexCommand formatted"
2015 document.header.insert(-1, "\\use_refstyle 0")
2018 def revert_refstyle(document):
2019 " Reverts neutral formatted refs to prettyref "
2020 re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
2021 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
2025 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
2028 j = find_end_of_inset(document.body, i)
2030 document.warning("Malformed LyX document: No end of InsetRef")
2033 k = find_token(document.body, "LatexCommand formatted", i)
2034 if k != -1 and k < j:
2035 document.body[k] = "LatexCommand prettyref"
2037 i = find_token(document.header, "\\use_refstyle", 0)
2039 document.header.pop(i)
2042 def revert_nameref(document):
2043 " Convert namerefs to regular references "
2044 cmds = ["Nameref", "nameref"]
2046 rx = re.compile(r'reference "(.*)"')
2049 oldcmd = "LatexCommand " + cmd
2051 # It seems better to look for this, as most of the reference
2052 # insets won't be ones we care about.
2053 i = find_token(document.body, oldcmd, i)
2058 # Make sure it is actually in an inset!
2059 # We could just check document.lines[i-1], but that relies
2060 # upon something that might easily change.
2061 # We'll look back a few lines.
2065 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2066 if stins == -1 or stins > cmdloc:
2068 endins = find_end_of_inset(document.body, stins)
2070 document.warning("Can't find end of inset at line " + stins + "!!")
2074 refline = find_token(document.body, "reference", stins)
2075 if refline == -1 or refline > endins:
2076 document.warning("Can't find reference for inset at line " + stinst + "!!")
2078 m = rx.match(document.body[refline])
2080 document.warning("Can't match reference line: " + document.body[ref])
2084 newcontent = ['\\begin_inset ERT', 'status collapsed', '', \
2085 '\\begin_layout Plain Layout', '', '\\backslash', \
2086 cmd + '{' + ref + '}', '\\end_layout', '', '\\end_inset']
2087 document.body[stins:endins + 1] = newcontent
2089 add_to_preamble(document, "\usepackage{nameref}")
2092 def remove_Nameref(document):
2093 " Convert Nameref commands to nameref commands "
2096 # It seems better to look for this, as most of the reference
2097 # insets won't be ones we care about.
2098 i = find_token(document.body, "LatexCommand Nameref" , i)
2104 # Make sure it is actually in an inset!
2105 # We could just check document.lines[i-1], but that relies
2106 # upon something that might easily change.
2107 # We'll look back a few lines.
2111 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2112 if stins == -1 or stins > cmdloc:
2114 endins = find_end_of_inset(document.body, stins)
2116 document.warning("Can't find end of inset at line " + stins + "!!")
2120 document.body[cmdloc] = "LatexCommand nameref"
2123 def revert_mathrsfs(document):
2124 " Load mathrsfs if \mathrsfs us use in the document "
2126 end = len(document.body) - 1
2128 j = document.body[i].find("\\mathscr{")
2130 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2131 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
2138 def convert_flexnames(document):
2139 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
2142 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
2144 i = find_token(document.body, "\\begin_inset Flex", i)
2147 m = rx.match(document.body[i])
2149 document.body[i] = "\\begin_inset Flex " + m.group(1)
2154 ["Alert", "CharStyle:Alert"],
2155 ["Code", "CharStyle:Code"],
2156 ["Concepts", "CharStyle:Concepts"],
2157 ["E-Mail", "CharStyle:E-Mail"],
2158 ["Emph", "CharStyle:Emph"],
2159 ["Expression", "CharStyle:Expression"],
2160 ["Initial", "CharStyle:Initial"],
2161 ["Institute", "CharStyle:Institute"],
2162 ["Meaning", "CharStyle:Meaning"],
2163 ["Noun", "CharStyle:Noun"],
2164 ["Strong", "CharStyle:Strong"],
2165 ["Structure", "CharStyle:Structure"],
2166 ["ArticleMode", "Custom:ArticleMode"],
2167 ["Endnote", "Custom:Endnote"],
2168 ["Glosse", "Custom:Glosse"],
2169 ["PresentationMode", "Custom:PresentationMode"],
2170 ["Tri-Glosse", "Custom:Tri-Glosse"]
2174 ["Abbrev", "Element:Abbrev"],
2175 ["CCC-Code", "Element:CCC-Code"],
2176 ["Citation-number", "Element:Citation-number"],
2177 ["City", "Element:City"],
2178 ["Code", "Element:Code"],
2179 ["CODEN", "Element:CODEN"],
2180 ["Country", "Element:Country"],
2181 ["Day", "Element:Day"],
2182 ["Directory", "Element:Directory"],
2183 ["Dscr", "Element:Dscr"],
2184 ["Email", "Element:Email"],
2185 ["Emph", "Element:Emph"],
2186 ["Filename", "Element:Filename"],
2187 ["Firstname", "Element:Firstname"],
2188 ["Fname", "Element:Fname"],
2189 ["GuiButton", "Element:GuiButton"],
2190 ["GuiMenu", "Element:GuiMenu"],
2191 ["GuiMenuItem", "Element:GuiMenuItem"],
2192 ["ISSN", "Element:ISSN"],
2193 ["Issue-day", "Element:Issue-day"],
2194 ["Issue-months", "Element:Issue-months"],
2195 ["Issue-number", "Element:Issue-number"],
2196 ["KeyCap", "Element:KeyCap"],
2197 ["KeyCombo", "Element:KeyCombo"],
2198 ["Keyword", "Element:Keyword"],
2199 ["Literal", "Element:Literal"],
2200 ["MenuChoice", "Element:MenuChoice"],
2201 ["Month", "Element:Month"],
2202 ["Orgdiv", "Element:Orgdiv"],
2203 ["Orgname", "Element:Orgname"],
2204 ["Postcode", "Element:Postcode"],
2205 ["SS-Code", "Element:SS-Code"],
2206 ["SS-Title", "Element:SS-Title"],
2207 ["State", "Element:State"],
2208 ["Street", "Element:Street"],
2209 ["Surname", "Element:Surname"],
2210 ["Volume", "Element:Volume"],
2211 ["Year", "Element:Year"]
2215 def revert_flexnames(document):
2216 if document.backend == "latex":
2217 flexlist = flex_insets
2219 flexlist = flex_elements
2221 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
2224 i = find_token(document.body, "\\begin_inset Flex", i)
2227 m = rx.match(document.body[i])
2229 document.warning("Illegal flex inset: " + document.body[i])
2236 document.body[i] = "\\begin_inset Flex " + f[1]
2242 def convert_mathdots(document):
2243 " Load mathdots automatically "
2245 i = find_token(document.header, "\\use_esint" , 0)
2247 document.header.insert(i + 1, "\\use_mathdots 1")
2251 def revert_mathdots(document):
2252 " Load mathdots if used in the document "
2254 ddots = re.compile(r'\\begin_inset Formula .*\\ddots', re.DOTALL)
2255 vdots = re.compile(r'\\begin_inset Formula .*\\vdots', re.DOTALL)
2256 iddots = re.compile(r'\\begin_inset Formula .*\\iddots', re.DOTALL)
2257 mathdots = find_token(document.header, "\\use_mathdots" , 0)
2258 no = find_token(document.header, "\\use_mathdots 0" , 0)
2259 auto = find_token(document.header, "\\use_mathdots 1" , 0)
2260 yes = find_token(document.header, "\\use_mathdots 2" , 0)
2262 del document.header[mathdots]
2264 i = find_token(document.body, '\\begin_inset Formula', i)
2267 j = find_end_of_inset(document.body, i)
2269 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2271 k = ddots.search("\n".join(document.body[i:j]))
2272 l = vdots.search("\n".join(document.body[i:j]))
2273 m = iddots.search("\n".join(document.body[i:j]))
2274 if (yes == -1) and ((no != -1) or (not k and not l and not m) or (auto != -1 and not m)):
2277 # use \@ifundefined to catch also the "auto" case
2278 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2279 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}\n"])
2283 def convert_rule(document):
2284 " Convert \\lyxline to CommandInset line "
2287 i = find_token(document.body, "\\lyxline" , i)
2291 j = find_token(document.body, "\\color" , i - 2)
2293 color = document.body[j] + '\n'
2296 k = find_token(document.body, "\\begin_layout Standard" , i - 4)
2297 # we need to handle the case that \lyxline is in a separate paragraph and that it is colored
2298 # the result is then an extra empty paragraph which we get by adding an empty ERT inset
2299 if k == i - 4 and j == i - 2 and document.body[i - 1] == '':
2300 layout = '\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n\n\\end_layout\n\n\\end_inset\n' \
2301 + '\\end_layout\n\n' \
2302 + '\\begin_layout Standard\n'
2303 elif k == i - 2 and document.body[i - 1] == '':
2306 layout = '\\end_layout\n\n' \
2307 + '\\begin_layout Standard\n'
2308 l = find_token(document.body, "\\begin_layout Standard" , i + 4)
2309 if l == i + 4 and document.body[i + 1] == '':
2312 layout2 = '\\end_layout\n' \
2313 + '\n\\begin_layout Standard\n'
2315 + '\\noindent\n\n' \
2317 + '\\begin_inset CommandInset line\n' \
2318 + 'LatexCommand rule\n' \
2319 + 'offset "0.5ex"\n' \
2320 + 'width "100line%"\n' \
2321 + 'height "1pt"\n' \
2322 + '\n\\end_inset\n\n\n' \
2324 document.body[i] = subst
2328 def revert_rule(document):
2329 " Revert line insets to Tex code "
2332 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
2336 j = find_token(document.body, "\\end_inset" , i)
2337 # assure we found the end_inset of the current inset
2338 if j > i + 6 or j == -1:
2339 document.warning("Malformed LyX document: Can't find end of line inset.")
2341 # determine the optional offset
2342 k = find_token(document.body, 'offset', i, j)
2344 offset = document.body[k][8:-1]
2347 # determine the width
2348 l = find_token(document.body, 'width', i, j)
2350 width = document.body[l][7:-1]
2353 # determine the height
2354 m = find_token(document.body, 'height', i, j)
2356 height = document.body[m][8:-1]
2359 # output the \rule command
2361 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
2363 subst = "\\rule{" + width + "}{" + height + "}"
2364 document.body[i:j + 1] = put_cmd_in_ert(subst)
2368 def revert_diagram(document):
2369 " Add the feyn package if \\Diagram is used in math "
2371 re_diagram = re.compile(r'\\begin_inset Formula .*\\Diagram', re.DOTALL)
2373 i = find_token(document.body, '\\begin_inset Formula', i)
2376 j = find_end_of_inset(document.body, i)
2378 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2380 m = re_diagram.search("\n".join(document.body[i:j]))
2384 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2385 add_to_preamble(document, "\\usepackage{feyn}")
2386 # only need to do it once!
2390 def convert_bibtex_clearpage(document):
2391 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2393 i = find_token(document.header, '\\papersides', 0)
2395 document.warning("Malformed LyX document: Can't find papersides definition.")
2397 sides = int(document.header[i][12])
2401 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2405 k = find_end_of_inset(document.body, j)
2407 document.warning("Can't find end of Bibliography inset at line " + str(j))
2411 # only act if there is the option "bibtotoc"
2412 m = find_token(document.body, 'options', j, k)
2414 document.warning("Can't find options for bibliography inset at line " + str(j))
2418 optline = document.body[m]
2419 idx = optline.find("bibtotoc")
2424 # so we want to insert a new page right before the paragraph that
2425 # this bibliography thing is in. we'll look for it backwards.
2428 if document.body[lay].startswith("\\begin_layout"):
2433 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2437 subst1 = '\\begin_layout Standard\n' \
2438 + '\\begin_inset Newpage clearpage\n' \
2439 + '\\end_inset\n\n\n' \
2441 subst2 = '\\begin_layout Standard\n' \
2442 + '\\begin_inset Newpage cleardoublepage\n' \
2443 + '\\end_inset\n\n\n' \
2446 document.body.insert(lay, subst1)
2447 document.warning(subst1)
2449 document.body.insert(lay, subst2)
2450 document.warning(subst2)
2459 supported_versions = ["2.0.0","2.0"]
2460 convert = [[346, []],
2466 [352, [convert_splitindex]],
2473 [359, [convert_nomencl_width]],
2483 [369, [convert_author_id]],
2487 [373, [merge_gbrief]],
2493 [379, [convert_math_output]],
2503 [389, [convert_html_quotes]],
2507 [393, [convert_optarg]],
2508 [394, [convert_use_makebox]],
2511 [397, [remove_Nameref]],
2513 [399, [convert_mathdots]],
2514 [400, [convert_rule]],
2516 [402, [convert_bibtex_clearpage]],
2517 [403, [convert_flexnames]],
2518 [404, [convert_prettyref]]
2521 revert = [[403, [revert_refstyle]],
2522 [402, [revert_flexnames]],
2524 [400, [revert_diagram]],
2525 [399, [revert_rule]],
2526 [398, [revert_mathdots]],
2527 [397, [revert_mathrsfs]],
2529 [395, [revert_nameref]],
2530 [394, [revert_DIN_C_pagesizes]],
2531 [393, [revert_makebox]],
2532 [392, [revert_argument]],
2533 [391, [revert_beamer_args]],
2534 [390, [revert_align_decimal, revert_IEEEtran]],
2535 [389, [revert_output_sync]],
2536 [388, [revert_html_quotes]],
2537 [387, [revert_pagesizes]],
2538 [386, [revert_math_scale]],
2539 [385, [revert_lyx_version]],
2540 [384, [revert_shadedboxcolor]],
2541 [383, [revert_fontcolor]],
2542 [382, [revert_turkmen]],
2543 [381, [revert_notefontcolor]],
2544 [380, [revert_equalspacing_xymatrix]],
2545 [379, [revert_inset_preview]],
2546 [378, [revert_math_output]],
2548 [376, [revert_multirow]],
2549 [375, [revert_includeall]],
2550 [374, [revert_includeonly]],
2551 [373, [revert_html_options]],
2552 [372, [revert_gbrief]],
2553 [371, [revert_fontenc]],
2554 [370, [revert_mhchem]],
2555 [369, [revert_suppress_date]],
2556 [368, [revert_author_id]],
2557 [367, [revert_hspace_glue_lengths]],
2558 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2559 [365, [revert_percent_skip_lengths]],
2560 [364, [revert_paragraph_indentation]],
2561 [363, [revert_branch_filename]],
2562 [362, [revert_longtable_align]],
2563 [361, [revert_applemac]],
2565 [359, [revert_nomencl_cwidth]],
2566 [358, [revert_nomencl_width]],
2567 [357, [revert_custom_processors]],
2568 [356, [revert_ulinelatex]],
2570 [354, [revert_strikeout]],
2571 [353, [revert_printindexall]],
2572 [352, [revert_subindex]],
2573 [351, [revert_splitindex]],
2574 [350, [revert_backgroundcolor]],
2575 [349, [revert_outputformat]],
2576 [348, [revert_xetex]],
2577 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2578 [346, [revert_tabularvalign]],
2579 [345, [revert_swiss]]
2583 if __name__ == "__main__":