# This file is part of lyx2lyx
# -*- coding: utf-8 -*-
-# Copyright (C) 2002-2011 The LyX Team
+# Copyright (C) 2002-2015 The LyX Team
# Copyright (C) 2002-2004 Dekel Tsur <dekel@lyx.org>
# Copyright (C) 2002-2006 José Matos <jamatos@lyx.org>
#
import lyx2lyx_version
version__ = lyx2lyx_version.version
except: # we are running from build directory so assume the last version
- version__ = '2.1'
+ 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_1_6_3", [218], ["1.1", "1.1.6.3","1.1.6.4"]),
("1_2", [220], minor_versions("1.2" , 4)),
("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" , 10)),
- ("2_0", range(346,414), minor_versions("2.0", 0)),
- ("2_1", range(414,475), minor_versions("2.1", 0))
+ # Note that range(i,j) is up to j *excluded*.
+ ("1_4", list(range(222,246)), minor_versions("1.4" , 5)),
+ ("1_5", list(range(246,277)), minor_versions("1.5" , 7)),
+ ("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
+ ("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
+ ("2_1", list(range(414,475)), minor_versions("2.1" , 5)),
+ ("2_2", list(range(475,509)), minor_versions("2.2" , 0))
]
####################################################################
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:
def __init__(self, end_format = 0, input = "", output = "", error = "",
debug = default_debug__, try_hard = 0, cjk_encoding = '',
- final_version = "", language = "english", encoding = "auto"):
+ final_version = "", systemlyxdir = '', language = "english",
+ encoding = "auto"):
"""Arguments:
end_format: final format that the file should be converted. (integer)
self.status = 0
self.encoding = encoding
self.language = language
+ self.systemlyxdir = systemlyxdir
def warning(self, message, debug_level= default_debug__):
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)
def set_version(self):
" Set the header with the version used."
- self.header[0] = " ".join(["#LyX %s created this file." % version__,
- "For more info see http://www.lyx.org/"])
+
+ initial_comment = " ".join(["#LyX %s created this file." % version__,
+ "For more info see http://www.lyx.org/"])
+
+ # Simple heuristic to determine the comment that always starts
+ # a lyx file
+ if self.header[0].startswith("#"):
+ self.header[0] = initial_comment
+ else:
+ self.header.insert(0, initial_comment)
+
+ # Old lyx files had a two lines comment header:
+ # 1) the first line had the user who had created it
+ # 2) the second line had the lyx version used
+ # later we decided that 1) was a privacy risk for no gain
+ # here we remove the second line effectively erasing 1)
if self.header[1][0] == '#':
del self.header[1]
def convert(self):
"Convert from current (self.format) to self.end_format."
+ if self.format == self.end_format:
+ self.warning("No conversion needed: Target format %s "
+ "same as current format!" % self.format, default_debug__)
+ return
+
mode, conversion_chain = self.chain()
self.warning("conversion chain: " + str(conversion_chain), 3)
def __init__(self, end_format = 0, input = "", output = "", error = "",
debug = default_debug__, try_hard = 0, cjk_encoding = '',
- final_version = ''):
+ final_version = '', systemlyxdir = ''):
LyX_base.__init__(self, end_format, input, output, error,
- debug, try_hard, cjk_encoding, final_version)
+ debug, try_hard, cjk_encoding, final_version,
+ systemlyxdir)
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",