2004-03-29 13:17:25 +00:00
|
|
|
# This file is part of lyx2lyx
|
2006-08-02 14:19:22 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# 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
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
""" Convert files to the file format generated by lyx 1.0"""
|
|
|
|
|
2005-11-24 12:25:26 +00:00
|
|
|
import re
|
|
|
|
from parser_tools import find_token, find_re
|
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
def obsolete_latex_title(document):
|
|
|
|
" Replace LatexTitle layout with Title. "
|
|
|
|
|
|
|
|
body = document.body
|
2005-11-24 12:25:26 +00:00
|
|
|
i = 0
|
|
|
|
while 1:
|
|
|
|
i = find_token(body, '\\layout', i)
|
|
|
|
if i == -1:
|
|
|
|
return
|
|
|
|
|
2006-08-02 15:45:44 +00:00
|
|
|
if body[i].lower().find('latex title') != -1:
|
2005-11-24 12:25:26 +00:00
|
|
|
body[i] = '\\layout Title'
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
2006-08-02 14:19:22 +00:00
|
|
|
def update_tabular(document):
|
|
|
|
" Update from tabular format 3 to 4 if necessary."
|
|
|
|
|
|
|
|
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
|
2005-11-24 12:25:26 +00:00
|
|
|
while 1:
|
|
|
|
i = find_re(lines, lyxtable_re, i)
|
|
|
|
if i == -1:
|
|
|
|
break
|
|
|
|
i = i + 1
|
|
|
|
format = lines[i][8:]
|
|
|
|
|
|
|
|
if format != '3':
|
|
|
|
continue
|
|
|
|
|
2006-08-02 14:19:22 +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
|
|
|
|
|
|
|
lines[i] = lines[i] + ' 0 0 -1 -1 -1 -1'
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
for j in range(rows):
|
|
|
|
lines[i] = lines[i] + ' 0 0'
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
for j in range(columns):
|
|
|
|
lines[i] = lines[i] + ' '
|
|
|
|
i = i + 1
|
|
|
|
|
2006-08-02 15:45:44 +00:00
|
|
|
while lines[i].strip():
|
2005-11-24 12:25:26 +00:00
|
|
|
lines[i] = lines[i] + ' 0 0 0'
|
|
|
|
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-02 14:19:22 +00:00
|
|
|
supported_versions = ["1.0.0","1.0"]
|
2005-11-24 12:25:26 +00:00
|
|
|
convert = [[215, [obsolete_latex_title, update_tabular]]]
|
2005-01-05 18:52:59 +00:00
|
|
|
revert = []
|
2004-03-29 13:17:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|
2004-04-14 08:45:46 +00:00
|
|
|
|