From 94160f97c0a71c8105e02c2f177b0e3cf754e889 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 20 Dec 2010 21:35:08 +0000 Subject: [PATCH] adjust xfig conversion to newer xfig as suggested by Jean-Pierre at http://www.lyx.org/trac/ticket/3016#comment:6 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36972 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/text.cpp | 51 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 0a887b80cb..ad9ae11bca 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2588,7 +2588,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, if (!tex_name.empty()) filename = tex_name; } - bool xfig = false; + bool external = false; string outname; if (makeAbsPath(filename, path).exists()) { string const abstexname = @@ -2600,20 +2600,53 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, fix_relative_filename(filename); string const lyxname = changeExtension(filename, ".lyx"); - if (t.cs() == "input" && FileName(absfigname).exists()) { + bool xfig = false; + external = FileName(absfigname).exists(); + if (t.cs() == "input") { + string const ext = getExtension(abstexname); + + // Combined PS/LaTeX: + // x.eps, x.pstex_t (old xfig) + // x.pstex, x.pstex_t (new xfig, e.g. 3.2.5) FileName const absepsname( changeExtension(abstexname, ".eps")); + FileName const abspstexname( + changeExtension(abstexname, ".pstex")); + bool const xfigeps = + (absepsname.exists() || + abspstexname.exists()) && + ext == "pstex_t"; + + // Combined PDF/LaTeX: + // x.pdf, x.pdftex_t (old xfig) + // x.pdf, x.pdf_t (new xfig, e.g. 3.2.5) FileName const abspdfname( changeExtension(abstexname, ".pdf")); - string const ext = getExtension(abstexname); bool const xfigpdf = - abspdfname.exists() && ext == "pdftex_t"; - bool const xfigeps = - absepsname.exists() && ext == "pstex_t"; - xfig = xfigpdf || xfigeps; + abspdfname.exists() && + (ext == "pdftex_t" || ext == "pdf_t"); + + // Combined PS/PDF/LaTeX: + // x_pspdftex.eps, x_pspdftex.pdf, x.pspdftex + string const absbase2( + removeExtension(abstexname) + "_pspdftex"); + FileName const abseps2name( + addExtension(absbase2, ".eps")); + FileName const abspdf2name( + addExtension(absbase2, ".pdf")); + bool const xfigboth = + abspdf2name.exists() && + abseps2name.exists() && ext == "pspdftex"; + + xfig = xfigpdf || xfigeps || xfigboth; + external = external && xfig; } - if (xfig) { + if (external) { outname = changeExtension(filename, ".fig"); + } else if (xfig) { + // Don't try to convert, the result + // would be full of ERT. + outname = filename; } else if (t.cs() != "verbatiminput" && tex2lyx(abstexname, FileName(abslyxname), p.getEncoding())) { @@ -2626,7 +2659,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, << filename << "'." << endl; outname = filename; } - if (xfig) { + if (external) { begin_inset(os, "External\n"); os << "\ttemplate XFig\n" << "\tfilename " << outname << '\n';