Am Sonntag, 4. Februar 2007 15:02 schrieb [EMAIL PROTECTED]:
> I don't have any objections, but I am worried it is a big change, and 
that 
> it'll bugs?  So I think it deserves some attention/discussion first, or 
am 
> I wrong?

The patch (untested so far) is attached. The only problems I can imagine 
are some special use cases: E.g. somebody processes the exported .tex file 
with some other tools, or somebody exports to "latex (plain)", but wants 
to process the file with pdflatex.
The solution for all these problems is to use external insets instead of 
graphics insets, and redefine the external templates to omit the 
extension.
We shoud definitely mention this change in the release notes, but I see no 
better way to solve the existing problems.
We could use the solution proposed by Angus for the preview images, but I 
see no other solution for http://bugzilla.lyx.org/show_bug.cgi?id=2764.


Georg
Index: src/insets/insetgraphics.C
===================================================================
--- src/insets/insetgraphics.C	(Revision 17036)
+++ src/insets/insetgraphics.C	(Arbeitskopie)
@@ -507,41 +507,6 @@ copyToDirIfNeeded(DocFileName const & fi
 	return copyFileIfNeeded(file, file_out);
 }
 
-
-string const stripExtensionIfPossible(string const & file)
-{
-	// Remove the extension so the LaTeX will use whatever
-	// is appropriate (when there are several versions in
-	// different formats)
-	// This works only if the filename contains no dots besides
-	// the just removed one. We can fool here by replacing all
-	// dots with a macro whose definition is just a dot ;-)
-	// The automatic format selection does not work if the file
-	// name is escaped.
-	string const latex_name = latex_path(file,
-					     support::EXCLUDE_EXTENSION);
-	if (contains(latex_name, '"'))
-		return latex_name;
-	return latex_path(removeExtension(file),
-			  support::PROTECT_EXTENSION,
-			  support::ESCAPE_DOTS);
-}
-
-
-string const stripExtensionIfPossible(string const & file, string const & to)
-{
-	// No conversion is needed. LaTeX can handle the graphic file as is.
-	// This is true even if the orig_file is compressed.
-	string const to_format = formats.getFormat(to)->extension();
-	string const file_format = getExtension(file);
-	// for latex .ps == .eps
-	if (to_format == file_format ||
-	    (to_format == "eps" && file_format ==  "ps") ||
-	    (to_format ==  "ps" && file_format == "eps"))
-		return stripExtensionIfPossible(file);
-	return latex_path(file, support::EXCLUDE_EXTENSION);
-}
-
 } // namespace anon
 
 
@@ -557,7 +522,7 @@ string const InsetGraphics::prepareFile(
 
 	// previewing source code, no file copying or file format conversion
 	if (runparams.dryrun)
-		return stripExtensionIfPossible(rel_file);
+		return latex_path(rel_file, support::EXCLUDE_EXTENSION);
 
 	// temp_file will contain the file for LaTeX to act on if, for example,
 	// we move it to a temp dir or uncompress it.
@@ -692,7 +657,7 @@ string const InsetGraphics::prepareFile(
 						      output_file);
 		runparams.exportdata->addExternalFile("dvi", source_file,
 						      output_file);
-		return stripExtensionIfPossible(output_file, to);
+		return latex_path(output_file, support::EXCLUDE_EXTENSION);
 	}
 
 	FileName const to_file = FileName(changeExtension(temp_file.absFilename(), ext));
@@ -710,7 +675,7 @@ string const InsetGraphics::prepareFile(
 						      output_to_file);
 		runparams.exportdata->addExternalFile("dvi", to_file,
 						      output_to_file);
-		return stripExtensionIfPossible(output_file);
+		return latex_path(output_file, support::EXCLUDE_EXTENSION);
 	}
 
 	lyxerr[Debug::GRAPHICS]
@@ -730,7 +695,7 @@ string const InsetGraphics::prepareFile(
 				to_file, output_to_file);
 	}
 
-	return stripExtensionIfPossible(output_file);
+	return latex_path(output_file, support::EXCLUDE_EXTENSION);
 }
 
 
@@ -790,8 +755,6 @@ int InsetGraphics::latex(Buffer const & 
 
 	string latex_str = before + '{';
 	// Convert the file if necessary.
-	// Remove the extension so LaTeX will use whatever is appropriate
-	// (when there are several versions in different formats)
 	latex_str += prepareFile(buf, runparams);
 	latex_str += '}' + after;
 	// FIXME UNICODE
@@ -895,13 +858,6 @@ void InsetGraphics::validate(LaTeXFeatur
 
 	features.require("graphicx");
 
-	if (features.runparams().nice) {
-		Buffer const * m_buffer = features.buffer().getMasterBuffer();
-		string const rel_file = removeExtension(params().filename.relFilename(m_buffer->filePath()));
-		if (contains(rel_file, "."))
-			features.require("lyxdot");
-	}
-
 	if (params().subcaption)
 		features.require("subfigure");
 }
Index: src/support/filetools.h
===================================================================
--- src/support/filetools.h	(Revision 17036)
+++ src/support/filetools.h	(Arbeitskopie)
@@ -165,6 +165,13 @@ enum latex_path_dots {
  *  If @c dots == ESCAPE_DOTS dots in the filename are replaced by
  *  "\\lyxdot ". This is needed for the \\includegraphics command if the
  *  automatic format selection is used.
+ *  The automatic format selection does not work if the file name is escaped.
+ *  Note that we do not use the automatic format selection anymore, because
+ *  it created lots of problems (e. g. bug 2764) and we do now have two
+ *  different formats for pdflatex and latex anyway.
+ *  The dot escaping machinery is nevertheless still available for users who
+ *  want to use the automatic format selection in their own external
+ *  templates.
  */
 std::string const latex_path(std::string const & path,
 		latex_path_extension extension = PROTECT_EXTENSION,
Index: lib/external_templates
===================================================================
--- lib/external_templates	(Revision 17036)
+++ lib/external_templates	(Arbeitskopie)
@@ -65,7 +65,7 @@ Template RasterImage
 		TransformOption Extra  ExtraOption
 		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
 		# This string is what is output to the LaTeX file.
-		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename.eps}"
 		UpdateFormat eps
 		UpdateResult "$$AbsPath$$Basename.eps"
 		Requirement "graphicx"
@@ -78,7 +78,7 @@ Template RasterImage
 		TransformOption Clip   ClipLatexOption
 		TransformOption Extra  ExtraOption
 		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
-		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename.png}"
 		UpdateFormat png
 		UpdateResult "$$AbsPath$$Basename.png"
 		Requirement "graphicx"
@@ -217,7 +217,7 @@ Template LilyPond
 		TransformOption Clip   ClipLatexOption
 		TransformOption Extra  ExtraOption
 		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
-		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename.eps}"
 		UpdateFormat eps
 		UpdateResult "$$AbsPath$$Basename.eps"
 		Requirement "graphicx"
@@ -230,7 +230,7 @@ Template LilyPond
 		TransformOption Clip   ClipLatexOption
 		TransformOption Extra  ExtraOption
 		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
-		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename.pdf}"
 		UpdateFormat pdf
 		UpdateResult "$$AbsPath$$Basename.pdf"
 		Requirement "graphicx"

Reply via email to