Jürgen reported last year that files did not get converted when included 
with the RasterImage template. I tried to reproduce this now and found 
the following bugs:

1. (graphicsinset) Converted files are not copied to the export directory 
if a converter is defined. The fix is very simple.

2. (insetexternal) The lines

ReferencedFile latex "$$AbsPath$$Basename.eps"
ReferencedFile dvi "$$AbsPath$$Basename.eps"

in the template definition tell LyX that the file 
"$$AbsPath$$Basename.eps" will be created by the conversion process and 
will be needed by the exported document in the latex format or dvi 
format, respectively. The actual substitution values for the variables 
depend on the output format: If we export to latex ("nice" == true), 
we'll get a filename like /home/xyz/abc.eps. This is fine, because the 
export mechanism copies the file from the temp dir /home/xyz/abc.eps. If 
we export to dvi ("nice" == false), we'll get something 
like /tmp/lyx_tmpdir4821c1GcBU/lyx_tmpbuf0/1_home_xyz_abc.eps. This is 
wrong, it should be /home/xyz/1_home_xyz_abc.eps, i. e. the directory 
part needs to be the substituted with "nice" == true, and the filename 
with the actual "nice" value. Otherwise the file will not get copied. I 
did exactly that in the attached patch. Another solution would be to 
change

ReferencedFile dvi "$$AbsPath$$Basename.eps"

to

ReferencedFile dvi "$$AbsPath" "$$Basename.eps"

and adjust the template mechanism, but this seems unnatural to me because 
all other filenames are complete with path.

Shall I apply the attached patch?

