Am Freitag, 16. Januar 2004 13:45 schrieb Jose' Matos:
>   For both graphics and included files we need to have the full location 
of 
> those files. One option would be to always give the absolute path. But 
that 
> can be ugly if for example we want to export the file, in that case you 
> want relative paths.

It is clear that relative paths are needed for exporting. But I still don't 
know why absolute paths are used when building the temporary file for 
running LaTeX.
The comment in insetgraphics.C saying that LaTeX needs an absolute path for 
compressed files is wrong (at least for tetex 2.0.2, I just tried). 
Assuming that this is true for all current LaTeX releases (this would need 
to be verified), is there any other reason (other than "it is safe") why we 
want absolute paths?
If using relative paths works reliable in all cases, we could always use 
relative paths. This would simplify the code quite a bit.

>    The problem is that all paths should be relative to the master 
> document....
> 
>   I hope you get the idea. I will give a look into the code and hope to 
have 
> a better solution by then...

Thanks for the explanation, José.

To come back to the original question: Can we remove buffer::niceFile()?
Yes. I suggest to follow Andrés suggestion and move it to LaTeXFeatures (see 
attached). While this does not change functionality, it makes the code 
better understandable IMHO. Since the patch deletes more lines than it 
adds, it must be good;-)

Georg
Index: src/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.1780
diff -u -p -r1.1780 ChangeLog
--- src/ChangeLog	2004/01/15 17:34:37	1.1780
+++ src/ChangeLog	2004/01/19 19:42:31
@@ -1,3 +1,7 @@
+2004-01-19  Georg Baum  <[EMAIL PROTECTED]>
+
+	* LaTeXFeatures.h: add nice_ and nice() const
+	* buffer.[Ch]: remove niceFile(), use LaTeXFeatures::nice() instead
 
 2004-01-15  André Pönitz  <[EMAIL PROTECTED]>
 
Index: src/LaTeXFeatures.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/LaTeXFeatures.C,v
retrieving revision 1.102
diff -u -p -r1.102 LaTeXFeatures.C
--- src/LaTeXFeatures.C	2003/12/29 13:55:42	1.102
+++ src/LaTeXFeatures.C	2004/01/19 19:42:32
@@ -42,8 +42,8 @@ using std::ostringstream;
 using std::set;
 
 
-LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p)
-	: buffer_(b), params_(p)
+LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, bool n)
+	: buffer_(b), params_(p), nice_(n)
 {}
 
 
Index: src/LaTeXFeatures.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/LaTeXFeatures.h,v
retrieving revision 1.54
diff -u -p -r1.54 LaTeXFeatures.h
--- src/LaTeXFeatures.h	2003/10/07 06:45:24	1.54
+++ src/LaTeXFeatures.h	2004/01/19 19:42:33
@@ -39,7 +39,7 @@ struct Language;
 class LaTeXFeatures {
 public:
 	///
-	LaTeXFeatures(Buffer const &, BufferParams const &);
+	LaTeXFeatures(Buffer const &, BufferParams const &, bool);
 	/// The packages needed by the document
 	std::string const getPackages() const;
 	/// The macros definitions needed by the document
@@ -82,6 +82,8 @@ public:
 	BufferParams const & bufferParams() const;
 	/// the return value is dependent upon both LyXRC and LaTeXFeatures.
 	bool useBabel() const;
+	///
+	bool nice() const { return nice_; };
 
 private:
 	std::list<std::string> usedLayouts_;
@@ -108,6 +110,10 @@ private:
 	Buffer const & buffer_;
 	///
 	BufferParams const & params_;
+	/** If we are writing a nice LaTeX file or not.
+	 *  Only needed by InsetInclude::validate().
+	 */
+	bool nice_;
 };
 
 #endif
Index: src/buffer.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v
retrieving revision 1.552
diff -u -p -r1.552 buffer.C
--- src/buffer.C	2003/12/29 15:49:50	1.552
+++ src/buffer.C	2004/01/19 19:42:38
@@ -148,7 +148,6 @@ struct Buffer::Impl
 	BufferParams params;
 	LyXVC lyxvc;
 	string temppath;
