2004-03-29 13:17:25 +00:00
|
|
|
# This file is part of lyx2lyx
|
2006-08-02 14:19:22 +00:00
|
|
|
# Copyright (C) 2004 José Matos <jamatos@lyx.org>
|
2004-03-29 13:17:25 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2011-08-25 23:10:36 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-03-29 13:17:25 +00:00
|
|
|
|
2024-06-15 09:06:06 +00:00
|
|
|
"""Convert files to the file format generated by lyx 1.0"""
|
2006-08-02 14:19:22 +00:00
|
|
|
|
2005-11-24 12:25:26 +00:00
|
|
|
import re
|
2024-06-18 09:25:52 +00:00
|
|
|
|
|
|
|
from parser_tools import find_re, find_token
|
2005-11-24 12:25:26 +00:00
|
|
|
|
2024-06-15 09:06:06 +00:00
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
def obsolete_latex_title(document):
|
2024-06-15 09:06:06 +00:00
|
|
|
"Replace LatexTitle layout with Title."
|
2006-08-02 14:19:22 +00:00
|
|
|
|
|
|
|
body = document.body
|
2005-11-24 12:25:26 +00:00
|
|
|
i = 0
|
2016-06-25 21:37:13 +00:00
|
|
|
while True:
|
2024-06-15 09:06:06 +00:00
|
|
|
i = find_token(body, "\\layout", i)
|
2005-11-24 12:25:26 +00:00
|
|
|
if i == -1:
|
|
|
|
return
|
|
|
|
|
2024-06-15 09:06:06 +00:00
|
|
|
if body[i].lower().find("latex title") != -1:
|
|
|
|
body[i] = "\\layout Title"
|
2005-11-24 12:25:26 +00:00
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
def update_tabular(document):
|
2024-06-15 09:06:06 +00:00
|
|
|
"Update from tabular format 3 to 4 if necessary."
|
2006-08-02 14:19:22 +00:00
|
|
|
|
|
|
|
lines = document.body
|
2005-11-24 12:25:26 +00:00
|
|
|
lyxtable_re = re.compile(r".*\\LyXTable$")
|
2006-08-02 14:19:22 +00:00
|
|
|
i = 0
|
2016-06-25 21:37:13 +00:00
|
|
|
while True:
|
2005-11-24 12:25:26 +00:00
|
|
|
i = find_re(lines, lyxtable_re, i)
|
|
|
|
if i == -1:
|
|
|
|
break
|
|
|
|
i = i + 1
|
|
|
|
format = lines[i][8:]
|
|
|
|
|
2024-06-15 09:06:06 +00:00
|
|
|
if format != "3":
|
2005-11-24 12:25:26 +00:00
|
|
|
continue
|
|
|
|
|
2024-06-15 09:06:06 +00:00
|
|
|
lines[i] = "multicol4"
|
2005-11-24 12:25:26 +00:00
|
|
|
i = i + 1
|
2006-08-02 15:45:44 +00:00
|
|
|
rows = int(lines[i].split()[0])
|
|
|
|
columns = int(lines[i].split()[1])
|
2005-11-24 12:25:26 +00:00
|
|
|
|
2024-06-15 09:06:06 +00:00
|
|
|
lines[i] = lines[i] + " 0 0 -1 -1 -1 -1"
|
2005-11-24 12:25:26 +00:00
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
for j in range(rows):
|
2024-06-15 09:06:06 +00:00
|
|
|
lines[i] = lines[i] + " 0 0"
|
2005-11-24 12:25:26 +00:00
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
for j in range(columns):
|
2024-06-15 09:06:06 +00:00
|
|
|
lines[i] = lines[i] + " "
|
2005-11-24 12:25:26 +00:00
|
|
|
i = i + 1
|
|
|
|
|
2006-08-02 15:45:44 +00:00
|
|
|
while lines[i].strip():
|
2024-06-15 09:06:06 +00:00
|
|
|
lines[i] = lines[i] + " 0 0 0"
|
2005-11-24 12:25:26 +00:00
|
|
|
i = i + 1
|
|
|
|
|
2006-08-02 15:45:44 +00:00
|
|
|
lines[i] = lines[i].strip()
|
2005-11-24 12:25:26 +00:00
|
|
|
|
|
|
|
|
2006-08-07 14:10:41 +00:00
|
|
|
supported_versions = ["1.0.%d" % i for i in range(5)] + ["1.0"]
|
2005-11-24 12:25:26 +00:00
|
|
|
convert = [[215, [obsolete_latex_title, update_tabular]]]
|
2024-06-15 09:06:06 +00:00
|
|
|
revert = []
|
2004-03-29 13:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|