# This file is part of lyx2lyx
# -*- coding: utf-8 -*-
+# Copyright (C) 2002-2011 The LyX Team
# Copyright (C) 2002-2004 Dekel Tsur <dekel@lyx.org>
# Copyright (C) 2002-2006 José Matos <jamatos@lyx.org>
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
" The LyX module has all the rules related with different lyx file formats."
import lyx2lyx_version
version__ = lyx2lyx_version.version
except: # we are running from build directory so assume the last version
- version__ = '2.0.0svn'
+ version__ = '2.2'
default_debug__ = 2
format_re = re.compile(r"(\d)[\.,]?(\d\d)")
fileformat = re.compile(r"\\lyxformat\s*(\S*)")
original_version = re.compile(r".*?LyX ([\d.]*)")
+original_tex2lyx_version = re.compile(r".*?tex2lyx ([\d.]*)")
##
# file format information:
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 7)),
- ("1_6", range(277,346), minor_versions("1.6" , 0)),
- ("2_0", [], minor_versions("2.0", 0))]
+ ("1_6", range(277,346), minor_versions("1.6" , 10)),
+ ("2_0", range(346,414), minor_versions("2.0", 8)),
+ ("2_1", range(414,475), minor_versions("2.1", 0)),
+ ("2_2", range(475,483), minor_versions("2.2", 0))
+ ]
####################################################################
# This is useful just for development versions #
def get_end_format():
" Returns the more recent file format available."
- return format_relation[-1][1][-1]
+ # this check will fail only when we have a new version
+ # and there is no format change yet.
+ if format_relation[-1][1]:
+ return format_relation[-1][1][-1]
+ return format_relation[-2][1][-1]
def get_backend(textclass):
def trim_eol(line):
" Remove end of line char(s)."
+ if line[-1] != '\n' and line[-1] != '\r':
+ # May happen for the last line of a document
+ return line
if line[-2:-1] == '\r':
return line[:-2]
else:
self.initial_version = self.read_version()
# Second pass over header and preamble, now we know the file encoding
+ # Do not forget the textclass (Debian bug #700828)
+ self.textclass = self.textclass.decode(self.encoding)
for i in range(len(self.header)):
self.header[i] = self.header[i].decode(self.encoding)
for i in range(len(self.preamble)):
return None
line = line.replace("fix",".")
- result = original_version.match(line)
+ # need to test original_tex2lyx_version first because tex2lyx
+ # writes "#LyX file created by tex2lyx 2.2"
+ result = original_tex2lyx_version.match(line)
+ if not result:
+ result = original_version.match(line)
+ if result:
+ # Special know cases: reLyX and KLyX
+ if line.find("reLyX") != -1 or line.find("KLyX") != -1:
+ return "0.12"
if result:
- # Special know cases: reLyX and KLyX
- if line.find("reLyX") != -1 or line.find("KLyX") != -1:
- return "0.12"
-
res = result.group(1)
if not res:
self.warning(line)
return mode, steps
+# Part of an unfinished attempt to make lyx2lyx gave a more
+# structured view of the document.
# def get_toc(self, depth = 4):
# " Returns the TOC of this LyX document."
# paragraphs_filter = {'Title' : 0,'Chapter' : 1, 'Section' : 2,
self.read()
+# FIXME: header settings are completely outdated, don't use like this
#class NewFile(LyX_base):
# " This class is to create new LyX files."
# def set_header(self, **params):
# "\\use_amsmath 1",
# "\\cite_engine basic",
# "\\use_bibtopic false",
+# "\\use_indices false",
# "\\paperorientation portrait",
# "\\secnumdepth 3",
# "\\tocdepth 3",
# self.body.extend(['','\\end_body', '\\end_document'])
+# Part of an unfinished attempt to make lyx2lyx gave a more
+# structured view of the document.
#class Paragraph:
# # unfinished implementation, it is missing the Text and Insets
# # representation.