Jürgen, can you check wether this fixes your problems?


Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog
--- lyx-1.4-clean/src/insets/ChangeLog	2005-01-11 19:38:55.000000000 +0100
+++ lyx-1.4-cvs/src/insets/ChangeLog	2005-01-11 21:07:32.000000000 +0100
@@ -1,3 +1,11 @@
+2005-01-11  Georg Baum  <[EMAIL PROTECTED]>
+
+	* insetgraphics.C (prepareFile): add missing calls to addExternalFile
+	* updateExternal.[Ch] (doSubstitution): take a new parameter that
+	determines what variables are substituted
+	* updateExternal.C (updateExternal): fix substitution of
+	ReferencedFiles
+
 2005-01-10  Angus Leeming  <[EMAIL PROTECTED]>
 
 	* ExternalTemplate.C: use support/package.h to provide the paths to the
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalSupport.C lyx-1.4-cvs/src/insets/ExternalSupport.C
--- lyx-1.4-clean/src/insets/ExternalSupport.C	2005-01-11 19:38:55.000000000 +0100
+++ lyx-1.4-cvs/src/insets/ExternalSupport.C	2005-01-11 21:03:14.000000000 +0100
@@ -62,7 +62,8 @@ void editExternal(InsetExternalParams co
 
 string const doSubstitution(InsetExternalParams const & params,
 			    Buffer const & buffer, string const & s,
-			    bool external_in_tmpdir)
+                            bool external_in_tmpdir,
+                            Substitute what)
 {
 	Buffer const * m_buffer = buffer.getMasterBuffer();
 	string const parentpath = external_in_tmpdir ?
@@ -71,43 +72,52 @@ string const doSubstitution(InsetExterna
 	string const filename = external_in_tmpdir ?
 		params.filename.mangledFilename() :
 		params.filename.outputFilename(parentpath);
-	string result;
 	string const basename = support::ChangeExtension(
 			support::OnlyFilename(filename), string());
 	string const absname = support::MakeAbsPath(filename, parentpath);
-	string const filepath = support::OnlyPath(filename);
-	string const abspath = support::OnlyPath(absname);
-	string const masterpath = external_in_tmpdir ?
-		m_buffer->temppath() :
-		m_buffer->filePath();
-	string relToMasterPath = support::OnlyPath(
-			support::MakeRelPath(absname, masterpath));
-	if (relToMasterPath == "./")
-		relToMasterPath.clear();
-	string relToParentPath = support::OnlyPath(
-			support::MakeRelPath(absname, parentpath));
-	if (relToParentPath == "./")
-		relToParentPath.clear();
 
-	result = support::subst(s, "$$FName", filename);
-	result = support::subst(result, "$$Basename", basename);
-	result = support::subst(result, "$$Extension",
-			'.' + support::GetExtension(filename));
-	result = support::subst(result, "$$FPath", filepath);
-	result = support::subst(result, "$$AbsPath", abspath);
-	result = support::subst(result, "$$RelPathMaster", relToMasterPath);
-	result = support::subst(result, "$$RelPathParent", relToParentPath);
-	if (support::AbsolutePath(filename)) {
-		result = support::subst(result, "$$AbsOrRelPathMaster",
-		                        abspath);
-		result = support::subst(result, "$$AbsOrRelPathParent",
-		                        abspath);
-	} else {
-		result = support::subst(result, "$$AbsOrRelPathMaster",
+	string result = s;
+	if (what != ALL_BUT_PATHS) {
+		string const filepath = support::OnlyPath(filename);
+		string const abspath = support::OnlyPath(absname);
+		string const masterpath = external_in_tmpdir ?
+			m_buffer->temppath() :
+			m_buffer->filePath();
+		string relToMasterPath = support::OnlyPath(
+				support::MakeRelPath(absname, masterpath));
+		if (relToMasterPath == "./")
+			relToMasterPath.clear();
+		string relToParentPath = support::OnlyPath(
+				support::MakeRelPath(absname, parentpath));
+		if (relToParentPath == "./")
+			relToParentPath.clear();
+
+		result = support::subst(result, "$$FPath", filepath);
+		result = support::subst(result, "$$AbsPath", abspath);
+		result = support::subst(result, "$$RelPathMaster",
 		                        relToMasterPath);
-		result = support::subst(result, "$$AbsOrRelPathParent",
+		result = support::subst(result, "$$RelPathParent",
 		                        relToParentPath);
+		if (support::AbsolutePath(filename)) {
+			result = support::subst(result, "$$AbsOrRelPathMaster",
+			                        abspath);
+			result = support::subst(result, "$$AbsOrRelPathParent",
+			                        abspath);
+		} else {
+			result = support::subst(result, "$$AbsOrRelPathMaster",
+			                        relToMasterPath);
+			result = support::subst(result, "$$AbsOrRelPathParent",
+			                        relToParentPath);
+		}
 	}
+
+	if (what == PATHS)
+		return result;
+
+	result = support::subst(result, "$$FName", filename);
+	result = support::subst(result, "$$Basename", basename);
+	result = support::subst(result, "$$Extension",
+			'.' + support::GetExtension(filename));
 	result = support::subst(result, "$$Tempname", params.tempname());
 	result = support::subst(result, "$$Sysdir",
 				support::package().system_support());
@@ -139,8 +148,8 @@ string const doSubstitution(InsetExterna
 namespace {
 
 /** update the file represented by the template.
-    If \param external_in_tmpdir == true, then the generated file is
-    place in the buffer's temporary directory.
+    If \p external_in_tmpdir == true, then the generated file is
+    placed in the buffer's temporary directory.
 */
 void updateExternal(InsetExternalParams const & params,
 		    string const & format,
@@ -238,9 +247,17 @@ void updateExternal(InsetExternalParams 
 					doSubstitution(params, buffer, *fit,
 					               true),
 					m_buffer->temppath());
-			string const file = doSubstitution(params, buffer,
-			                                   *fit,
-			                                   external_in_tmpdir);
+			// The path of the referenced file is never the
+			// temp path, but the filename may be the mangled
+			// or the real name. Therefore we substitute the
+			// paths and names separately.
+			string file = support::subst(*fit, "$$FName",
+					"$$FPath$$Basename$$Extension");
+			file = doSubstitution(params, buffer, file, false,
+			                      PATHS);
+			file = doSubstitution(params, buffer, file,
+			                      external_in_tmpdir,
+			                      ALL_BUT_PATHS);
 			// if file is a relative name, it is interpreted
 			// relative to the master document.
 			exportdata.addExternalFile(rit->first, source, file);
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalSupport.h lyx-1.4-cvs/src/insets/ExternalSupport.h
--- lyx-1.4-clean/src/insets/ExternalSupport.h	2004-06-01 15:32:28.000000000 +0200
+++ lyx-1.4-cvs/src/insets/ExternalSupport.h	2005-01-11 20:26:40.000000000 +0100
@@ -34,6 +34,12 @@ void editExternal(InsetExternalParams co
 		  Buffer const & buffer);
 
 
+enum Substitute {
+	ALL,
+	PATHS,
+	ALL_BUT_PATHS
+};
+
 /** Substitute meta-variables in string \p s, making use of \p params and
     \p buffer.
     If \p external_in_tmpdir is true, all files are assumed to be in the
@@ -44,12 +50,13 @@ void editExternal(InsetExternalParams co
 std::string const doSubstitution(InsetExternalParams const & params,
 				 Buffer const & buffer,
                                  std::string const & s,
-                                 bool external_in_tmpdir = false);
+                                 bool external_in_tmpdir = false,
+                                 Substitute what = ALL);
 
 
 /** Write the output for a specific file format
     and generate any external data files.
-    If \param external_in_tmpdir == true, then the generated file is
+    If \p external_in_tmpdir == true, then the generated file is
     place in the buffer's temporary directory.
 */
 int writeExternal(InsetExternalParams const &,
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetgraphics.C lyx-1.4-cvs/src/insets/insetgraphics.C
--- lyx-1.4-clean/src/insets/insetgraphics.C	2005-01-12 21:05:54.000000000 +0100
+++ lyx-1.4-cvs/src/insets/insetgraphics.C	2005-01-10 22:32:51.000000000 +0100
@@ -674,7 +673,12 @@ string const InsetGraphics::prepareFile(
 
 	// if no special converter defined, then we take the default one
 	// from ImageMagic: convert from:inname.from to:outname.to
-	if (!converters.convert(&buf, temp_file, temp_file, from, to)) {
+	if (converters.convert(&buf, temp_file, temp_file, from, to)) {
+		runparams.exportdata->addExternalFile("latex",
+				to_file, output_to_file);
+		runparams.exportdata->addExternalFile("dvi",
+				to_file, output_to_file);
+	} else {
 		string const command =
 			"sh " + LibFileSearch("scripts", "convertDefault.sh") +
 				' ' + formats.extension(from) + ':' + temp_file +

Reply via email to