On Tue, 20 Nov 2007 08:58:47 +0200
Martin Vermeer <[EMAIL PROTECTED]> wrote:

> On Mon, 19 Nov 2007 23:30:04 +0000 (UTC)
> Angus Leeming <[EMAIL PROTECTED]> wrote:
> 
> > Martin Vermeer <[EMAIL PROTECTED]> writes:
> > > -        # Put here the conversions needed from LaTeX string
> > > -        # to LyXText:
> > > +        # Put here the conversions needed from LaTeX string to LyXText:
> > > +        # Umlauted characters:
> > > +        fullcontent = fullcontent.replace(r'\\\"a', 
> > > u'ä').replace(r'\\\"o', 
> > u'ö').replace(r'\\\"u', u'ü')
> > > +        # Same German style:
> > > +        fullcontent = fullcontent.replace(r'"a', u'ä').replace(r'"o', 
> > u'ö').replace(r'"u', u'ü')
> > 
> > This doesn't look very robust. What about Noël/No\"el?. Can't you make use 
> > of 
> > a tool that's dedicated to this type of conversion, like recode?
> > 
> > http://www.delorie.com/gnu/docs/recode/recode_13.html
> > 
> > Angus
> 
> Except that this isn't just a charset conversion problem, but a general
> latex -> lyxtext one. Been thinking about using tex2lyx... rather would
> avoid that. I would be happy if the common use cases are handled
> transparently, and the less common ones without crash or data loss,
> with some manual patch-up at most.

A bit like the attached. We're still not out of the woods though --
e.g., \see doesn't get handled.

- Martin
Index: lyx_1_6.py
===================================================================
--- lyx_1_6.py	(revision 21680)
+++ lyx_1_6.py	(working copy)
@@ -363,8 +363,11 @@
         document.body[i:i + 2] = ["\\begin_inset Index",
           "status collapsed",
           "\\begin_layout standard"]
-        # Put here the conversions needed from LaTeX string
-        # to LyXText:
+        # Put here the conversions needed from LaTeX string to LyXText:
+        # Umlauted characters (most common ones):
+        fullcontent = fullcontent.replace(r'\\\"a', u'ä').replace(r'\\\"o', u'ö').replace(r'\\\"u', u'ü')
+	# Generic, \" -> ":
+        fullcontent = fullcontent.replace(r'\"', '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout standard\n"\n\\end_layout\n\\end_inset\n')
         # Math:
         r = re.compile('^(.*?)(\$.*?\$)(.*)')
         g = fullcontent
@@ -374,11 +377,15 @@
           f = m.group(2).replace('\\\\', '\\')
           g = m.group(3)
           if s:
+            # this is non-math!
+            s = s.replace(r'\\', '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout standard\n\\backslash\n\\end_layout\n\\end_inset\n')
             document.body.insert(i + 3, s)
             i += 1
           document.body.insert(i + 3, "\\begin_inset Formula " + f)
           document.body.insert(i + 4, "\\end_inset")
           i += 2
+        # Generic, \\ -> \backslash:
+        g = g.replace(r'\\', '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout standard\n\\backslash\n\\end_layout\n\\end_inset\n')
         document.body.insert(i + 3, g)
         document.body[i + 4] = "\\end_layout"
         i = i + 5

Reply via email to