From: Richard Heck Date: Mon, 7 Jul 2008 21:20:30 +0000 (+0000) Subject: Some more cleanup of these conversion routines. X-Git-Tag: 1.6.10~4178 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7c03f1808b20edb7a82e44f5f7aba65ad65d7cb5;p=features.git Some more cleanup of these conversion routines. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25498 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 9b8c2764ca..11349ed64f 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -147,6 +147,20 @@ def read_unicodesymbols(): return spec_chars +def line2lyx(line): + '''Converts LaTeX commands, such as: \"u, to unicode characters, and + escapes backslashes, etc, into ERT. line may well be a multi-line + string when it is returned. + NOTE: If we want to convert \label{} into an InsetLabel, then this + is the place to do it.''' + if not line: + return line + line = wrap_into_ert(line, '\\', '\\backslash') + line = wrap_into_ert(line, '{', '{') + line = wrap_into_ert(line, '}', '}') + return line + + def latex2lyx(data): '''Takes a string, possibly multi-line, and returns the result of converting LaTeX constructs into LyX constructs. Returns a list of @@ -174,31 +188,20 @@ def latex2lyx(data): #document.warning("LAST: " + document.body[-1]) g = line m = mathre.match(g) - if m == None: - g = wrap_into_ert(g, '\\', '\\backslash') - g = wrap_into_ert(g, '{', '{') - g = wrap_into_ert(g, '}', '}') - subst = g.split('\n') - retval += subst - continue while m != None: s = m.group(1) f = m.group(2).replace('\\\\', '\\') g = m.group(3) if s: # this is non-math! - s = wrap_into_ert(s, '\\', '\\backslash') - s = wrap_into_ert(s, '{', '{') - s = wrap_into_ert(s, '}', '}') + s = line2lyx(s) subst = s.split('\n') retval += subst retval.append("\\begin_inset Formula " + f) retval.append("\\end_inset") m = mathre.match(g) - # Generic, \\ -> \backslash: - g = wrap_into_ert(g, r'\\', '\\backslash') - g = wrap_into_ert(g, '{', '{') - g = wrap_into_ert(g, '}', '}') + # Handle whatever is left, which is just text + g = line2lyx(g) subst = g.split('\n') retval += subst return retval