} //namespace anon
+bool Format::formatSorter(Format const * lhs, Format const * rhs)
+{
+ return _(lhs->prettyname()) < _(rhs->prettyname());
+}
bool operator<(Format const & a, Format const & b)
{
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);
format = "jpg";
else if (contains(str, "%PDF"))
- format = "pdf";
+ // autodetect pdf format for graphics inclusion
+ format = "pdf6";
else if (contains(str, "PNG"))
format = "png";
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;
}
// LinkBack files look like PDF, but have the .linkback extension
string const ext = getExtension(filename.absFileName());
- if (format_name == "pdf" && ext == "linkback") {
+ if (format_name == "pdf6" && ext == "linkback") {
#ifdef USE_MACOSX_PACKAGING
return editLinkBackFile(filename.absFileName().c_str());
#else