]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx2lyx_tools.py
Don't use widest label for numerical citations.
[lyx.git] / lib / lyx2lyx / lyx2lyx_tools.py
index 426e11d9693909f84ee93e6f2322c6dc2197cf99..1edd1fbfc85f28c26de2cae4ed08d3f794bf6f9e 100644 (file)
@@ -1,6 +1,6 @@
 # This file is part of lyx2lyx
 # -*- coding: utf-8 -*-
-# Copyright (C) 2010 The LyX team
+# Copyright (C) 2011 The LyX team
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -14,7 +14,7 @@
 #
 # 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.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 '''
 This modules offer several free functions to help with lyx2lyx'ing. 
@@ -60,12 +60,12 @@ latex_length(slen):
 '''
 
 import string
-from parser_tools import find_token
+from parser_tools import find_token, find_end_of_inset
 from unicode_symbols import unicode_reps
 
 
 # This will accept either a list of lines or a single line.
-# It is bad practice to pass something with embedded newlines, 
+# It is bad practice to pass something with embedded newlines,
 # though we will handle that.
 def add_to_preamble(document, text):
     " Add text to the preamble if it is not already there. "
@@ -117,7 +117,7 @@ def put_cmd_in_ert(arg):
     Returns a list of strings, with the lines so wrapped.
     '''
     
-    ret = ["\\begin_inset ERT", "status collapsed", "\\begin_layout Plain Layout", ""]
+    ret = ["\\begin_inset ERT", "status collapsed", "", "\\begin_layout Plain Layout", ""]
     # It will be faster for us to work with a single string internally. 
     # That way, we only go through the unicode_reps loop once.
     if type(arg) is list:
@@ -128,10 +128,41 @@ def put_cmd_in_ert(arg):
       s = s.replace(rep[1], rep[0].replace('\\\\', '\\'))
     s = s.replace('\\', "\\backslash\n")
     ret += s.splitlines()
-    ret += ["\\end_layout", "\\end_inset"]
+    ret += ["\\end_layout", "", "\\end_inset"]
     return ret
 
-            
+
+def get_ert(lines, i):
+    'Convert an ERT inset into LaTeX.'
+    if not lines[i].startswith("\\begin_inset ERT"):
+        return ""
+    j = find_end_of_inset(lines, i)
+    if j == -1:
+        return ""
+    while i < j and not lines[i].startswith("status"):
+        i = i + 1
+    i = i + 1
+    ret = ""
+    first = True
+    while i < j:
+        if lines[i] == "\\begin_layout Plain Layout":
+            if first:
+                first = False
+            else:
+                ret = ret + "\n"
+            while i + 1 < j and lines[i+1] == "":
+                i = i + 1
+        elif lines[i] == "\\end_layout":
+            while i + 1 < j and lines[i+1] == "":
+                i = i + 1
+        elif lines[i] == "\\backslash":
+            ret = ret + "\\"
+        else:
+            ret = ret + lines[i]
+        i = i + 1
+    return ret
+
+
 def lyx2latex(document, lines):
     'Convert some LyX stuff into corresponding LaTeX stuff, as best we can.'