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 generated by lyx 0.10"""
21 def regularise_header(document):
22 " Place tokens in their 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, starting from position k, if
35 not existing return last position in line."""
39 k = line.find('\\', j)
48 def regularise_body(document):
50 while i < len(document.body):
51 line = document.body[i]
55 k = line.find('\\', j)
65 k = find_next_space(line, j+1)
67 # These tokens take the rest of the line
69 if token in ["added_space_bottom", "added_space_top", "align", "layout", "fill_bottom", "fill_top", "labelwidthstring", "pagebreak_top", "pagebreak_bottom", "noindent"]:
73 # These tokens take no arguments
74 if token in ["backslash", "begin_deeper", "end_deeper", "end_float", "end_inset", "hfill", "newline", "protected_separator"]:
79 # These tokens take one argument
80 if token in ["bar", "begin_float", "family", "latex", "shape", "size", "series", "cursor"]:
81 k = find_next_space(line, k + 1)
86 # Special treatment for insets
87 if token in ["begin_inset"]:
88 l = find_next_space(line, k + 1)
96 if inset in ["LatexCommand", "LatexDel"]:
100 if inset == "Quotes":
101 l = find_next_space(line, l + 1)
108 # We are inside a latex inset, pass the text verbatim
112 document.body[i: i+1] = tmp
116 convert = [[210, [regularise_header, regularise_body]]]
120 if __name__ == "__main__":