mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 21:55:29 +00:00
status tag patch from Georg
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8315 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8af1fa7aeb
commit
30f1fd59ae
@ -11,9 +11,13 @@ LyX file-format changes
|
||||
|
||||
* format incremented to 228.
|
||||
* Change the output of all insets derived from InsetCollapsable
|
||||
except for InsetERT (which has this output already), changing lines
|
||||
except for InsetERT (which has a similar output already), changing lines
|
||||
"collapsed true" -> "status collapsed"
|
||||
"collapsed false" -> "status open".
|
||||
* Change the output of InsetERT, changing lines
|
||||
"status Collapsed" -> "status collapsed"
|
||||
"status Open" -> "status open".
|
||||
"status Inlined" -> "status inlined".
|
||||
|
||||
2003-12-10 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
|
@ -1,3 +1,12 @@
|
||||
2004-01-06 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* lyxrevert_228.py: convert ERT status, too
|
||||
* lyxconvert_227.py: ditto, also stop at \\begin_alyout and not
|
||||
\\layout in convert_collapsable()
|
||||
* lyxconvert_228.py (convert_minipage): Add status tag conversion
|
||||
* lyxrevert_225.py: Convert vspace and frameless box insets
|
||||
* lyxrevert_22[3-8].py: fix the 'é' in José's name
|
||||
|
||||
2003-12-29 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
|
||||
|
||||
* lyx2lyx: up the format to 229.
|
||||
|
@ -16,7 +16,7 @@
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
import sys
|
||||
from parser_tools import find_tokens
|
||||
from parser_tools import find_token, find_tokens
|
||||
|
||||
def convert_collapsable(lines):
|
||||
i = 0
|
||||
@ -34,8 +34,8 @@ def convert_collapsable(lines):
|
||||
break
|
||||
|
||||
# Seach for a line starting 'collapsed'
|
||||
# If, however, we find a line starting '\layout' (_always_ present)
|
||||
# then break with a warning message
|
||||
# If, however, we find a line starting '\begin_layout'
|
||||
# (_always_ present) then break with a warning message
|
||||
i = i + 1
|
||||
while 1:
|
||||
if (lines[i] == "collapsed false"):
|
||||
@ -44,16 +44,44 @@ def convert_collapsable(lines):
|
||||
elif (lines[i] == "collapsed true"):
|
||||
lines[i] = "status collapsed"
|
||||
break
|
||||
elif (lines[i][:7] == "\\layout"):
|
||||
elif (lines[i][:13] == "\\begin_layout"):
|
||||
sys.stderr.write("Malformed lyx file\n")
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
i = i + 1
|
||||
|
||||
def convert_ert(lines):
|
||||
i = 0
|
||||
while 1:
|
||||
i = find_token(lines, "\\begin_inset ERT", i)
|
||||
if i == -1:
|
||||
break
|
||||
|
||||
# Seach for a line starting 'status'
|
||||
# If, however, we find a line starting '\begin_layout'
|
||||
# (_always_ present) then break with a warning message
|
||||
i = i + 1
|
||||
while 1:
|
||||
if (lines[i] == "status Open"):
|
||||
lines[i] = "status open"
|
||||
break
|
||||
elif (lines[i] == "status Collapsed"):
|
||||
lines[i] = "status collapsed"
|
||||
break
|
||||
elif (lines[i] == "status Inlined"):
|
||||
lines[i] = "status inlined"
|
||||
break
|
||||
elif (lines[i][:13] == "\\begin_layout"):
|
||||
sys.stderr.write("Malformed lyx file\n")
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
i = i + 1
|
||||
|
||||
def convert(header, body):
|
||||
convert_collapsable(body)
|
||||
convert_ert(body)
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
@ -73,6 +73,15 @@ def convert_minipage(lines):
|
||||
else:
|
||||
width = ' "0"'
|
||||
|
||||
if lines[i][:9] == "collapsed":
|
||||
if lines[i][9:] == "true":
|
||||
status = "collapsed"
|
||||
else:
|
||||
status = "open"
|
||||
del lines[i]
|
||||
else:
|
||||
status = "collapsed"
|
||||
|
||||
lines.insert(i, 'use_parbox 0')
|
||||
i = i + 1
|
||||
lines.insert(i, 'width' + width)
|
||||
@ -83,6 +92,8 @@ def convert_minipage(lines):
|
||||
i = i + 1
|
||||
lines.insert(i, 'height_special "totalheight"')
|
||||
i = i + 1
|
||||
lines.insert(i, 'status ' + status)
|
||||
i = i + 1
|
||||
|
||||
def convert(header, body):
|
||||
convert_minipage(body)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# This file is part of lyx2lyx
|
||||
# Copyright (C) 2003 Jos<EFBFBD>é Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -1,5 +1,5 @@
|
||||
# This file is part of lyx2lyx
|
||||
# Copyright (C) 2003 Jos<EFBFBD>é Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -1,5 +1,6 @@
|
||||
# This file is part of lyx2lyx
|
||||
# Copyright (C) 2003 Jos<6F>é Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@ -16,8 +17,10 @@
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
import re
|
||||
from parser_tools import find_token, find_end_of_inset
|
||||
from string import replace
|
||||
from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \
|
||||
get_paragraph, get_value, del_token, is_nonempty_line
|
||||
from string import find, replace, split
|
||||
import sys
|
||||
|
||||
def rm_end_layout(lines):
|
||||
i = 0
|
||||
@ -65,11 +68,235 @@ def end_document(lines):
|
||||
return
|
||||
lines[i] = "\\the_end"
|
||||
|
||||
# Convert backslashes into valid ERT code, append the converted text to
|
||||
# lines[i] and return the (maybe incremented) line index i
|
||||
def convert_ertbackslash(lines, i, ert):
|
||||
for c in ert:
|
||||
if c == '\\':
|
||||
lines[i] = lines[i] + '\\backslash '
|
||||
lines.insert(i, '')
|
||||
i = i + 1
|
||||
else:
|
||||
lines[i] = lines[i] + c
|
||||
return i
|
||||
|
||||
def convert_vspace(header, lines):
|
||||
|
||||
# Get default spaceamount
|
||||
i = find_token(header, '\\defskip', 0)
|
||||
if i == -1:
|
||||
defskipamount = 'medskip'
|
||||
else:
|
||||
defskipamount = split(header[i])[1]
|
||||
|
||||
# Convert the insets
|
||||
i = 0
|
||||
while 1:
|
||||
i = find_token(lines, '\\begin_inset VSpace', i)
|
||||
if i == -1:
|
||||
return
|
||||
spaceamount = split(lines[i])[2]
|
||||
|
||||
# Are we at the beginning or end of a paragraph?
|
||||
paragraph_start = 1
|
||||
start = get_paragraph(lines, i) + 1
|
||||
for k in range(start, i):
|
||||
if is_nonempty_line(lines[k]):
|
||||
paragraph_start = 0
|
||||
break
|
||||
paragraph_end = 1
|
||||
j = find_end_of_inset(lines, i)
|
||||
if j == -1:
|
||||
sys.stderr.write("Malformed lyx file: Missing '\\end_inset'\n")
|
||||
i = i + 1
|
||||
continue
|
||||
end = get_next_paragraph(lines, i)
|
||||
for k in range(j + 1, end):
|
||||
if is_nonempty_line(lines[k]):
|
||||
paragraph_end = 0
|
||||
break
|
||||
|
||||
# Convert to paragraph formatting if we are at the beginning or end
|
||||
# of a paragraph and the resulting paragraph would not be empty
|
||||
if ((paragraph_start and not paragraph_end) or
|
||||
(paragraph_end and not paragraph_start)):
|
||||
# The order is important: del and insert invalidate some indices
|
||||
del lines[j]
|
||||
del lines[i]
|
||||
if paragraph_start:
|
||||
lines.insert(start, '\\added_space_top ' + spaceamount + ' ')
|
||||
else:
|
||||
lines.insert(start, '\\added_space_bottom ' + spaceamount + ' ')
|
||||
continue
|
||||
|
||||
# Convert to ERT
|
||||
lines[i:i+1] = ['\\begin_inset ERT', 'status Collapsed', '',
|
||||
'\\layout Standard', '', '\\backslash ']
|
||||
i = i + 6
|
||||
if spaceamount[-1] == '*':
|
||||
spaceamount = spaceamount[:-1]
|
||||
keep = 1
|
||||
else:
|
||||
keep = 0
|
||||
|
||||
# Replace defskip by the actual value
|
||||
if spaceamount == 'defskip':
|
||||
spaceamount = defskipamount
|
||||
|
||||
# LaTeX does not know \\smallskip* etc
|
||||
if keep:
|
||||
if spaceamount == 'smallskip':
|
||||
spaceamount = '\\smallskipamount'
|
||||
elif spaceamount == 'medskip':
|
||||
spaceamount = '\\medskipamount'
|
||||
elif spaceamount == 'bigskip':
|
||||
spaceamount = '\\bigskipamount'
|
||||
elif spaceamount == 'vfill':
|
||||
spaceamount = '\\fill'
|
||||
|
||||
# Finally output the LaTeX code
|
||||
if (spaceamount == 'smallskip' or spaceamount == 'medskip' or
|
||||
spaceamount == 'bigskip' or spaceamount == 'vfill'):
|
||||
lines.insert(i, spaceamount)
|
||||
else :
|
||||
if keep:
|
||||
lines.insert(i, 'vspace*{')
|
||||
else:
|
||||
lines.insert(i, 'vspace{')
|
||||
i = convert_ertbackslash(lines, i, spaceamount)
|
||||
lines[i] = lines[i] + '}'
|
||||
i = i + 1
|
||||
|
||||
# Convert a LyX length into valid ERT code and append it to lines[i]
|
||||
# Return the (maybe incremented) line index i
|
||||
def convert_ertlen(lines, i, len, special):
|
||||
units = {"text%":"\\textwidth", "col%":"\\columnwidth",
|
||||
"page%":"\\pagewidth", "line%":"\\linewidth",
|
||||
"theight%":"\\textheight", "pheight%":"\\pageheight"}
|
||||
|
||||
# Convert special lengths
|
||||
if special != 'none':
|
||||
len = '%f\\' % len2value(len) + special
|
||||
|
||||
# Convert LyX units to LaTeX units
|
||||
for unit in units.keys():
|
||||
if find(len, unit) != -1:
|
||||
len = '%f' % (len2value(len) / 100) + units[unit]
|
||||
break
|
||||
|
||||
# Convert backslashes and insert the converted length into lines
|
||||
return convert_ertbackslash(lines, i, len)
|
||||
|
||||
# Return the value of len without the unit in numerical form
|
||||
def len2value(len):
|
||||
result = re.search('([+-]?[0-9.]+)', len)
|
||||
if result:
|
||||
return float(result.group(1))
|
||||
# No number means 1.0
|
||||
return 1.0
|
||||
|
||||
def convert_frameless_box(lines):
|
||||
pos = ['t', 'c', 'b']
|
||||
inner_pos = ['c', 't', 'b', 's']
|
||||
i = 0
|
||||
while 1:
|
||||
i = find_token(lines, '\\begin_inset Frameless', i)
|
||||
if i == -1:
|
||||
return
|
||||
j = find_end_of_inset(lines, i)
|
||||
if j == -1:
|
||||
sys.stderr.write("Malformed lyx file: Missing '\\end_inset'\n")
|
||||
i = i + 1
|
||||
continue
|
||||
del lines[i]
|
||||
|
||||
# Gather parameters
|
||||
params = {'position':'0', 'hor_pos':'c', 'has_inner_box':'1',
|
||||
'inner_pos':'1', 'use_parbox':'0', 'width':'100col%',
|
||||
'special':'none', 'height':'1in',
|
||||
'height_special':'totalheight', 'collapsed':'false'}
|
||||
for key in params.keys():
|
||||
value = replace(get_value(lines, key, i, j), '"', '')
|
||||
if value != "":
|
||||
if key == 'position':
|
||||
# convert new to old position: 'position "t"' -> 0
|
||||
value = find_token(pos, value, 0)
|
||||
if value != -1:
|
||||
params[key] = value
|
||||
elif key == 'inner_pos':
|
||||
# convert inner position
|
||||
value = find_token(inner_pos, value, 0)
|
||||
if value != -1:
|
||||
params[key] = value
|
||||
else:
|
||||
params[key] = value
|
||||
j = del_token(lines, key, i, j)
|
||||
i = i + 1
|
||||
|
||||
# Convert to minipage or ERT?
|
||||
# Note that the inner_position and height parameters of a minipage
|
||||
# inset are ignored and not accessible for the user, although they
|
||||
# are present in the file format and correctly read in and written.
|
||||
# Therefore we convert to ERT if they do not have their LaTeX
|
||||
# defaults. These are:
|
||||
# - the value of "position" for "inner_pos"
|
||||
# - "\totalheight" for "height"
|
||||
if (params['use_parbox'] != '0' or
|
||||
params['has_inner_box'] != '1' or
|
||||
params['special'] != 'none' or
|
||||
inner_pos[params['inner_pos']] != pos[params['position']] or
|
||||
params['height_special'] != 'totalheight' or
|
||||
len2value(params['height']) != 1.0):
|
||||
|
||||
# Convert to ERT
|
||||
if params['collapsed'] == 'true':
|
||||
params['collapsed'] = 'Collapsed'
|
||||
else:
|
||||
params['collapsed'] = 'Open'
|
||||
lines[i : i] = ['\\begin_inset ERT', 'status ' + params['collapsed'],
|
||||
'', '\\layout Standard', '', '\\backslash ']
|
||||
i = i + 6
|
||||
if params['use_parbox'] == '1':
|
||||
lines.insert(i, 'parbox')
|
||||
else:
|
||||
lines.insert(i, 'begin{minipage}')
|
||||
lines[i] = lines[i] + '[' + pos[params['position']] + ']['
|
||||
i = convert_ertlen(lines, i, params['height'], params['height_special'])
|
||||
lines[i] = lines[i] + '][' + inner_pos[params['inner_pos']] + ']{'
|
||||
i = convert_ertlen(lines, i, params['width'], params['special'])
|
||||
lines[i] = lines[i] + '}{'
|
||||
i = i + 1
|
||||
lines[i:i] = ['', '\\end_inset ']
|
||||
i = i + 2
|
||||
j = find_end_of_inset(lines, i)
|
||||
if j == -1:
|
||||
sys.stderr.write("Malformed lyx file: Missing '\\end_inset'\n")
|
||||
break
|
||||
lines[j-1:j-1] += ['\\begin_inset ERT', 'status ' + params['collapsed'],
|
||||
'', '\\layout Standard', '']
|
||||
j = j + 4
|
||||
if params['use_parbox'] == '1':
|
||||
lines.insert(j, '}')
|
||||
else:
|
||||
lines[j:j] = ['\\backslash ', 'end{minipage}']
|
||||
else:
|
||||
|
||||
# Convert to minipage
|
||||
lines[i:i] = ['\\begin_inset Minipage',
|
||||
'position %d' % params['position'],
|
||||
'inner_position %d' % params['inner_pos'],
|
||||
'height "' + params['height'] + '"',
|
||||
'width "' + params['width'] + '"',
|
||||
'collapsed ' + params['collapsed']]
|
||||
i = i + 6
|
||||
|
||||
def convert(header, body):
|
||||
rm_end_layout(body)
|
||||
begin_layout2layout(body)
|
||||
end_document(body)
|
||||
valignment_middle(body)
|
||||
convert_vspace(header, body)
|
||||
convert_frameless_box(body)
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
@ -1,5 +1,5 @@
|
||||
# This file is part of lyx2lyx
|
||||
# Copyright (C) 2003 Jos<EFBFBD>é Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -1,5 +1,5 @@
|
||||
# This file is part of lyx2lyx
|
||||
# Copyright (C) 2003 Jos<EFBFBD>é Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -1,5 +1,5 @@
|
||||
# This file is part of lyx2lyx
|
||||
# Copyright (C) 2003 Jos<EFBFBD>é Matos <jamatos@fep.up.pt>
|
||||
# Copyright (C) 2003 José Matos <jamatos@fep.up.pt>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@ -16,7 +16,7 @@
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
import sys
|
||||
from parser_tools import find_tokens
|
||||
from parser_tools import find_token, find_tokens
|
||||
|
||||
def convert_collapsable(lines):
|
||||
i = 0
|
||||
@ -33,13 +33,12 @@ def convert_collapsable(lines):
|
||||
if i == -1:
|
||||
break
|
||||
|
||||
# Seach for a line starting 'collapsed'
|
||||
# If, however, we find a line starting '\layout' (_always_ present)
|
||||
# then break with a warning message
|
||||
# Seach for a line starting 'status'
|
||||
# If, however, we find a line starting '\begin_layout'
|
||||
# (_always_ present) then break with a warning message
|
||||
i = i + 1
|
||||
while 1:
|
||||
if (lines[i] == "status open"):
|
||||
lines[i] = "collapsed false"
|
||||
lines[i] = "collapsed false"
|
||||
break
|
||||
elif (lines[i] == "status collapsed" or
|
||||
@ -53,8 +52,37 @@ def convert_collapsable(lines):
|
||||
|
||||
i = i + 1
|
||||
|
||||
def convert_ert(lines):
|
||||
i = 0
|
||||
while 1:
|
||||
i = find_token(lines, "\\begin_inset ERT", i)
|
||||
if i == -1:
|
||||
break
|
||||
|
||||
# Seach for a line starting 'status'
|
||||
# If, however, we find a line starting '\begin_layout'
|
||||
# (_always_ present) then break with a warning message
|
||||
i = i + 1
|
||||
while 1:
|
||||
if (lines[i] == "status open"):
|
||||
lines[i] = "status Open"
|
||||
break
|
||||
elif (lines[i] == "status collapsed"):
|
||||
lines[i] = "status Collapsed"
|
||||
break
|
||||
elif (lines[i] == "status inlined"):
|
||||
lines[i] = "status Inlined"
|
||||
break
|
||||
elif (lines[i][:13] == "\\begin_layout"):
|
||||
sys.stderr.write("Malformed lyx file\n")
|
||||
break
|
||||
i = i + 1
|
||||
|
||||
i = i + 1
|
||||
|
||||
def convert(header, body):
|
||||
convert_collapsable(body)
|
||||
convert_ert(body)
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
@ -1,3 +1,7 @@
|
||||
2004-01-06 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* insetnote.C (InsetNoteParams::write): write label only once
|
||||
|
||||
2004-01-05 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* insetbranch.C (isBranchSelected): use the BranchNamesEqual
|
||||
|
@ -82,7 +82,6 @@ void InsetNoteParams::write(ostream & os) const
|
||||
{
|
||||
string const label = notetranslator().find(type);
|
||||
os << "Note " << label << "\n";
|
||||
os << label << "\n";
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
2004-01-06 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* text.C: fix status tag output for ERT inset
|
||||
|
||||
2003-12-17 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* preamble.C: Change file format from 225 to 228
|
||||
@ -5,7 +9,6 @@
|
||||
* text.C: Changes for format 228 (see ../../development/FORMAT)
|
||||
* text.C: Add lyxgreyedout environment
|
||||
* context.[Ch]: New function Context::add_extra_stuff()
|
||||
* context.[Ch]: Add ~Context() with warning message
|
||||
|
||||
2003-12-08 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
|
@ -253,7 +253,7 @@ void handle_ert(ostream & os, string const & s, Context & context, bool check_la
|
||||
}
|
||||
Context newcontext(true, context.textclass);
|
||||
begin_inset(os, "ERT");
|
||||
os << "\nstatus Collapsed\n";
|
||||
os << "\nstatus collapsed\n";
|
||||
newcontext.check_layout(os);
|
||||
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
|
||||
if (*it == '\\')
|
||||
@ -271,7 +271,7 @@ void handle_comment(ostream & os, string const & s, Context & context)
|
||||
// TODO: Handle this better
|
||||
Context newcontext(true, context.textclass);
|
||||
begin_inset(os, "ERT");
|
||||
os << "\nstatus Collapsed\n";
|
||||
os << "\nstatus collapsed\n";
|
||||
newcontext.check_layout(os);
|
||||
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
|
||||
if (*it == '\\')
|
||||
|
Loading…
Reference in New Issue
Block a user