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:
# 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
#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 [""]
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
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", ""] + \
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", "",
"\\end_layout",
""]
document.body[i:k] = newstuff
- i = k
+ i = i + len(newstuff)
def convert_ams_classes(document):
tc = document.textclass
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