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 ''' removes option from line m. returns whether we did anything '''
33 l = document.body[m].find(option)
36 val = document.body[m][l:].split('"')[1]
37 document.body[m] = document.body[m][:l - 1] + document.body[m][l+len(option + '="' + val + '"'):]
41 def find_end_of_inset(lines, i):
42 " Find end of inset, where lines[i] is included."
43 return find_end_of(lines, i, "\\begin_inset", "\\end_inset")
46 def find_end_of_layout(lines, i):
47 " Find end of layout, where lines[i] is included."
48 return find_end_of(lines, i, "\\begin_layout", "\\end_layout")
51 # Note that text can be either a list of lines or a single line.
52 def add_to_preamble(document, text):
53 """ Add text to the preamble if it is not already there.
54 Only the first line is checked!"""
56 if not type(text) is list:
57 # split on \n just in case
58 # it'll give us the one element list we want
59 # if there's no \n, too
60 text = text.split('\n')
62 if find_token(document.preamble, text[0], 0) != -1:
65 document.preamble.extend(text)
68 # Note that text can be either a list of lines or a single line.
69 # It should really be a list.
70 def insert_to_preamble(index, document, text):
71 """ Insert text to the preamble at a given line"""
73 if not type(text) is list:
74 # split on \n just in case
75 # it'll give us the one element list we want
76 # if there's no \n, too
77 text = text.split('\n')
79 document.preamble[index:index] = text
82 def read_unicodesymbols():
83 " Read the unicodesymbols list of unicode characters and corresponding commands."
84 pathname = os.path.abspath(os.path.dirname(sys.argv[0]))
85 fp = open(os.path.join(pathname.strip('lyx2lyx'), 'unicodesymbols'))
87 # Two backslashes, followed by some non-word character, and then a character
88 # in brackets. The idea is to check for constructs like: \"{u}, which is how
89 # they are written in the unicodesymbols file; but they can also be written
90 # as: \"u or even \" u.
91 r = re.compile(r'\\\\(\W)\{(\w)\}')
92 for line in fp.readlines():
93 if line[0] != '#' and line.strip() != "":
94 line=line.replace(' "',' ') # remove all quotation marks with spaces before
95 line=line.replace('" ',' ') # remove all quotation marks with spaces after
96 line=line.replace(r'\"','"') # replace \" by " (for characters with diaeresis)
98 [ucs4,command,dead] = line.split(None,2)
99 if command[0:1] != "\\":
101 spec_chars.append([command, unichr(eval(ucs4))])
107 # If the character is a double-quote, then we need to escape it, too,
108 # since it is done that way in the LyX file.
109 if m.group(1) == "\"":
112 command += m.group(1) + m.group(2)
113 commandbl += m.group(1) + ' ' + m.group(2)
114 spec_chars.append([command, unichr(eval(ucs4))])
115 spec_chars.append([commandbl, unichr(eval(ucs4))])
120 unicode_reps = read_unicodesymbols()
123 # DO NOT USE THIS ROUTINE ANY MORE. Better yet, replace the uses that
124 # have been made of it with uses of put_cmd_in_ert.
125 def old_put_cmd_in_ert(string):
126 for rep in unicode_reps:
127 string = string.replace(rep[1], rep[0].replace('\\\\', '\\'))
128 string = string.replace('\\', "\\backslash\n")
129 string = "\\begin_inset ERT\nstatus collapsed\n\\begin_layout Plain Layout\n" \
130 + string + "\n\\end_layout\n\\end_inset"
134 # This routine wraps some content in an ERT inset.
136 # NOTE: The function accepts either a single string or a LIST of strings as
137 # argument. But it returns a LIST of strings, split on \n, so that it does
138 # not have embedded newlines.
140 # This is how lyx2lyx represents a LyX document: as a list of strings,
141 # each representing a line of a LyX file. Embedded newlines confuse
144 # A call to this routine will often go something like this:
145 # i = find_token('\\begin_inset FunkyInset', ...)
147 # j = find_end_of_inset(document.body, i)
148 # content = ...extract content from insets
149 # # that could be as simple as:
150 # # content = lyx2latex(document[i:j + 1])
151 # ert = put_cmd_in_ert(content)
152 # document.body[i:j] = ert
153 # Now, before we continue, we need to reset i appropriately. Normally,
156 # That puts us right after the ERT we just inserted.
158 def put_cmd_in_ert(arg):
159 ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
160 # Despite the warnings just given, it will be faster for us to work
161 # with a single string internally. That way, we only go through the
162 # unicode_reps loop once.
163 if type(arg) is list:
167 for rep in unicode_reps:
168 s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
169 s = s.replace('\\', "\\backslash\n")
170 ret += s.splitlines()
171 ret += ["\\end_layout", "\\end_inset"]
175 def lyx2latex(document, lines):
176 'Convert some LyX stuff into corresponding LaTeX stuff, as best we can.'
177 # clean up multiline stuff
183 for curline in range(len(lines)):
184 line = lines[curline]
185 if line.startswith("\\begin_inset Note Note"):
186 # We want to skip LyX notes, so remember where the inset ends
187 note_end = find_end_of_inset(lines, curline + 1)
189 elif note_end >= curline:
192 elif line.startswith("\\begin_inset ERT"):
193 # We don't want to replace things inside ERT, so figure out
194 # where the end of the inset is.
195 ert_end = find_end_of_inset(lines, curline + 1)
197 elif line.startswith("\\begin_inset Formula"):
199 elif line.startswith("\\begin_inset Quotes"):
200 # For now, we do a very basic reversion. Someone who understands
201 # quotes is welcome to fix it up.
202 qtype = line[20:].strip()
216 elif line.startswith("\\begin_inset space"):
217 line = line[18:].strip()
218 if line.startswith("\\hspace"):
219 # Account for both \hspace and \hspace*
222 elif line == "\\space{}":
224 elif line == "\\thinspace{}":
227 # The LyX length is in line[8:], after the \length keyword
228 length = latex_length(line[8:])[1]
229 line = hspace + "{" + length + "}"
231 elif line.isspace() or \
232 line.startswith("\\begin_layout") or \
233 line.startswith("\\end_layout") or \
234 line.startswith("\\begin_inset") or \
235 line.startswith("\\end_inset") or \
236 line.startswith("\\lang") or \
237 line.strip() == "status collapsed" or \
238 line.strip() == "status open":
242 # this needs to be added to the preamble because of cases like
243 # \textmu, \textbackslash, etc.
244 add_to_preamble(document, ['% added by lyx2lyx for converted index entries',
245 '\\@ifundefined{textmu}',
246 ' {\\usepackage{textcomp}}{}'])
247 # a lossless reversion is not possible
248 # try at least to handle some common insets and settings
249 if ert_end >= curline:
250 line = line.replace(r'\backslash', '\\')
252 # No need to add "{}" after single-nonletter macros
253 line = line.replace('&', '\\&')
254 line = line.replace('#', '\\#')
255 line = line.replace('^', '\\textasciicircum{}')
256 line = line.replace('%', '\\%')
257 line = line.replace('_', '\\_')
258 line = line.replace('$', '\\$')
260 # Do the LyX text --> LaTeX conversion
261 for rep in unicode_reps:
262 line = line.replace(rep[1], rep[0] + "{}")
263 line = line.replace(r'\backslash', r'\textbackslash{}')
264 line = line.replace(r'\series bold', r'\bfseries{}').replace(r'\series default', r'\mdseries{}')
265 line = line.replace(r'\shape italic', r'\itshape{}').replace(r'\shape smallcaps', r'\scshape{}')
266 line = line.replace(r'\shape slanted', r'\slshape{}').replace(r'\shape default', r'\upshape{}')
267 line = line.replace(r'\emph on', r'\em{}').replace(r'\emph default', r'\em{}')
268 line = line.replace(r'\noun on', r'\scshape{}').replace(r'\noun default', r'\upshape{}')
269 line = line.replace(r'\bar under', r'\underbar{').replace(r'\bar default', r'}')
270 line = line.replace(r'\family sans', r'\sffamily{}').replace(r'\family default', r'\normalfont{}')
271 line = line.replace(r'\family typewriter', r'\ttfamily{}').replace(r'\family roman', r'\rmfamily{}')
272 line = line.replace(r'\InsetSpace ', r'').replace(r'\SpecialChar ', r'')
277 def latex_length(slen):
279 Convert lengths to their LaTeX representation. Returns (bool, length),
280 where the bool tells us if it was a percentage, and the length is the
281 LaTeX representation.
285 # the slen has the form
286 # ValueUnit+ValueUnit-ValueUnit or
287 # ValueUnit+-ValueUnit
288 # the + and - (glue lengths) are optional
289 # the + always precedes the -
291 # Convert relative lengths to LaTeX units
292 units = {"text%":"\\textwidth", "col%":"\\columnwidth",
293 "page%":"\\paperwidth", "line%":"\\linewidth",
294 "theight%":"\\textheight", "pheight%":"\\paperheight"}
295 for unit in units.keys():
300 minus = slen.rfind("-", 1, i)
301 plus = slen.rfind("+", 0, i)
302 latex_unit = units[unit]
303 if plus == -1 and minus == -1:
305 value = str(float(value)/100)
306 end = slen[i + len(unit):]
307 slen = value + latex_unit + end
309 value = slen[plus + 1:i]
310 value = str(float(value)/100)
311 begin = slen[:plus + 1]
312 end = slen[i+len(unit):]
313 slen = begin + value + latex_unit + end
315 value = slen[minus + 1:i]
316 value = str(float(value)/100)
317 begin = slen[:minus + 1]
318 slen = begin + value + latex_unit
320 # replace + and -, but only if the - is not the first character
321 slen = slen[0] + slen[1:].replace("+", " plus ").replace("-", " minus ")
322 # handle the case where "+-1mm" was used, because LaTeX only understands
323 # "plus 1mm minus 1mm"
324 if slen.find("plus minus"):
325 lastvaluepos = slen.rfind(" ")
326 lastvalue = slen[lastvaluepos:]
327 slen = slen.replace(" ", lastvalue + " ")
328 return (percent, slen)
331 def revert_flex_inset(document, name, LaTeXname, position):
332 " Convert flex insets to TeX code "
335 i = find_token(document.body, '\\begin_inset Flex ' + name, i)
338 z = find_end_of_inset(document.body, i)
340 document.warning("Malformed LyX document: Can't find end of Flex " + name + " inset.")
342 # remove the \end_inset
343 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
344 # we need to reset character layouts if necessary
345 j = find_token(document.body, '\\emph on', i, z)
346 k = find_token(document.body, '\\noun on', i, z)
347 l = find_token(document.body, '\\series', i, z)
348 m = find_token(document.body, '\\family', i, z)
349 n = find_token(document.body, '\\shape', i, z)
350 o = find_token(document.body, '\\color', i, z)
351 p = find_token(document.body, '\\size', i, z)
352 q = find_token(document.body, '\\bar under', i, z)
353 r = find_token(document.body, '\\uuline on', i, z)
354 s = find_token(document.body, '\\uwave on', i, z)
355 t = find_token(document.body, '\\strikeout on', i, z)
357 document.body.insert(z - 2, "\\emph default")
359 document.body.insert(z - 2, "\\noun default")
361 document.body.insert(z - 2, "\\series default")
363 document.body.insert(z - 2, "\\family default")
365 document.body.insert(z - 2, "\\shape default")
367 document.body.insert(z - 2, "\\color inherit")
369 document.body.insert(z - 2, "\\size default")
371 document.body.insert(z - 2, "\\bar default")
373 document.body.insert(z - 2, "\\uuline default")
375 document.body.insert(z - 2, "\\uwave default")
377 document.body.insert(z - 2, "\\strikeout default")
378 document.body[i:i + 4] = put_cmd_in_ert(LaTeXname + "{")
382 def revert_font_attrs(document, name, LaTeXname):
383 " Reverts font changes to TeX code "
387 i = find_token(document.body, name + ' on', i)
390 j = find_token(document.body, name + ' default', i)
391 k = find_token(document.body, name + ' on', i + 1)
392 # if there is no default set, the style ends with the layout
393 # assure hereby that we found the correct layout end
394 if j != -1 and (j < k or k == -1):
395 document.body[j:j + 1] = put_cmd_in_ert("}")
397 j = find_token(document.body, '\\end_layout', i)
398 document.body[j:j] = put_cmd_in_ert("}")
399 document.body[i:i + 1] = put_cmd_in_ert(LaTeXname + "{")
404 def revert_layout_command(document, name, LaTeXname, position):
405 " Reverts a command from a layout to TeX code "
408 i = find_token(document.body, '\\begin_layout ' + name, i)
412 # find the next layout
415 j = find_token(document.body, '\\begin_layout', j)
416 l = len(document.body)
417 # if nothing was found it was the last layout of the document
419 document.body[l - 4:l - 4] = put_cmd_in_ert("}")
421 # exclude plain layout because this can be TeX code or another inset
422 elif document.body[j] != '\\begin_layout Plain Layout':
423 document.body[j - 2:j - 2] = put_cmd_in_ert("}")
427 document.body[i] = '\\begin_layout Standard'
428 document.body[i + 1:i + 1] = put_cmd_in_ert(LaTeXname + "{")
433 val = string.atoi(s, 16)
436 return str(val / 256.0)
439 ###############################################################################
441 ### Conversion and reversion routines
443 ###############################################################################
445 def revert_swiss(document):
446 " Set language german-ch to ngerman "
448 if document.language == "german-ch":
449 document.language = "ngerman"
450 i = find_token(document.header, "\\language", 0)
452 document.header[i] = "\\language ngerman"
455 j = find_token(document.body, "\\lang german-ch", j)
458 document.body[j] = document.body[j].replace("\\lang german-ch", "\\lang ngerman")
462 def revert_tabularvalign(document):
463 " Revert the tabular valign option "
466 i = find_token(document.body, "\\begin_inset Tabular", i)
469 end = find_end_of_inset(document.body, i)
471 document.warning("Can't find end of inset at line " + str(i))
474 fline = find_token(document.body, "<features", i, end)
476 document.warning("Can't find features for inset at line " + str(i))
479 p = document.body[fline].find("islongtable")
481 q = document.body[fline].find("tabularvalignment")
484 # This seems wrong: It removes everything after
485 # tabularvalignment, too.
486 document.body[fline] = document.body[fline][:q - 1] + '>'
491 tabularvalignment = 'c'
492 # which valignment is specified?
493 m = document.body[fline].find('tabularvalignment="top"')
495 tabularvalignment = 't'
496 m = document.body[fline].find('tabularvalignment="bottom"')
498 tabularvalignment = 'b'
499 # delete tabularvalignment
500 q = document.body[fline].find("tabularvalignment")
503 # This seems wrong: It removes everything after
504 # tabularvalignment, too.
505 document.body[fline] = document.body[fline][:q - 1] + '>'
507 # don't add a box when centered
508 if tabularvalignment == 'c':
511 subst = ['\\end_layout', '\\end_inset']
512 document.body[end:end] = subst # just inserts those lines
513 subst = ['\\begin_inset Box Frameless',
514 'position "' + tabularvalignment +'"',
519 # we don't know the width, assume 50%
523 'height_special "totalheight"',
526 '\\begin_layout Plain Layout']
527 document.body[i:i] = subst # this just inserts the array at i
528 # since there could be a tabular inside a tabular, we cannot
533 def revert_phantom_types(document, ptype, cmd):
534 " Reverts phantom to ERT "
537 i = find_token(document.body, "\\begin_inset Phantom " + ptype, i)
540 end = find_end_of_inset(document.body, i)
542 document.warning("Can't find end of inset at line " + str(i))
545 blay = find_token(document.body, "\\begin_layout Plain Layout", i, end)
547 document.warning("Can't find layout for inset at line " + str(i))
550 bend = find_token(document.body, "\\end_layout", blay, end)
552 document.warning("Malformed LyX document: Could not find end of Phantom inset's layout.")
555 substi = ["\\begin_inset ERT", "status collapsed", "",
556 "\\begin_layout Plain Layout", "", "", "\\backslash",
557 cmd + "{", "\\end_layout", "", "\\end_inset"]
558 substj = ["\\size default", "", "\\begin_inset ERT", "status collapsed", "",
559 "\\begin_layout Plain Layout", "", "}", "\\end_layout", "", "\\end_inset"]
560 # do the later one first so as not to mess up the numbering
561 document.body[bend:end + 1] = substj
562 document.body[i:blay + 1] = substi
563 i = end + len(substi) + len(substj) - (end - bend) - (blay - i) - 2
566 def revert_phantom(document):
567 revert_phantom_types(document, "Phantom", "phantom")
569 def revert_hphantom(document):
570 revert_phantom_types(document, "HPhantom", "hphantom")
572 def revert_vphantom(document):
573 revert_phantom_types(document, "VPhantom", "vphantom")
576 def revert_xetex(document):
577 " Reverts documents that use XeTeX "
578 i = find_token(document.header, '\\use_xetex', 0)
580 document.warning("Malformed LyX document: Missing \\use_xetex.")
582 if get_value(document.header, "\\use_xetex", i) == 'false':
583 del document.header[i]
585 del document.header[i]
586 # 1.) set doc encoding to utf8-plain
587 i = find_token(document.header, "\\inputencoding", 0)
589 document.warning("Malformed LyX document: Missing \\inputencoding.")
590 document.header[i] = "\\inputencoding utf8-plain"
591 # 2.) check font settings
592 l = find_token(document.header, "\\font_roman", 0)
594 document.warning("Malformed LyX document: Missing \\font_roman.")
595 line = document.header[l]
596 l = re.compile(r'\\font_roman (.*)$')
599 l = find_token(document.header, "\\font_sans", 0)
601 document.warning("Malformed LyX document: Missing \\font_sans.")
602 line = document.header[l]
603 l = re.compile(r'\\font_sans (.*)$')
606 l = find_token(document.header, "\\font_typewriter", 0)
608 document.warning("Malformed LyX document: Missing \\font_typewriter.")
609 line = document.header[l]
610 l = re.compile(r'\\font_typewriter (.*)$')
612 typewriter = m.group(1)
613 osf = get_value(document.header, '\\font_osf', 0) == "true"
614 sf_scale = float(get_value(document.header, '\\font_sf_scale', 0))
615 tt_scale = float(get_value(document.header, '\\font_tt_scale', 0))
616 # 3.) set preamble stuff
617 pretext = '%% This document must be processed with xelatex!\n'
618 pretext += '\\usepackage{fontspec}\n'
619 if roman != "default":
620 pretext += '\\setmainfont[Mapping=tex-text]{' + roman + '}\n'
621 if sans != "default":
622 pretext += '\\setsansfont['
624 pretext += 'Scale=' + str(sf_scale / 100) + ','
625 pretext += 'Mapping=tex-text]{' + sans + '}\n'
626 if typewriter != "default":
627 pretext += '\\setmonofont'
629 pretext += '[Scale=' + str(tt_scale / 100) + ']'
630 pretext += '{' + typewriter + '}\n'
632 pretext += '\\defaultfontfeatures{Numbers=OldStyle}\n'
633 pretext += '\usepackage{xunicode}\n'
634 pretext += '\usepackage{xltxtra}\n'
635 insert_to_preamble(0, document, pretext)
636 # 4.) reset font settings
637 i = find_token(document.header, "\\font_roman", 0)
639 document.warning("Malformed LyX document: Missing \\font_roman.")
640 document.header[i] = "\\font_roman default"
641 i = find_token(document.header, "\\font_sans", 0)
643 document.warning("Malformed LyX document: Missing \\font_sans.")
644 document.header[i] = "\\font_sans default"
645 i = find_token(document.header, "\\font_typewriter", 0)
647 document.warning("Malformed LyX document: Missing \\font_typewriter.")
648 document.header[i] = "\\font_typewriter default"
649 i = find_token(document.header, "\\font_osf", 0)
651 document.warning("Malformed LyX document: Missing \\font_osf.")
652 document.header[i] = "\\font_osf false"
653 i = find_token(document.header, "\\font_sc", 0)
655 document.warning("Malformed LyX document: Missing \\font_sc.")
656 document.header[i] = "\\font_sc false"
657 i = find_token(document.header, "\\font_sf_scale", 0)
659 document.warning("Malformed LyX document: Missing \\font_sf_scale.")
660 document.header[i] = "\\font_sf_scale 100"
661 i = find_token(document.header, "\\font_tt_scale", 0)
663 document.warning("Malformed LyX document: Missing \\font_tt_scale.")
664 document.header[i] = "\\font_tt_scale 100"
667 def revert_outputformat(document):
668 " Remove default output format param "
669 i = find_token(document.header, '\\default_output_format', 0)
671 document.warning("Malformed LyX document: Missing \\default_output_format.")
673 del document.header[i]
676 def revert_backgroundcolor(document):
677 " Reverts background color to preamble code "
678 i = find_token(document.header, "\\backgroundcolor", 0)
681 colorcode = get_value(document.header, '\\backgroundcolor', i)
682 del document.header[i]
683 # don't clutter the preamble if backgroundcolor is not set
684 if colorcode == "#ffffff":
686 red = hex2ratio(colorcode[1:3])
687 green = hex2ratio(colorcode[3:5])
688 blue = hex2ratio(colorcode[5:7])
689 insert_to_preamble(0, document,
690 '% Commands inserted by lyx2lyx to set the background color\n'
691 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
692 + '\\definecolor{page_backgroundcolor}{rgb}{'
693 + red + ',' + green + ',' + blue + '}\n'
694 + '\\pagecolor{page_backgroundcolor}\n')
697 def revert_splitindex(document):
698 " Reverts splitindex-aware documents "
699 i = find_token(document.header, '\\use_indices', 0)
701 document.warning("Malformed LyX document: Missing \\use_indices.")
703 indices = get_value(document.header, "\\use_indices", i)
705 useindices = (indices == "true")
707 preamble += "\\usepackage{splitidx}\n"
708 del document.header[i]
710 # deal with index declarations in the preamble
713 i = find_token(document.header, "\\index", i)
716 k = find_token(document.header, "\\end_index", i)
718 document.warning("Malformed LyX document: Missing \\end_index.")
721 line = document.header[i]
722 l = re.compile(r'\\index (.*)$')
725 ishortcut = get_value(document.header, '\\shortcut', i, k)
727 preamble += "\\newindex[" + iname + "]{" + ishortcut + "}\n"
728 del document.header[i:k + 1]
730 insert_to_preamble(0, document, preamble)
732 # deal with index insets
733 # these need to have the argument removed
736 i = find_token(document.body, "\\begin_inset Index", i)
739 line = document.body[i]
740 l = re.compile(r'\\begin_inset Index (.*)$')
743 if itype == "idx" or indices == "false":
744 document.body[i] = "\\begin_inset Index"
746 k = find_end_of_inset(document.body, i)
748 document.warning("Can't find end of index inset!")
751 content = lyx2latex(document, document.body[i:k])
753 content = content.replace('"', r'\"')
754 subst = put_cmd_in_ert("\\sindex[" + itype + "]{" + content + "}")
755 document.body[i:k + 1] = subst
758 # deal with index_print insets
761 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
764 k = find_end_of_inset(document.body, i)
765 ptype = get_value(document.body, 'type', i, k).strip('"')
767 j = find_token(document.body, "type", i, k)
770 del document.body[i:k + 1]
772 subst = put_cmd_in_ert("\\printindex[" + ptype + "]{}")
773 document.body[i:k + 1] = subst
777 def convert_splitindex(document):
778 " Converts index and printindex insets to splitindex-aware format "
781 i = find_token(document.body, "\\begin_inset Index", i)
784 document.body[i] = document.body[i].replace("\\begin_inset Index",
785 "\\begin_inset Index idx")
789 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
792 if document.body[i + 1].find('LatexCommand printindex') == -1:
793 document.warning("Malformed LyX document: Incomplete printindex inset.")
795 subst = ["LatexCommand printindex",
797 document.body[i + 1:i + 2] = subst
801 def revert_subindex(document):
802 " Reverts \\printsubindex CommandInset types "
803 i = find_token(document.header, '\\use_indices', 0)
805 document.warning("Malformed LyX document: Missing \\use_indices.")
807 indices = get_value(document.header, "\\use_indices", i)
808 useindices = (indices == "true")
811 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
814 k = find_end_of_inset(document.body, i)
815 ctype = get_value(document.body, 'LatexCommand', i, k)
816 if ctype != "printsubindex":
819 ptype = get_value(document.body, 'type', i, k).strip('"')
821 del document.body[i:k + 1]
823 subst = put_cmd_in_ert("\\printsubindex[" + ptype + "]{}")
824 document.body[i:k + 1] = subst
828 def revert_printindexall(document):
829 " Reverts \\print[sub]index* CommandInset types "
830 i = find_token(document.header, '\\use_indices', 0)
832 document.warning("Malformed LyX document: Missing \\use_indices.")
834 indices = get_value(document.header, "\\use_indices", i)
835 useindices = (indices == "true")
838 i = find_token(document.body, "\\begin_inset CommandInset index_print", i)
841 k = find_end_of_inset(document.body, i)
842 ctype = get_value(document.body, 'LatexCommand', i, k)
843 if ctype != "printindex*" and ctype != "printsubindex*":
847 del document.body[i:k + 1]
849 subst = put_cmd_in_ert("\\" + ctype + "{}")
850 document.body[i:k + 1] = subst
854 def revert_strikeout(document):
855 " Reverts \\strikeout font attribute "
856 changed = revert_font_attrs(document, "\\uuline", "\\uuline")
857 changed = revert_font_attrs(document, "\\uwave", "\\uwave") or changed
858 changed = revert_font_attrs(document, "\\strikeout", "\\sout") or changed
860 insert_to_preamble(0, document,
861 '% Commands inserted by lyx2lyx for proper underlining\n'
862 + '\\PassOptionsToPackage{normalem}{ulem}\n'
863 + '\\usepackage{ulem}\n')
866 def revert_ulinelatex(document):
867 " Reverts \\uline font attribute "
868 i = find_token(document.body, '\\bar under', 0)
871 insert_to_preamble(0, document,
872 '% Commands inserted by lyx2lyx for proper underlining\n'
873 + '\\PassOptionsToPackage{normalem}{ulem}\n'
874 + '\\usepackage{ulem}\n'
875 + '\\let\\cite@rig\\cite\n'
876 + '\\newcommand{\\b@xcite}[2][\\%]{\\def\\def@pt{\\%}\\def\\pas@pt{#1}\n'
877 + ' \\mbox{\\ifx\\def@pt\\pas@pt\\cite@rig{#2}\\else\\cite@rig[#1]{#2}\\fi}}\n'
878 + '\\renewcommand{\\underbar}[1]{{\\let\\cite\\b@xcite\\uline{#1}}}\n')
881 def revert_custom_processors(document):
882 " Remove bibtex_command and index_command params "
883 i = find_token(document.header, '\\bibtex_command', 0)
885 document.warning("Malformed LyX document: Missing \\bibtex_command.")
887 del document.header[i]
888 i = find_token(document.header, '\\index_command', 0)
890 document.warning("Malformed LyX document: Missing \\index_command.")
892 del document.header[i]
895 def convert_nomencl_width(document):
896 " Add set_width param to nomencl_print "
899 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
902 document.body.insert(i + 2, "set_width \"none\"")
906 def revert_nomencl_width(document):
907 " Remove set_width param from nomencl_print "
910 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
913 j = find_end_of_inset(document.body, i)
914 l = find_token(document.body, "set_width", i, j)
916 document.warning("Can't find set_width option for nomencl_print!")
923 def revert_nomencl_cwidth(document):
924 " Remove width param from nomencl_print "
927 i = find_token(document.body, "\\begin_inset CommandInset nomencl_print", i)
930 j = find_end_of_inset(document.body, i)
931 l = find_token(document.body, "width", i, j)
933 document.warning("Can't find width option for nomencl_print!")
936 width = get_value(document.body, "width", i, j).strip('"')
938 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
939 add_to_preamble(document, ["\\setlength{\\nomlabelwidth}{" + width + "}"])
943 def revert_applemac(document):
944 " Revert applemac encoding to auto "
945 if document.encoding != "applemac":
947 document.encoding = "auto"
948 i = find_token(document.header, "\\encoding", 0)
950 document.header[i] = "\\encoding auto"
953 def revert_longtable_align(document):
954 " Remove longtable alignment setting "
957 i = find_token(document.body, "\\begin_inset Tabular", i)
960 end = find_end_of_inset(document.body, i)
962 document.warning("Can't find end of inset at line " + str(i))
965 fline = find_token(document.body, "<features", i, end)
967 document.warning("Can't find features for inset at line " + str(i))
970 j = document.body[fline].find("longtabularalignment")
974 # FIXME Is this correct? It wipes out everything after the
976 document.body[fline] = document.body[fline][:j - 1] + '>'
977 # since there could be a tabular inside this one, we
978 # cannot jump to end.
982 def revert_branch_filename(document):
983 " Remove \\filename_suffix parameter from branches "
986 i = find_token(document.header, "\\filename_suffix", i)
989 del document.header[i]
992 def revert_paragraph_indentation(document):
993 " Revert custom paragraph indentation to preamble code "
994 i = find_token(document.header, "\\paragraph_indentation", 0)
997 length = get_value(document.header, "\\paragraph_indentation", i)
998 # we need only remove the line if indentation is default
999 if length != "default":
1000 # handle percent lengths
1001 length = latex_length(length)[1]
1002 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1003 add_to_preamble(document, ["\\setlength{\\parindent}{" + length + "}"])
1004 del document.header[i]
1007 def revert_percent_skip_lengths(document):
1008 " Revert relative lengths for paragraph skip separation to preamble code "
1009 i = find_token(document.header, "\\defskip", 0)
1012 length = get_value(document.header, "\\defskip", i)
1013 # only revert when a custom length was set and when
1014 # it used a percent length
1015 if length in ('smallskip', 'medskip', 'bigskip'):
1017 # handle percent lengths
1018 percent, length = latex_length(length)
1019 if percent == "True":
1020 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1021 add_to_preamble(document, ["\\setlength{\\parskip}{" + length + "}"])
1022 # set defskip to medskip as default
1023 document.header[i] = "\\defskip medskip"
1026 def revert_percent_vspace_lengths(document):
1027 " Revert relative VSpace lengths to ERT "
1030 i = find_token(document.body, "\\begin_inset VSpace", i)
1033 # only revert if a custom length was set and if
1034 # it used a percent length
1035 r = re.compile(r'\\begin_inset VSpace (.*)$')
1036 m = r.match(document.body[i])
1038 if length in ('defskip', 'smallskip', 'medskip', 'bigskip', 'vfill'):
1041 # check if the space has a star (protected space)
1042 protected = (document.body[i].rfind("*") != -1)
1044 length = length.rstrip('*')
1045 # handle percent lengths
1046 percent, length = latex_length(length)
1047 # revert the VSpace inset to ERT
1048 if percent == "True":
1050 subst = put_cmd_in_ert("\\vspace*{" + length + "}")
1052 subst = put_cmd_in_ert("\\vspace{" + length + "}")
1053 document.body[i:i + 2] = subst
1057 def revert_percent_hspace_lengths(document):
1058 " Revert relative HSpace lengths to ERT "
1061 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1064 j = find_end_of_inset(document.body, i)
1066 document.warning("Can't find end of inset at line " + str(i))
1069 # only revert if a custom length was set...
1070 length = get_value(document.body, '\\length', i + 1, j)
1072 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1076 if document.body[i].find("\\hspace*{}") != -1:
1078 # ...and if it used a percent length
1079 percent, length = latex_length(length)
1080 # revert the HSpace inset to ERT
1081 if percent == "True":
1082 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
1083 document.body[i:j + 1] = subst
1084 # if we did a substitution, this will still be ok
1088 def revert_hspace_glue_lengths(document):
1089 " Revert HSpace glue lengths to ERT "
1092 i = find_token(document.body, "\\begin_inset space \\hspace", i)
1095 j = find_end_of_inset(document.body, i)
1097 document.warning("Can't find end of inset at line " + str(i))
1100 length = get_value(document.body, '\\length', i + 1, j)
1102 document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
1106 if document.body[i].find("\\hspace*{}") != -1:
1108 # only revert if the length contains a plus or minus at pos != 0
1109 if length.find('-',1) != -1 or length.find('+',1) != -1:
1110 # handle percent lengths
1111 length = latex_length(length)[1]
1112 # revert the HSpace inset to ERT
1113 subst = put_cmd_in_ert("\\hspace" + protected + "{" + length + "}")
1114 document.body[i:j+1] = subst
1118 def convert_author_id(document):
1119 " Add the author_id to the \\author definition and make sure 0 is not used"
1122 re_author = re.compile(r'(\\author) (\".*\")\s*(.*)$')
1125 i = find_token(document.header, "\\author", i)
1128 m = re_author.match(document.header[i])
1132 document.header[i] = "\\author %i %s %s" % (anum, name, email)
1133 # FIXME Should this really be incremented if we didn't match?
1139 i = find_token(document.body, "\\change_", i)
1142 change = document.body[i].split(' ');
1143 if len(change) == 3:
1145 author_id = int(change[1])
1147 document.body[i] = "%s %i %s" % (type, author_id + 1, time)
1151 def revert_author_id(document):
1152 " Remove the author_id from the \\author definition "
1155 rx = re.compile(r'(\\author)\s+(\d+)\s+(\".*\")\s*(.*)$')
1159 i = find_token(document.header, "\\author", i)
1162 m = rx.match(document.header[i])
1164 author_id = int(m.group(2))
1165 idmap[author_id] = anum
1168 document.header[i] = "\\author %s %s" % (name, email)
1170 # FIXME Should this be incremented if we didn't match?
1175 i = find_token(document.body, "\\change_", i)
1178 change = document.body[i].split(' ');
1179 if len(change) == 3:
1181 author_id = int(change[1])
1183 document.body[i] = "%s %i %s" % (type, idmap[author_id], time)
1187 def revert_suppress_date(document):
1188 " Revert suppressing of default document date to preamble code "
1189 i = find_token(document.header, "\\suppress_date", 0)
1192 # remove the preamble line and write to the preamble
1193 # when suppress_date was true
1194 date = get_value(document.header, "\\suppress_date", i)
1196 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
1197 add_to_preamble(document, ["\\date{}"])
1198 del document.header[i]
1201 def revert_mhchem(document):
1202 "Revert mhchem loading to preamble code"
1205 i = find_token(document.header, "\\use_mhchem", 0)
1207 document.warning("Malformed LyX document: Could not find mhchem setting.")
1210 val = get_value(document.header, "\\use_mhchem", i)
1215 del document.header[i]
1217 if mhchem == "auto":
1220 i = find_token(document.body, "\\begin_inset Formula", i)
1223 line = document.body[i]
1224 if line.find("\\ce{") != -1 or line.find("\\cf{") != 1:
1230 pre = ["% lyx2lyx mhchem commands",
1231 "\\PassOptionsToPackage{version=3}{mhchem}",
1232 "\\usepackage{mhchem}"]
1233 add_to_preamble(document, pre)
1236 def revert_fontenc(document):
1237 " Remove fontencoding param "
1238 i = find_token(document.header, '\\fontencoding', 0)
1240 document.warning("Malformed LyX document: Missing \\fontencoding.")
1242 del document.header[i]
1245 def merge_gbrief(document):
1246 " Merge g-brief-en and g-brief-de to one class "
1248 if document.textclass != "g-brief-de":
1249 if document.textclass == "g-brief-en":
1250 document.textclass = "g-brief"
1251 document.set_textclass()
1254 obsoletedby = { "Brieftext": "Letter",
1255 "Unterschrift": "Signature",
1256 "Strasse": "Street",
1257 "Zusatz": "Addition",
1260 "RetourAdresse": "ReturnAddress",
1261 "MeinZeichen": "MyRef",
1262 "IhrZeichen": "YourRef",
1263 "IhrSchreiben": "YourMail",
1266 "Konto": "BankAccount",
1267 "Postvermerk": "PostalComment",
1268 "Adresse": "Address",
1270 "Betreff": "Reference",
1271 "Anrede": "Opening",
1277 i = find_token(document.body, "\\begin_layout", i)
1281 layout = document.body[i][14:]
1282 if layout in obsoletedby:
1283 document.body[i] = "\\begin_layout " + obsoletedby[layout]
1287 document.textclass = "g-brief"
1288 document.set_textclass()
1291 def revert_gbrief(document):
1292 " Revert g-brief to g-brief-en "
1293 if document.textclass == "g-brief":
1294 document.textclass = "g-brief-en"
1295 document.set_textclass()
1298 def revert_html_options(document):
1299 " Remove html options "
1300 i = find_token(document.header, '\\html_use_mathml', 0)
1302 del document.header[i]
1303 i = find_token(document.header, '\\html_be_strict', 0)
1305 del document.header[i]
1308 def revert_includeonly(document):
1311 i = find_token(document.header, "\\begin_includeonly", i)
1314 j = find_end_of(document.header, i, "\\begin_includeonly", "\\end_includeonly")
1316 document.warning("Unable to find end of includeonly section!!")
1318 document.header[i : j + 1] = []
1321 def revert_includeall(document):
1322 " Remove maintain_unincluded_children param "
1323 i = find_token(document.header, '\\maintain_unincluded_children', 0)
1325 del document.header[i]
1328 def revert_multirow(document):
1329 " Revert multirow cells in tables to TeX-code"
1333 # cell type 3 is multirow begin cell
1334 i = find_token(document.body, '<cell multirow="3"', i)
1337 # a multirow cell was found
1339 # remove the multirow tag, set the valignment to top
1340 # and remove the bottom line
1341 # FIXME Are we sure these always have space around them?
1342 document.body[i] = document.body[i].replace(' multirow="3" ', ' ')
1343 document.body[i] = document.body[i].replace('valignment="middle"', 'valignment="top"')
1344 document.body[i] = document.body[i].replace(' bottomline="true" ', ' ')
1345 # write ERT to create the multirow cell
1346 # use 2 rows and 2cm as default with because the multirow span
1347 # and the column width is only hardly accessible
1348 cend = find_token(document.body, "</cell>", i)
1350 document.warning("Malformed LyX document: Could not find end of tabular cell.")
1353 blay = find_token(document.body, "\\begin_layout", i, cend)
1355 document.warning("Can't find layout for cell!")
1358 bend = find_end_of_layout(document.body, blay)
1360 document.warning("Can't find end of layout for cell!")
1364 # do the later one first, so as not to mess up the numbering
1365 # we are wrapping the whole cell in this ert
1366 # so before the end of the layout...
1367 document.body[bend:bend] = put_cmd_in_ert("}")
1368 # ...and after the beginning
1369 document.body[blay+1:blay+1] = put_cmd_in_ert("\\multirow{2}{2cm}{")
1372 # cell type 4 is multirow part cell
1373 k = find_token(document.body, '<cell multirow="4"', cend)
1376 # remove the multirow tag, set the valignment to top
1377 # and remove the top line
1378 # FIXME Are we sure these always have space around them?
1379 document.body[k] = document.body[k].replace(' multirow="4" ', ' ')
1380 document.body[k] = document.body[k].replace('valignment="middle"', 'valignment="top"')
1381 document.body[k] = document.body[k].replace(' topline="true" ', ' ')
1383 # this will always be ok
1386 if multirow == True:
1387 add_to_preamble(document,
1388 ["% lyx2lyx multirow additions ", "\\usepackage{multirow}"])
1391 def convert_math_output(document):
1392 " Convert \html_use_mathml to \html_math_output "
1393 i = find_token(document.header, "\\html_use_mathml", 0)
1396 rgx = re.compile(r'\\html_use_mathml\s+(\w+)')
1397 m = rgx.match(document.header[i])
1398 newval = "0" # MathML
1402 newval = "2" # Images
1404 document.warning("Can't match " + document.header[i])
1405 document.header[i] = "\\html_math_output " + newval
1408 def revert_math_output(document):
1409 " Revert \html_math_output to \html_use_mathml "
1410 i = find_token(document.header, "\\html_math_output", 0)
1413 rgx = re.compile(r'\\html_math_output\s+(\d)')
1414 m = rgx.match(document.header[i])
1418 if val == "1" or val == "2":
1421 document.warning("Unable to match " + document.header[i])
1422 document.header[i] = "\\html_use_mathml " + newval
1426 def revert_inset_preview(document):
1427 " Dissolves the preview inset "
1430 i = find_token(document.body, "\\begin_inset Preview", i)
1433 iend = find_end_of_inset(document.body, i)
1435 document.warning("Malformed LyX document: Could not find end of Preview inset.")
1439 # This has several issues.
1440 # We need to do something about the layouts inside InsetPreview.
1441 # If we just leave the first one, then we have something like:
1442 # \begin_layout Standard
1444 # \begin_layout Standard
1445 # and we get a "no \end_layout" error. So something has to be done.
1446 # Ideally, we would check if it is the same as the layout we are in.
1447 # If so, we just remove it; if not, we end the active one. But it is
1448 # not easy to know what layout we are in, due to depth changes, etc,
1449 # and it is not clear to me how much work it is worth doing. In most
1450 # cases, the layout will probably be the same.
1452 # For the same reason, we have to remove the \end_layout tag at the
1453 # end of the last layout in the inset. Again, that will sometimes be
1454 # wrong, but it will usually be right. To know what to do, we would
1455 # again have to know what layout the inset is in.
1457 blay = find_token(document.body, "\\begin_layout", i, iend)
1459 document.warning("Can't find layout for preview inset!")
1460 # always do the later one first...
1461 del document.body[iend]
1462 del document.body[i]
1463 # deletions mean we do not need to reset i
1466 # This is where we would check what layout we are in.
1467 # The check for Standard is definitely wrong.
1469 # lay = document.body[blay].split(None, 1)[1]
1470 # if lay != oldlayout:
1471 # # record a boolean to tell us what to do later....
1472 # # better to do it later, since (a) it won't mess up
1473 # # the numbering and (b) we only modify at the end.
1475 # we want to delete the last \\end_layout in this inset, too.
1476 # note that this may not be the \\end_layout that goes with blay!!
1477 bend = find_end_of_layout(document.body, blay)
1479 tmp = find_token(document.body, "\\end_layout", bend + 1, iend)
1484 document.warning("Unable to find last layout in preview inset!")
1485 del document.body[iend]
1486 del document.body[i]
1487 # deletions mean we do not need to reset i
1489 # always do the later one first...
1490 del document.body[iend]
1491 del document.body[bend]
1492 del document.body[i:blay + 1]
1493 # we do not need to reset i
1496 def revert_equalspacing_xymatrix(document):
1497 " Revert a Formula with xymatrix@! to an ERT inset "
1499 has_preamble = False
1500 has_equal_spacing = False
1503 i = find_token(document.body, "\\begin_inset Formula", i)
1506 j = find_end_of_inset(document.body, i)
1508 document.warning("Malformed LyX document: Could not find end of Formula inset.")
1512 for curline in range(i,j):
1513 found = document.body[curline].find("\\xymatrix@!")
1518 has_equal_spacing = True
1519 content = [document.body[i][21:]]
1520 content += document.body[i + 1:j]
1521 subst = put_cmd_in_ert(content)
1522 document.body[i:j + 1] = subst
1523 i += len(subst) - (j - i) + 1
1525 for curline in range(i,j):
1526 l = document.body[curline].find("\\xymatrix")
1528 has_preamble = True;
1532 if has_equal_spacing and not has_preamble:
1533 add_to_preamble(document, ['% lyx2lyx xymatrix addition', '\\usepackage[all]{xy}'])
1536 def revert_notefontcolor(document):
1537 " Reverts greyed-out note font color to preamble code "
1539 i = find_token(document.header, "\\notefontcolor", 0)
1542 colorcode = get_value(document.header, '\\notefontcolor', i)
1543 del document.header[i]
1544 # the color code is in the form #rrggbb where every character denotes a hex number
1545 red = hex2ratio(colorcode[1:3])
1546 green = hex2ratio(colorcode[3:5])
1547 blue = hex2ratio(colorcode[5:7])
1548 # write the preamble
1549 insert_to_preamble(0, document,
1550 ['% Commands inserted by lyx2lyx to set the font color',
1551 '% for greyed-out notes',
1552 '\\@ifundefined{definecolor}{\\usepackage{color}}{}'
1553 '\\definecolor{note_fontcolor}{rgb}{'
1554 + str(red) + ', ' + str(green)
1555 + ', ' + str(blue) + '}',
1556 '\\renewenvironment{lyxgreyedout}',
1557 ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}'])
1560 def revert_turkmen(document):
1561 "Set language Turkmen to English"
1563 if document.language == "turkmen":
1564 document.language = "english"
1565 i = find_token(document.header, "\\language", 0)
1567 document.header[i] = "\\language english"
1570 j = find_token(document.body, "\\lang turkmen", j)
1573 document.body[j] = document.body[j].replace("\\lang turkmen", "\\lang english")
1577 def revert_fontcolor(document):
1578 " Reverts font color to preamble code "
1582 i = find_token(document.header, "\\fontcolor", i)
1585 colorcode = get_value(document.header, '\\fontcolor', 0)
1586 del document.header[i]
1587 # don't clutter the preamble if backgroundcolor is not set
1588 if colorcode == "#000000":
1590 # the color code is in the form #rrggbb where every character denotes a hex number
1591 # convert the string to an int
1592 red = string.atoi(colorcode[1:3],16)
1593 # we want the output "0.5" for the value "127" therefore add here
1596 redout = float(red) / 256
1597 green = string.atoi(colorcode[3:5],16)
1600 greenout = float(green) / 256
1601 blue = string.atoi(colorcode[5:7],16)
1604 blueout = float(blue) / 256
1605 # write the preamble
1606 insert_to_preamble(0, document,
1607 '% Commands inserted by lyx2lyx to set the font color\n'
1608 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1609 + '\\definecolor{document_fontcolor}{rgb}{'
1610 + str(redout) + ', ' + str(greenout)
1611 + ', ' + str(blueout) + '}\n'
1612 + '\\color{document_fontcolor}\n')
1614 def revert_shadedboxcolor(document):
1615 " Reverts shaded box color to preamble code "
1619 i = find_token(document.header, "\\boxbgcolor", i)
1622 colorcode = get_value(document.header, '\\boxbgcolor', 0)
1623 del document.header[i]
1624 # the color code is in the form #rrggbb where every character denotes a hex number
1625 # convert the string to an int
1626 red = string.atoi(colorcode[1:3],16)
1627 # we want the output "0.5" for the value "127" therefore increment here
1630 redout = float(red) / 256
1631 green = string.atoi(colorcode[3:5],16)
1634 greenout = float(green) / 256
1635 blue = string.atoi(colorcode[5:7],16)
1638 blueout = float(blue) / 256
1639 # write the preamble
1640 insert_to_preamble(0, document,
1641 '% Commands inserted by lyx2lyx to set the color\n'
1642 '% of boxes with shaded background\n'
1643 + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
1644 + '\\definecolor{shadecolor}{rgb}{'
1645 + str(redout) + ', ' + str(greenout)
1646 + ', ' + str(blueout) + '}\n')
1649 def revert_lyx_version(document):
1650 " Reverts LyX Version information from Inset Info "
1651 version = "LyX version"
1653 import lyx2lyx_version
1654 version = lyx2lyx_version.version
1660 i = find_token(document.body, '\\begin_inset Info', i)
1663 j = find_end_of_inset(document.body, i + 1)
1666 document.warning("Malformed LyX document: Could not find end of Info inset.")
1672 # but we shall try to be forgiving.
1674 for k in range(i, j):
1675 if document.body[k].startswith("arg"):
1676 arg = document.body[k][3:].strip().strip('"')
1677 if document.body[k].startswith("type"):
1678 typ = document.body[k][4:].strip().strip('"')
1679 if arg != "version" or typ != "lyxinfo":
1683 # We do not actually know the version of LyX used to produce the document.
1684 # But we can use our version, since we are reverting.
1686 # Now we want to check if the line after "\end_inset" is empty. It normally
1687 # is, so we want to remove it, too.
1689 if document.body[j + 1].strip() == "":
1691 document.body[i: lastline] = s
1695 def revert_math_scale(document):
1696 " Remove math scaling and LaTeX options "
1697 i = find_token(document.header, '\\html_math_img_scale', 0)
1699 del document.header[i]
1700 i = find_token(document.header, '\\html_latex_start', 0)
1702 del document.header[i]
1703 i = find_token(document.header, '\\html_latex_end', 0)
1705 del document.header[i]
1708 def revert_pagesizes(document):
1710 " Revert page sizes to default "
1711 i = find_token(document.header, '\\papersize', 0)
1713 size = document.header[i][11:]
1714 if size == "a0paper" or size == "a1paper" or size == "a2paper" \
1715 or size == "a6paper" or size == "b0paper" or size == "b1paper" \
1716 or size == "b2paper" or size == "b6paper" or size == "b0j" \
1717 or size == "b1j" or size == "b2j" or size == "b3j" or size == "b4j" \
1718 or size == "b5j" or size == "b6j":
1719 del document.header[i]
1722 def revert_DIN_C_pagesizes(document):
1724 " Revert DIN C page sizes to default "
1725 i = find_token(document.header, '\\papersize', 0)
1727 size = document.header[i][11:]
1728 if size == "c0paper" or size == "c1paper" or size == "c2paper" \
1729 or size == "c3paper" or size == "c4paper" or size == "c5paper" \
1730 or size == "c6paper":
1731 del document.header[i]
1734 def convert_html_quotes(document):
1735 " Remove quotes around html_latex_start and html_latex_end "
1737 i = find_token(document.header, '\\html_latex_start', 0)
1739 line = document.header[i]
1740 l = re.compile(r'\\html_latex_start\s+"(.*)"')
1743 document.header[i] = "\\html_latex_start " + m.group(1)
1745 i = find_token(document.header, '\\html_latex_end', 0)
1747 line = document.header[i]
1748 l = re.compile(r'\\html_latex_end\s+"(.*)"')
1751 document.header[i] = "\\html_latex_end " + m.group(1)
1754 def revert_html_quotes(document):
1755 " Remove quotes around html_latex_start and html_latex_end "
1757 i = find_token(document.header, '\\html_latex_start', 0)
1759 line = document.header[i]
1760 l = re.compile(r'\\html_latex_start\s+(.*)')
1762 document.header[i] = "\\html_latex_start \"" + m.group(1) + "\""
1764 i = find_token(document.header, '\\html_latex_end', 0)
1766 line = document.header[i]
1767 l = re.compile(r'\\html_latex_end\s+(.*)')
1769 document.header[i] = "\\html_latex_end \"" + m.group(1) + "\""
1772 def revert_output_sync(document):
1773 " Remove forward search options "
1774 i = find_token(document.header, '\\output_sync_macro', 0)
1776 del document.header[i]
1777 i = find_token(document.header, '\\output_sync', 0)
1779 del document.header[i]
1782 def convert_beamer_args(document):
1783 " Convert ERT arguments in Beamer to InsetArguments "
1785 if document.textclass != "beamer" and document.textclass != "article-beamer":
1788 layouts = ("Block", "ExampleBlock", "AlertBlock")
1789 for layout in layouts:
1792 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1795 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1797 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1800 bert = find_token(document.body, '\\begin_inset ERT', blay)
1802 document.warning("Malformed Beamer LyX document: Can't find argument of " + layout + " layout.")
1805 eert = find_end_of_inset(document.body, bert)
1807 document.warning("Malformed LyX document: Can't find end of ERT.")
1811 # So the ERT inset begins at line k and goes to line l. We now wrap it in
1812 # an argument inset.
1813 # Do the end first, so as not to mess up the variables.
1814 document.body[eert + 1:eert + 1] = ['', '\\end_layout', '', '\\end_inset', '']
1815 document.body[bert:bert] = ['\\begin_inset OptArg', 'status open', '',
1816 '\\begin_layout Plain Layout']
1820 def revert_beamer_args(document):
1821 " Revert Beamer arguments to ERT "
1823 if document.textclass != "beamer" and document.textclass != "article-beamer":
1826 layouts = ("Block", "ExampleBlock", "AlertBlock")
1827 for layout in layouts:
1830 blay = find_token(document.body, '\\begin_layout ' + layout, blay)
1833 elay = find_end_of(document.body, blay, '\\begin_layout', '\\end_layout')
1835 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1838 bopt = find_token(document.body, '\\begin_inset OptArg', blay)
1840 # it is legal not to have one of these
1843 eopt = find_end_of_inset(document.body, bopt)
1845 document.warning("Malformed LyX document: Can't find end of argument.")
1848 bplay = find_token(document.body, '\\begin_layout Plain Layout', blay)
1850 document.warning("Malformed LyX document: Can't find plain layout.")
1853 eplay = find_end_of(document.body, bplay, '\\begin_layout', '\\end_layout')
1855 document.warning("Malformed LyX document: Can't find end of plain layout.")
1858 # So the content of the argument inset goes from bplay + 1 to eplay - 1
1862 document.warning(str(bcont) + " " + str(eplay))
1865 # we convert the content of the argument into pure LaTeX...
1866 content = lyx2latex(document, document.body[bcont:eplay])
1867 strlist = put_cmd_in_ert(["{" + content + "}"])
1869 # now replace the optional argument with the ERT
1870 document.body[bopt:eopt + 1] = strlist
1874 def revert_align_decimal(document):
1877 l = document.body[l].find('alignment=decimal')
1880 remove_option(document, l, 'decimal_point')
1881 document.body[l].replace('decimal', 'center')
1884 def convert_optarg(document):
1885 " Convert \\begin_inset OptArg to \\begin_inset Argument "
1888 i = find_token(document.body, '\\begin_inset OptArg', i)
1891 document.body[i] = "\\begin_inset Argument"
1895 def revert_argument(document):
1896 " Convert \\begin_inset Argument to \\begin_inset OptArg "
1899 i = find_token(document.body, '\\begin_inset Argument', i)
1902 document.body[i] = "\\begin_inset OptArg"
1906 def revert_makebox(document):
1907 " Convert \\makebox to TeX code "
1910 # only revert frameless boxes without an inner box
1911 i = find_token(document.body, '\\begin_inset Box Frameless', i)
1913 # remove the option use_makebox
1914 revert_use_makebox(document)
1916 z = find_end_of_inset(document.body, i)
1918 document.warning("Malformed LyX document: Can't find end of box inset.")
1920 j = find_token(document.body, 'use_makebox 1', i)
1921 # assure we found the makebox of the current box
1922 if j < z and j != -1:
1923 y = find_token(document.body, "\\begin_layout", i)
1924 if y > z or y == -1:
1925 document.warning("Malformed LyX document: Can't find layout in box.")
1927 # remove the \end_layout \end_inset pair
1928 document.body[z - 2:z + 1] = put_cmd_in_ert("}")
1929 # determine the alignment
1930 k = find_token(document.body, 'hor_pos', j - 4)
1931 align = document.body[k][9]
1932 # determine the width
1933 l = find_token(document.body, 'width "', j + 1)
1934 length = document.body[l][7:]
1935 # remove trailing '"'
1936 length = length[:-1]
1937 length = latex_length(length)[1]
1938 subst = "\\makebox[" + length + "][" \
1940 document.body[i:y + 1] = put_cmd_in_ert(subst)
1944 def revert_use_makebox(document):
1945 " Deletes use_makebox option of boxes "
1948 # remove the option use_makebox
1949 h = find_token(document.body, 'use_makebox', 0)
1952 del document.body[h]
1956 def convert_use_makebox(document):
1957 " Adds use_makebox option for boxes "
1960 # remove the option use_makebox
1961 i = find_token(document.body, '\\begin_inset Box', i)
1964 k = find_token(document.body, 'use_parbox', i)
1966 document.warning("Malformed LyX document: Can't find use_parbox statement in box.")
1968 document.body.insert(k + 1, "use_makebox 0")
1972 def revert_IEEEtran(document):
1973 " Convert IEEEtran layouts and styles to TeX code "
1974 if document.textclass != "IEEEtran":
1976 revert_flex_inset(document, "IEEE membership", "\\IEEEmembership", 0)
1977 revert_flex_inset(document, "Lowercase", "\\MakeLowercase", 0)
1978 layouts = ("Special Paper Notice", "After Title Text", "Publication ID",
1979 "Page headings", "Biography without photo")
1980 latexcmd = {"Special Paper Notice": "\\IEEEspecialpapernotice",
1981 "After Title Text": "\\IEEEaftertitletext",
1982 "Publication ID": "\\IEEEpubid"}
1983 obsoletedby = {"Page headings": "MarkBoth",
1984 "Biography without photo": "BiographyNoPhoto"}
1985 for layout in layouts:
1988 i = find_token(document.body, '\\begin_layout ' + layout, i)
1991 j = find_end_of(document.body, i, '\\begin_layout', '\\end_layout')
1993 document.warning("Malformed LyX document: Can't find end of " + layout + " layout.")
1996 if layout in obsoletedby:
1997 document.body[i] = "\\begin_layout " + obsoletedby[layout]
2000 content = lyx2latex(document, document.body[i:j + 1])
2001 add_to_preamble(document, [latexcmd[layout] + "{" + content + "}"])
2002 del document.body[i:j + 1]
2005 def convert_prettyref(document):
2006 " Converts prettyref references to neutral formatted refs "
2007 re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
2008 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
2012 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
2015 j = find_end_of_inset(document.body, i)
2017 document.warning("Malformed LyX document: No end of InsetRef!")
2020 k = find_token(document.body, "LatexCommand prettyref", i)
2021 if k != -1 and k < j:
2022 document.body[k] = "LatexCommand formatted"
2024 document.header.insert(-1, "\\use_refstyle 0")
2027 def revert_refstyle(document):
2028 " Reverts neutral formatted refs to prettyref "
2029 re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
2030 nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
2034 i = find_token(document.body, "\\begin_inset CommandInset ref", i)
2037 j = find_end_of_inset(document.body, i)
2039 document.warning("Malformed LyX document: No end of InsetRef")
2042 k = find_token(document.body, "LatexCommand formatted", i)
2043 if k != -1 and k < j:
2044 document.body[k] = "LatexCommand prettyref"
2046 i = find_token(document.header, "\\use_refstyle", 0)
2048 document.header.pop(i)
2051 def revert_nameref(document):
2052 " Convert namerefs to regular references "
2053 cmds = ["Nameref", "nameref"]
2055 rx = re.compile(r'reference "(.*)"')
2058 oldcmd = "LatexCommand " + cmd
2060 # It seems better to look for this, as most of the reference
2061 # insets won't be ones we care about.
2062 i = find_token(document.body, oldcmd, i)
2067 # Make sure it is actually in an inset!
2068 # We could just check document.lines[i-1], but that relies
2069 # upon something that might easily change.
2070 # We'll look back a few lines.
2074 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2075 if stins == -1 or stins > cmdloc:
2077 endins = find_end_of_inset(document.body, stins)
2079 document.warning("Can't find end of inset at line " + stins + "!!")
2083 refline = find_token(document.body, "reference", stins)
2084 if refline == -1 or refline > endins:
2085 document.warning("Can't find reference for inset at line " + stinst + "!!")
2087 m = rx.match(document.body[refline])
2089 document.warning("Can't match reference line: " + document.body[ref])
2093 newcontent = ['\\begin_inset ERT', 'status collapsed', '', \
2094 '\\begin_layout Plain Layout', '', '\\backslash', \
2095 cmd + '{' + ref + '}', '\\end_layout', '', '\\end_inset']
2096 document.body[stins:endins + 1] = newcontent
2098 add_to_preamble(document, "\usepackage{nameref}")
2101 def remove_Nameref(document):
2102 " Convert Nameref commands to nameref commands "
2105 # It seems better to look for this, as most of the reference
2106 # insets won't be ones we care about.
2107 i = find_token(document.body, "LatexCommand Nameref" , i)
2113 # Make sure it is actually in an inset!
2114 # We could just check document.lines[i-1], but that relies
2115 # upon something that might easily change.
2116 # We'll look back a few lines.
2120 stins = find_token(document.body, "\\begin_inset CommandInset ref", stins)
2121 if stins == -1 or stins > cmdloc:
2123 endins = find_end_of_inset(document.body, stins)
2125 document.warning("Can't find end of inset at line " + stins + "!!")
2129 document.body[cmdloc] = "LatexCommand nameref"
2132 def revert_mathrsfs(document):
2133 " Load mathrsfs if \mathrsfs us use in the document "
2135 end = len(document.body) - 1
2137 j = document.body[i].find("\\mathscr{")
2139 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2140 add_to_preamble(document, ["\\usepackage{mathrsfs}"])
2147 def convert_flexnames(document):
2148 "Convert \\begin_inset Flex Custom:Style to \\begin_inset Flex Style and similarly for CharStyle and Element."
2151 rx = re.compile(r'^\\begin_inset Flex (?:Custom|CharStyle|Element):(.+)$')
2153 i = find_token(document.body, "\\begin_inset Flex", i)
2156 m = rx.match(document.body[i])
2158 document.body[i] = "\\begin_inset Flex " + m.group(1)
2163 ["Alert", "CharStyle:Alert"],
2164 ["Code", "CharStyle:Code"],
2165 ["Concepts", "CharStyle:Concepts"],
2166 ["E-Mail", "CharStyle:E-Mail"],
2167 ["Emph", "CharStyle:Emph"],
2168 ["Expression", "CharStyle:Expression"],
2169 ["Initial", "CharStyle:Initial"],
2170 ["Institute", "CharStyle:Institute"],
2171 ["Meaning", "CharStyle:Meaning"],
2172 ["Noun", "CharStyle:Noun"],
2173 ["Strong", "CharStyle:Strong"],
2174 ["Structure", "CharStyle:Structure"],
2175 ["ArticleMode", "Custom:ArticleMode"],
2176 ["Endnote", "Custom:Endnote"],
2177 ["Glosse", "Custom:Glosse"],
2178 ["PresentationMode", "Custom:PresentationMode"],
2179 ["Tri-Glosse", "Custom:Tri-Glosse"]
2183 ["Abbrev", "Element:Abbrev"],
2184 ["CCC-Code", "Element:CCC-Code"],
2185 ["Citation-number", "Element:Citation-number"],
2186 ["City", "Element:City"],
2187 ["Code", "Element:Code"],
2188 ["CODEN", "Element:CODEN"],
2189 ["Country", "Element:Country"],
2190 ["Day", "Element:Day"],
2191 ["Directory", "Element:Directory"],
2192 ["Dscr", "Element:Dscr"],
2193 ["Email", "Element:Email"],
2194 ["Emph", "Element:Emph"],
2195 ["Filename", "Element:Filename"],
2196 ["Firstname", "Element:Firstname"],
2197 ["Fname", "Element:Fname"],
2198 ["GuiButton", "Element:GuiButton"],
2199 ["GuiMenu", "Element:GuiMenu"],
2200 ["GuiMenuItem", "Element:GuiMenuItem"],
2201 ["ISSN", "Element:ISSN"],
2202 ["Issue-day", "Element:Issue-day"],
2203 ["Issue-months", "Element:Issue-months"],
2204 ["Issue-number", "Element:Issue-number"],
2205 ["KeyCap", "Element:KeyCap"],
2206 ["KeyCombo", "Element:KeyCombo"],
2207 ["Keyword", "Element:Keyword"],
2208 ["Literal", "Element:Literal"],
2209 ["MenuChoice", "Element:MenuChoice"],
2210 ["Month", "Element:Month"],
2211 ["Orgdiv", "Element:Orgdiv"],
2212 ["Orgname", "Element:Orgname"],
2213 ["Postcode", "Element:Postcode"],
2214 ["SS-Code", "Element:SS-Code"],
2215 ["SS-Title", "Element:SS-Title"],
2216 ["State", "Element:State"],
2217 ["Street", "Element:Street"],
2218 ["Surname", "Element:Surname"],
2219 ["Volume", "Element:Volume"],
2220 ["Year", "Element:Year"]
2224 def revert_flexnames(document):
2225 if document.backend == "latex":
2226 flexlist = flex_insets
2228 flexlist = flex_elements
2230 rx = re.compile(r'^\\begin_inset Flex\s+(.+)$')
2233 i = find_token(document.body, "\\begin_inset Flex", i)
2236 m = rx.match(document.body[i])
2238 document.warning("Illegal flex inset: " + document.body[i])
2245 document.body[i] = "\\begin_inset Flex " + f[1]
2251 def convert_mathdots(document):
2252 " Load mathdots automatically "
2254 i = find_token(document.header, "\\use_esint" , 0)
2256 document.header.insert(i + 1, "\\use_mathdots 1")
2260 def revert_mathdots(document):
2261 " Load mathdots if used in the document "
2263 ddots = re.compile(r'\\begin_inset Formula .*\\ddots', re.DOTALL)
2264 vdots = re.compile(r'\\begin_inset Formula .*\\vdots', re.DOTALL)
2265 iddots = re.compile(r'\\begin_inset Formula .*\\iddots', re.DOTALL)
2266 mathdots = find_token(document.header, "\\use_mathdots" , 0)
2267 no = find_token(document.header, "\\use_mathdots 0" , 0)
2268 auto = find_token(document.header, "\\use_mathdots 1" , 0)
2269 yes = find_token(document.header, "\\use_mathdots 2" , 0)
2271 del document.header[mathdots]
2273 i = find_token(document.body, '\\begin_inset Formula', i)
2276 j = find_end_of_inset(document.body, i)
2278 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2280 k = ddots.search("\n".join(document.body[i:j]))
2281 l = vdots.search("\n".join(document.body[i:j]))
2282 m = iddots.search("\n".join(document.body[i:j]))
2283 if (yes == -1) and ((no != -1) or (not k and not l and not m) or (auto != -1 and not m)):
2286 # use \@ifundefined to catch also the "auto" case
2287 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2288 add_to_preamble(document, ["\\@ifundefined{iddots}{\\usepackage{mathdots}}\n"])
2292 def convert_rule(document):
2293 " Convert \\lyxline to CommandInset line "
2296 i = find_token(document.body, "\\lyxline" , i)
2300 j = find_token(document.body, "\\color" , i - 2)
2302 color = document.body[j] + '\n'
2305 k = find_token(document.body, "\\begin_layout Standard" , i - 4)
2306 # we need to handle the case that \lyxline is in a separate paragraph and that it is colored
2307 # the result is then an extra empty paragraph which we get by adding an empty ERT inset
2308 if k == i - 4 and j == i - 2 and document.body[i - 1] == '':
2309 layout = '\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n\n\\end_layout\n\n\\end_inset\n' \
2310 + '\\end_layout\n\n' \
2311 + '\\begin_layout Standard\n'
2312 elif k == i - 2 and document.body[i - 1] == '':
2315 layout = '\\end_layout\n\n' \
2316 + '\\begin_layout Standard\n'
2317 l = find_token(document.body, "\\begin_layout Standard" , i + 4)
2318 if l == i + 4 and document.body[i + 1] == '':
2321 layout2 = '\\end_layout\n' \
2322 + '\n\\begin_layout Standard\n'
2324 + '\\noindent\n\n' \
2326 + '\\begin_inset CommandInset line\n' \
2327 + 'LatexCommand rule\n' \
2328 + 'offset "0.5ex"\n' \
2329 + 'width "100line%"\n' \
2330 + 'height "1pt"\n' \
2331 + '\n\\end_inset\n\n\n' \
2333 document.body[i] = subst
2337 def revert_rule(document):
2338 " Revert line insets to Tex code "
2341 i = find_token(document.body, "\\begin_inset CommandInset line" , i)
2345 j = find_token(document.body, "\\end_inset" , i)
2346 # assure we found the end_inset of the current inset
2347 if j > i + 6 or j == -1:
2348 document.warning("Malformed LyX document: Can't find end of line inset.")
2350 # determine the optional offset
2351 k = find_token(document.body, 'offset', i, j)
2353 offset = document.body[k][8:-1]
2356 # determine the width
2357 l = find_token(document.body, 'width', i, j)
2359 width = document.body[l][7:-1]
2362 # determine the height
2363 m = find_token(document.body, 'height', i, j)
2365 height = document.body[m][8:-1]
2368 # output the \rule command
2370 subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}"
2372 subst = "\\rule{" + width + "}{" + height + "}"
2373 document.body[i:j + 1] = put_cmd_in_ert(subst)
2377 def revert_diagram(document):
2378 " Add the feyn package if \\Diagram is used in math "
2380 re_diagram = re.compile(r'\\begin_inset Formula .*\\Diagram', re.DOTALL)
2382 i = find_token(document.body, '\\begin_inset Formula', i)
2385 j = find_end_of_inset(document.body, i)
2387 document.warning("Malformed LyX document: Can't find end of Formula inset.")
2389 m = re_diagram.search("\n".join(document.body[i:j]))
2393 add_to_preamble(document, ["% this command was inserted by lyx2lyx"])
2394 add_to_preamble(document, "\\usepackage{feyn}")
2395 # only need to do it once!
2399 def convert_bibtex_clearpage(document):
2400 " insert a clear(double)page bibliographystyle if bibtotoc option is used "
2402 i = find_token(document.header, '\\papersides', 0)
2404 document.warning("Malformed LyX document: Can't find papersides definition.")
2406 sides = int(document.header[i][12])
2410 j = find_token(document.body, "\\begin_inset CommandInset bibtex", j)
2414 k = find_end_of_inset(document.body, j)
2416 document.warning("Can't find end of Bibliography inset at line " + str(j))
2420 # only act if there is the option "bibtotoc"
2421 m = find_token(document.body, 'options', j, k)
2423 document.warning("Can't find options for bibliography inset at line " + str(j))
2427 optline = document.body[m]
2428 idx = optline.find("bibtotoc")
2433 # so we want to insert a new page right before the paragraph that
2434 # this bibliography thing is in. we'll look for it backwards.
2437 if document.body[lay].startswith("\\begin_layout"):
2442 document.warning("Can't find layout containing bibliography inset at line " + str(j))
2446 subst1 = '\\begin_layout Standard\n' \
2447 + '\\begin_inset Newpage clearpage\n' \
2448 + '\\end_inset\n\n\n' \
2450 subst2 = '\\begin_layout Standard\n' \
2451 + '\\begin_inset Newpage cleardoublepage\n' \
2452 + '\\end_inset\n\n\n' \
2455 document.body.insert(lay, subst1)
2456 document.warning(subst1)
2458 document.body.insert(lay, subst2)
2459 document.warning(subst2)
2468 supported_versions = ["2.0.0","2.0"]
2469 convert = [[346, []],
2475 [352, [convert_splitindex]],
2482 [359, [convert_nomencl_width]],
2492 [369, [convert_author_id]],
2496 [373, [merge_gbrief]],
2502 [379, [convert_math_output]],
2512 [389, [convert_html_quotes]],
2516 [393, [convert_optarg]],
2517 [394, [convert_use_makebox]],
2520 [397, [remove_Nameref]],
2522 [399, [convert_mathdots]],
2523 [400, [convert_rule]],
2525 [402, [convert_bibtex_clearpage]],
2526 [403, [convert_flexnames]],
2527 [404, [convert_prettyref]]
2530 revert = [[403, [revert_refstyle]],
2531 [402, [revert_flexnames]],
2533 [400, [revert_diagram]],
2534 [399, [revert_rule]],
2535 [398, [revert_mathdots]],
2536 [397, [revert_mathrsfs]],
2538 [395, [revert_nameref]],
2539 [394, [revert_DIN_C_pagesizes]],
2540 [393, [revert_makebox]],
2541 [392, [revert_argument]],
2542 [391, [revert_beamer_args]],
2543 [390, [revert_align_decimal, revert_IEEEtran]],
2544 [389, [revert_output_sync]],
2545 [388, [revert_html_quotes]],
2546 [387, [revert_pagesizes]],
2547 [386, [revert_math_scale]],
2548 [385, [revert_lyx_version]],
2549 [384, [revert_shadedboxcolor]],
2550 [383, [revert_fontcolor]],
2551 [382, [revert_turkmen]],
2552 [381, [revert_notefontcolor]],
2553 [380, [revert_equalspacing_xymatrix]],
2554 [379, [revert_inset_preview]],
2555 [378, [revert_math_output]],
2557 [376, [revert_multirow]],
2558 [375, [revert_includeall]],
2559 [374, [revert_includeonly]],
2560 [373, [revert_html_options]],
2561 [372, [revert_gbrief]],
2562 [371, [revert_fontenc]],
2563 [370, [revert_mhchem]],
2564 [369, [revert_suppress_date]],
2565 [368, [revert_author_id]],
2566 [367, [revert_hspace_glue_lengths]],
2567 [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
2568 [365, [revert_percent_skip_lengths]],
2569 [364, [revert_paragraph_indentation]],
2570 [363, [revert_branch_filename]],
2571 [362, [revert_longtable_align]],
2572 [361, [revert_applemac]],
2574 [359, [revert_nomencl_cwidth]],
2575 [358, [revert_nomencl_width]],
2576 [357, [revert_custom_processors]],
2577 [356, [revert_ulinelatex]],
2579 [354, [revert_strikeout]],
2580 [353, [revert_printindexall]],
2581 [352, [revert_subindex]],
2582 [351, [revert_splitindex]],
2583 [350, [revert_backgroundcolor]],
2584 [349, [revert_outputformat]],
2585 [348, [revert_xetex]],
2586 [347, [revert_phantom, revert_hphantom, revert_vphantom]],
2587 [346, [revert_tabularvalign]],
2588 [345, [revert_swiss]]
2592 if __name__ == "__main__":