1 # This file is part of lyx2lyx
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2006 José Matos <jamatos@lyx.org>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 """ Convert files to the file format generated by lyx 0.10"""
21 def regularise_header(document):
22 " Put each entry in header into a separate line. "
24 while i < len(document.header):
25 line = document.header[i]
26 if len(line.split('\\')) > 1:
27 tmp = [ '\\'+ token.strip() for token in line.split('\\')][1:]
28 document.header[i: i+1] = tmp
33 def find_next_space(line, j):
34 """ Return position of next space or backslash, which one comes
35 first, starting from position k, if not existing return last
40 k = line.find('\\', j)
49 def regularise_body(document):
50 """ Place tokens starting with a backslash into a separate line. """
52 getline_tokens = ["added_space_bottom", "added_space_top",
53 "align", "layout", "fill_bottom", "fill_top",
54 "labelwidthstring", "pagebreak_top",
55 "pagebreak_bottom", "noindent"]
57 noargs_tokens = ["backslash", "begin_deeper", "end_deeper",
58 "end_float", "end_inset", "hfill", "newline",
59 "protected_separator"]
61 onearg_tokens = ["bar", "begin_float", "family", "latex", "shape",
62 "size", "series", "cursor"]
65 while i < len(document.body):
66 line = document.body[i]
70 k = line.find('\\', j)
80 k = find_next_space(line, j+1)
82 # These tokens take the rest of the line
84 if token in getline_tokens:
88 # These tokens take no arguments
89 if token in noargs_tokens:
94 # These tokens take one argument
95 if token in onearg_tokens:
96 k = find_next_space(line, k + 1)
101 # Special treatment for insets
102 if token in ["begin_inset"]:
103 l = find_next_space(line, k + 1)
111 if inset in ["LatexCommand", "LatexDel"]:
115 if inset == "Quotes":
116 l = find_next_space(line, l + 1)
121 document.warning("unkown inset %s" % line)
124 # We are inside a latex inset, pass the text verbatim
128 document.body[i: i+1] = tmp
132 supported_versions = ["0.10.%d" % i for i in range(8)] + ["0.10"]
133 convert = [[210, [regularise_header, regularise_body]]]
137 if __name__ == "__main__":