]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.C
Fix bug 3101 and 3108
[lyx.git] / src / tex2lyx / text.C
index 4981b93a101040af7def06b692bdb97c3508b7f8..2f7740686faf04eea94d3693aee58b084fdeb0f4 100644 (file)
@@ -32,6 +32,7 @@
 
 namespace lyx {
 
+using support::addExtension;
 using support::changeExtension;
 using support::FileName;
 using support::makeAbsPath;
@@ -354,11 +355,11 @@ void translate_box_len(string const & length, string & value, string & unit, str
 string find_file(string const & name, string const & path,
                 char const * const * extensions)
 {
+       // FIXME UNICODE encoding of name and path may be wrong (makeAbsPath
+       // expects utf8)
        for (char const * const * what = extensions; *what; ++what) {
-               // We don't use ChangeExtension() because it does the wrong
-               // thing if name contains a dot.
-               string const trial = name + '.' + (*what);
-               if (fs::exists(FileName(makeAbsPath(trial, path)).toFilesystemEncoding()))
+               string const trial = addExtension(name, *what);
+               if (fs::exists(makeAbsPath(trial, path).toFilesystemEncoding()))
                        return trial;
        }
        return string();
@@ -1021,7 +1022,9 @@ void fix_relative_filename(string & name)
 {
        if (lyx::support::absolutePath(name))
                return;
-       name = makeRelPath(makeAbsPath(name, getMasterFilePath()),
+       // FIXME UNICODE encoding of name may be wrong (makeAbsPath expects
+       // utf8)
+       name = makeRelPath(makeAbsPath(name, getMasterFilePath()).absFilename(),
                           getParentFilePath());
 }
 
@@ -1052,7 +1055,13 @@ void parse_noweb(Parser & p, ostream & os, Context & context)
                return;
        }
 
-       context.check_end_layout(os);
+       // We use new_paragraph instead of check_end_layout because the stuff
+       // following the noweb chunk needs to start with a \begin_layout.
+       // This may create a new paragraph even if there was none in the
+       // noweb file, but the alternative is an invalid LyX file. Since
+       // noweb code chunks are implemented with a layout style in LyX they
+       // always must be in an own paragraph.
+       context.new_paragraph(os);
        Context newcontext(true, context.textclass, context.textclass["Scrap"]);
        newcontext.check_layout(os);
        os << name;
@@ -1480,7 +1489,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        string const path = getMasterFilePath();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
-                       if (!fs::exists(FileName(makeAbsPath(name, path)).toFilesystemEncoding())) {
+                       // FIXME UNICODE encoding of name and path may be
+                       // wrong (makeAbsPath expects utf8)
+                       if (!fs::exists(makeAbsPath(name, path).toFilesystemEncoding())) {
                                // The file extension is probably missing.
                                // Now try to find it out.
                                string const dvips_name =
@@ -1510,7 +1521,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        name = pdftex_name;
                        }
 
-                       if (fs::exists(FileName(makeAbsPath(name, path)).toFilesystemEncoding()))
+                       // FIXME UNICODE encoding of name and path may be
+                       // wrong (makeAbsPath expects utf8)
+                       if (fs::exists(makeAbsPath(name, path).toFilesystemEncoding()))
                                fix_relative_filename(name);
                        else
                                cerr << "Warning: Could not find graphics file '"
@@ -2088,7 +2101,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                         || t.cs() == "~" || t.cs() == "." || t.cs() == "=") {
                        // we need the trim as the LyX parser chokes on such spaces
                        context.check_layout(os);
-                       os << "\n\\i \\" << t.cs() << "{"
+                       os << "\\i \\" << t.cs() << "{"
                           << trim(parse_text_snippet(p, FLAG_ITEM, outer, context), " ")
                           << "}\n";
                }
@@ -2099,9 +2112,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        skip_braces(p); // eat {}
                }
 
-               else if (t.cs() == "i" || t.cs() == "j") {
+               else if (t.cs() == "i" || t.cs() == "j" || t.cs() == "l" ||
+                        t.cs() == "L") {
                        context.check_layout(os);
-                       os << "\\" << t.cs() << ' ';
+                       os << "\\i \\" << t.cs() << "{}\n";
                        skip_braces(p); // eat {}
                }
 
@@ -2131,8 +2145,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        string const path = getMasterFilePath();
                        // We want to preserve relative / absolute filenames,
                        // therefore path is only used for testing
+                       // FIXME UNICODE encoding of filename and path may be
+                       // wrong (makeAbsPath expects utf8)
                        if (t.cs() == "include" &&
-                           !fs::exists(FileName(makeAbsPath(filename, path)).toFilesystemEncoding())) {
+                           !fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) {
                                // The file extension is probably missing.
                                // Now try to find it out.
                                string const tex_name =
@@ -2141,9 +2157,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                if (!tex_name.empty())
                                        filename = tex_name;
                        }
-                       if (fs::exists(FileName(makeAbsPath(filename, path)).toFilesystemEncoding())) {
+                       // FIXME UNICODE encoding of filename and path may be
+                       // wrong (makeAbsPath expects utf8)
+                       if (fs::exists(makeAbsPath(filename, path).toFilesystemEncoding())) {
                                string const abstexname =
-                                       makeAbsPath(filename, path);
+                                       makeAbsPath(filename, path).absFilename();
                                string const abslyxname =
                                        changeExtension(abstexname, ".lyx");
                                fix_relative_filename(filename);