]> git.lyx.org Git - lyx.git/blobdiff - lib/lyx2lyx/lyx_1_6.py
Fix the configure script. Python apparently does not like tabs as much as spaces.
[lyx.git] / lib / lyx2lyx / lyx_1_6.py
index d11ed229745174eda299ce0a65d5223da01c8a83..562f32946bcef81216f61757e8e2d703b472b5d1 100644 (file)
@@ -209,7 +209,7 @@ def extract_argument(line):
     return (line[:pos + 1], line[pos + 1:])
 
 
-def latex2ert(line):
+def latex2ert(line, isindex):
     '''Converts LaTeX commands into ERT. line may well be a multi-line
        string when it is returned.'''
     if not line:
@@ -246,6 +246,9 @@ def latex2ert(line):
     # put all remaining braces in ERT
     line = wrap_into_ert(line, '}', '}')
     line = wrap_into_ert(line, '{', '{')
+    if isindex:
+        # active character that is not available in all font encodings
+        line = wrap_into_ert(line, '|', '|')
     retval += line
     return retval
 
@@ -257,10 +260,12 @@ unicode_reps = read_unicodesymbols()
 #end up inside ERT. That routine could be modified so that it returned
 #a list of lines, and we could then skip ERT bits and only deal with
 #the other bits.
-def latex2lyx(data):
+def latex2lyx(data, isindex):
     '''Takes a string, possibly multi-line, and returns the result of
     converting LaTeX constructs into LyX constructs. Returns a list of
-    lines, suitable for insertion into document.body.'''
+    lines, suitable for insertion into document.body.
+    The bool isindex specifies whether we are in an index macro (which
+    has some specific active characters that need to be ERTed).'''
 
     if not data:
         return [""]
@@ -309,14 +314,14 @@ def latex2lyx(data):
             g = m.group(3)
             if s:
                 # this is non-math!
-                s = latex2ert(s)
+                s = latex2ert(s, isindex)
                 subst = s.split('\n')
                 retval += subst
             retval.append("\\begin_inset Formula " + f)
             retval.append("\\end_inset")
             m = mathre.match(g)
         # Handle whatever is left, which is just text
-        g = latex2ert(g)
+        g = latex2ert(g, isindex)
         subst = g.split('\n')
         retval += subst
     return retval
@@ -1096,7 +1101,7 @@ def convert_latexcommand_index(document):
             linelist = [""]
         else:
             fullcontent = m.group(1)
-            linelist = latex2lyx(fullcontent)
+            linelist = latex2lyx(fullcontent, True)
         #document.warning(fullcontent)
 
         linelist = ["\\begin_inset Index", "status collapsed", "\\begin_layout Standard", ""] + \
@@ -1321,13 +1326,13 @@ def convert_url(document):
       j = find_token(document.body, "target", i)
       if j == -1:
         document.warning("Malformed LyX document: Can't find target for url inset")
-        i = j
+        i += 1
         continue
       target = document.body[j][8:-1]
       k = find_token(document.body, "\\end_inset", j)
       if k == -1:
         document.warning("Malformed LyX document: Can't find end of url inset")
-        i = k
+        i = j
         continue
       newstuff = ["\\begin_inset Flex URL",
         "status collapsed", "",
@@ -1337,7 +1342,7 @@ def convert_url(document):
         "\\end_layout",
         ""]
       document.body[i:k] = newstuff
-      i = k
+      i = i + len(newstuff)
 
 def convert_ams_classes(document):
   tc = document.textclass
@@ -2176,7 +2181,7 @@ def convert_subfig(document):
         addedLines -= 1
         subst = ['\\begin_inset Float figure', 'wide false', 'sideways false',
                  'status open', '', '\\begin_layout Plain Layout', '\\begin_inset Caption',
-                 '', '\\begin_layout Plain Layout'] + latex2lyx(caption) + \
+                 '', '\\begin_layout Plain Layout'] + latex2lyx(caption, False) + \
                  [ '\\end_layout', '', '\\end_inset', '',
                  '\\end_layout', '', '\\begin_layout Plain Layout']
         document.body[i : i] = subst