-	bool nicefile;
 	TexRow texrow;
 
 	/// need to regenerate .tex ?
@@ -186,8 +185,7 @@ struct Buffer::Impl
 
 
 Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
-	: nicefile(true),
-	  lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
+	: lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
 	  filename(file), filepath(OnlyPath(file)), file_fully_loaded(false),
 		text(0, 0)
 {
@@ -294,18 +303,6 @@ string const & Buffer::temppath() const
 }
 
 
-bool & Buffer::niceFile()
-{
-	return pimpl_->nicefile;
-}
-
-
-bool Buffer::niceFile() const
-{
-	return pimpl_->nicefile;
-}
-
-
 TexRow & Buffer::texrow()
 {
 	return pimpl_->texrow;
@@ -848,11 +862,10 @@ void Buffer::makeLaTeXFile(ostream & os,
 			   bool output_preamble, bool output_body)
 {
 	OutputParams runparams = runparams_in;
-	niceFile() = runparams.nice; // this will be used by Insetincludes.
 
 	// validate the buffer.
 	lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
-	LaTeXFeatures features(*this, params());
+	LaTeXFeatures features(*this, params(), runparams.nice);
 	validate(features);
 	lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
 
@@ -944,9 +957,6 @@ void Buffer::makeLaTeXFile(ostream & os,
 	lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
 	lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
 			    << '.' << endl;
-
-	// we want this to be true outside previews (for insetexternal)
-	niceFile() = true;
 }
 
 
@@ -990,11 +1000,8 @@ void Buffer::makeLinuxDocFile(string con
 	ofstream ofs;
 	if (!openFileWrite(ofs, fname))
 		return;
-
-	niceFile() = runparams.nice; // this will be used by included files.
 
-	LaTeXFeatures features(*this, params());
-
+	LaTeXFeatures features(*this, params(), runparams.nice);
 	validate(features);
 
 	texrow().reset();
@@ -1040,9 +1050,6 @@ void Buffer::makeLinuxDocFile(string con
 
 	ofs.close();
 	// How to check for successful close
-
-	// we want this to be true outside previews (for insetexternal)
-	niceFile() = true;
 }
 
 
@@ -1053,10 +1060,8 @@ void Buffer::makeDocBookFile(string cons
 	ofstream ofs;
 	if (!openFileWrite(ofs, fname))
 		return;
-
-	niceFile() = runparams.nice; // this will be used by Insetincludes.
 
-	LaTeXFeatures features(*this, params());
+	LaTeXFeatures features(*this, params(), runparams.nice);
 	validate(features);
 
 	texrow().reset();
@@ -1101,9 +1109,6 @@ void Buffer::makeDocBookFile(string cons
 
 	ofs.close();
 	// How to check for successful close
-
-	// we want this to be true outside previews (for insetexternal)
-	niceFile() = true;
 }
 
 
Index: src/buffer.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/buffer.h,v
retrieving revision 1.175
diff -u -p -r1.175 buffer.h
--- src/buffer.h	2003/12/03 15:27:14	1.175
+++ src/buffer.h	2004/01/19 19:42:39
@@ -274,12 +274,6 @@ public:
 
 	/// Where to put temporary files.
 	std::string const & temppath() const;
-
-	/** If we are writing a nice LaTeX file or not.
-	    While writing as LaTeX, tells whether we are
-	    doing a 'nice' LaTeX file */
-	bool & niceFile();
-	bool niceFile() const;
 
 	/// Used when typesetting to place errorboxes.
 	TexRow & texrow();
Index: src/insets/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.959
diff -u -p -r1.959 ChangeLog
--- src/insets/ChangeLog	2004/01/15 17:34:39	1.959
+++ src/insets/ChangeLog	2004/01/19 19:44:18
@@ -1,3 +1,9 @@
+2004-01-19  Georg Baum  <[EMAIL PROTECTED]>
+
+	* insetgraphics.C, insetinclude.C: use runparams.nice instead of
+	buffer->niceFile()
+	* insetinclude.C (validate): use feautures.nice() instead of
+	buffer->niceFile()
 
 2004-01-15  André Pönitz  <[EMAIL PROTECTED]>
 
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.232
diff -u -p -r1.232 insetgraphics.C
--- src/insets/insetgraphics.C	2004/01/15 17:34:40	1.232
+++ src/insets/insetgraphics.C	2004/01/19 19:44:24
@@ -633,9 +679,9 @@ int InsetGraphics::plaintext(Buffer cons
 
 
 int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os,
-			    OutputParams const &) const
+			    OutputParams const & runparams) const
 {
-	string const file_name = buf.niceFile() ?
+	string const file_name = runparams.nice ?
 				params().filename.relFilename(buf.filePath()):
 				params().filename.absFilename();
 
Index: src/insets/insetinclude.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetinclude.C,v
retrieving revision 1.179
diff -u -p -r1.179 insetinclude.C
--- src/insets/insetinclude.C	2004/01/15 17:34:40	1.179
+++ src/insets/insetinclude.C	2004/01/19 19:44:26
@@ -388,7 +388,7 @@ int InsetInclude::linuxdoc(Buffer const 
 
 		// write it to a file (so far the complete file)
 		string writefile = ChangeExtension(included_file, ".sgml");
-		if (!buffer.temppath().empty() && !buffer.niceFile()) {
+		if (!buffer.temppath().empty() && !runparams.nice) {
 			incfile = subst(incfile, '/','@');
 			writefile = AddName(buffer.temppath(), incfile);
 		} else
@@ -401,7 +401,6 @@ int InsetInclude::linuxdoc(Buffer const 
 		lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
 		OutputParams runp = runparams;
-		runp.nice = buffer.niceFile();		
 		tmp->makeLinuxDocFile(writefile, runp, true);
 	}
 
@@ -432,7 +431,7 @@ int InsetInclude::docbook(Buffer const &
 
 		// write it to a file (so far the complete file)
 		string writefile = ChangeExtension(included_file, ".sgml");
-		if (!buffer.temppath().empty() && !buffer.niceFile()) {
+		if (!buffer.temppath().empty() && !runparams.nice) {
 			incfile = subst(incfile, '/','@');
 			writefile = AddName(buffer.temppath(), incfile);
 		} else
@@ -444,7 +443,6 @@ int InsetInclude::docbook(Buffer const &
 		lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
 		OutputParams runp = runparams;
-		runp.nice = buffer.niceFile();
 		tmp->makeDocBookFile(writefile, runp, true);
 	}
 
@@ -468,17 +466,20 @@ void InsetInclude::validate(LaTeXFeature
 
 	string const included_file = includedFilename(buffer, params_);
 
-	if (!buffer.temppath().empty() &&
-	    !buffer.niceFile() &&
-	    !isVerbatim(params_)) {
+	if (IsLyXFilename(included_file))
+		writefile = ChangeExtension(writefile, ".sgml");
+	else if (!buffer.temppath().empty() &&
+	         !features.nice() &&
+	         !isVerbatim(params_)) {
 		incfile = subst(incfile, '/','@');
+#ifdef __EMX__
+// FIXME: It seems that the following is necessary (see latex() above)
+//		incfile = subst(incfile, ':', '$');
+#endif
 		writefile = AddName(buffer.temppath(), incfile);
 	} else
 		writefile = included_file;
 
-	if (IsLyXFilename(included_file))
-		writefile = ChangeExtension(writefile, ".sgml");
-
 	features.includeFile(include_label, writefile);
 
 	if (isVerbatim(params_))
@@ -490,10 +489,8 @@ void InsetInclude::validate(LaTeXFeature
 	if (loadIfNeeded(buffer, params_)) {
 		// a file got loaded
 		Buffer * const tmp = bufferlist.getBuffer(included_file);
-		if (tmp) {
-			tmp->niceFile() = buffer.niceFile();
+		if (tmp)
 			tmp->validate(features);
-		}
 	}
 }
 

Reply via email to