]> git.lyx.org Git - features.git/commitdiff
status tag patch from Georg
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 Jan 2004 14:36:43 +0000 (14:36 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 Jan 2004 14:36:43 +0000 (14:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8315 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
development/FORMAT
lib/lyx2lyx/ChangeLog
lib/lyx2lyx/lyxconvert_227.py
lib/lyx2lyx/lyxconvert_228.py
lib/lyx2lyx/lyxrevert_223.py
lib/lyx2lyx/lyxrevert_224.py
lib/lyx2lyx/lyxrevert_225.py
lib/lyx2lyx/lyxrevert_226.py
lib/lyx2lyx/lyxrevert_227.py
lib/lyx2lyx/lyxrevert_228.py
src/insets/ChangeLog
src/insets/insetnote.C
src/tex2lyx/ChangeLog
src/tex2lyx/text.C

index aaf9e3e0366aec5f3e3489535e703c36492a6fb2..f50a4146c291acdcd5dcc84c62a98690a87346cc 100644 (file)
@@ -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>
 
index c609e0b3d86277d09cbe026ca5b093137ca49553..47b069ffc3acb0d9a8254d5241fb7395253998ec 100644 (file)
@@ -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.
index 5ea38b22257808d906c9fb60dd422c24209b9c1c..e6e39d64082769309989f512f2204f1c0fe0e641 100644 (file)
@@ -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
index 33e5af65858574b92276c9da3337a55abebee531..4f6443aaf4a6c468ccd3126678fe57ccece7305e 100644 (file)
@@ -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)
index 7e9fc2c393023cf2c6bbb1a1d06935cc55d75a36..e9c0849382759d04416ee0b8f7961a0b71f9b831 100644 (file)
@@ -1,5 +1,5 @@
 # This file is part of lyx2lyx
-# Copyright (C) 2003 Jos\81é 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
index 1c159145654cf119f6764beef81c8055914f37ae..b5632846729a8f078c3d94f84b557152ce1e7a90 100644 (file)
@@ -1,5 +1,5 @@
 # This file is part of lyx2lyx
-# Copyright (C) 2003 Jos\81é 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
index 2a953dbc8dfe1cf3d34f9baab111c050e3a78e5f..c6d39649abfe883b404542af757dd26006a68ecf 100644 (file)
@@ -1,5 +1,6 @@
 # This file is part of lyx2lyx
-# Copyright (C) 2003 Jos\81é 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
 # 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
index f0d04e5fbad28f50423dfd42d7e42e725e3e73fc..e8db766a82523be976d0a2f1cdae0fc6101ca7a3 100644 (file)
@@ -1,5 +1,5 @@
 # This file is part of lyx2lyx
-# Copyright (C) 2003 Jos\81é 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
index 6aa93635addfe8decdc37c4c23fc0a95590c3216..5b79b20ed53099a991686964b7f5c6944bc87d54 100644 (file)
@@ -1,5 +1,5 @@
 # This file is part of lyx2lyx
-# Copyright (C) 2003 Jos\81é 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
index 1f74e9812c9459110df075b465c683a30dab3308..42352a28298e0ded1a007a7932d92727dbab9540 100644 (file)
@@ -1,5 +1,5 @@
 # This file is part of lyx2lyx
-# Copyright (C) 2003 Jos\81é 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
index 9e265a198f9b7815c75df460b7b94c645f68be90..8d45e2940e5e2f0f04374036434765f085f07e5f 100644 (file)
@@ -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
index c2bd5767fa3c59854b06ee5746037e9ef29b7c7b..3a8c38a2d340545a0251bae1de0aa28ea73860ee 100644 (file)
@@ -82,7 +82,6 @@ void InsetNoteParams::write(ostream & os) const
 {
        string const label = notetranslator().find(type);
        os << "Note " << label << "\n";
-       os << label << "\n";
 }
 
 
index 9a58ad4aab1e3bdd4147564b3855317b7bc51661..e9aa267f95bcc903199969d2dc95b9c3d690253e 100644 (file)
@@ -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>
 
index 5177d30762a9bf4bc864886660723b842d1c65a2..e8a651270f23cb6993693fd786adf296c2329db7 100644 (file)
@@ -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 == '\\')