X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FFormat.cpp;h=485715b6e3b23911d622c31897856467f748bd0e;hb=3d4076b598deb18660e50ec9c327efc3b15f15d0;hp=8872fb1ddee532a73ea209b9b186012587edae50;hpb=cb5dd33475e7cca472ead1fd3eac9f174b8b76ba;p=lyx.git diff --git a/src/Format.cpp b/src/Format.cpp index 8872fb1dde..485715b6e3 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -115,6 +115,10 @@ private: } //namespace anon +bool Format::formatSorter(Format const * lhs, Format const * rhs) +{ + return _(lhs->prettyname()) < _(rhs->prettyname()); +} bool operator<(Format const & a, Format const & b) { @@ -249,12 +253,11 @@ string guessFormatFromContents(FileName const & fn) string str; string format; bool firstLine = true; + bool backslash = false; + int dollars = 0; while ((count++ < max_count) && format.empty()) { - if (ifs.eof()) { - LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n" - << "\tFile type not recognised before EOF!"); + if (ifs.eof()) break; - } getline(ifs, str); string const stamp = str.substr(0, 2); @@ -359,9 +362,32 @@ string guessFormatFromContents(FileName const & fn) else if (contains(str, "BITPIX")) format = "fits"; + + else if (contains(str, "\\documentclass") || + contains(str, "\\chapter") || + contains(str, "\\section") || + contains(str, "\\begin") || + contains(str, "\\end") || + contains(str, "$$") || + contains(str, "\\[") || + contains(str, "\\]")) + format = "latex"; + else { + if (contains(str, '\\')) + backslash = true; + dollars += count_char(str, '$'); + } } - if (!format.empty()) { + if (format.empty() && backslash && dollars > 1) + // inline equation + format = "latex"; + + if (format.empty()) { + if (ifs.eof()) + LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n" + "\tFile type not recognised before EOF!"); + } else { LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format); return format; }