Hi,

I'm sorry for the delay. Here are the final patches for DVI inverse search for 
lyx 1.4. The aims of these patches are:

1. Detect if latex accepts a command line option for producing dvi with source 
file information and store this command line option in lyxrc.defaults under 
the option \source_specials_switch. This options is usually --src-specials. 
This is done by the patch source-specials-configure.diff.

2. Create dvis with source information only when calling view->dvi, and not 
when calling view->postscript. Also, when exporting to dvi or postscript, 
dont insert source information. This is the job of 
dvi-inverse-search-final.diff.

The aims in 2. are done in the following way: when the variable 
lyxrc.source_specials_switch is set, calling view->dvi will not export (in 
lyx_tmpdir) filename.tex, but filename_pre.tex. Thus, running latex will 
provide filename_pre.dvi. All the other operations will export the buffer to 
filename.tex and the operation will be as usual.

With these patches, dvi inverse search should work out of the box, without 
user intervention.

I admit that the pathes are a hack. The code in LaTeX.C and exporter.C seems 
to need a cleanup, at least. I also would like to have a different behavior 
when an xdvi is called, then the buffer is modified, then anothe xdvi is 
called (without closing the first one). Presently, both xdvi will show the 
same contents. The best behavior would be that the dvi previewers keep 
different contents, for comparison. I think that to implement this it will be 
necessary almost a rewrite of LaTex.C.

Anyway, the patches need testing.

How is the schedule for 1.4?

Regards,
João.
Index: src/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.2213
diff -u -r1.2213 ChangeLog
--- src/ChangeLog	2005/07/07 10:51:55	1.2213
+++ src/ChangeLog	2005/07/10 09:46:21
@@ -1,3 +1,18 @@
+2005-07-10  Joao Luis Meloni Assirati  <[EMAIL PROTECTED]>
+
+	* exporter.{C.h} (Export):
+	* converter.{C,h} (convert): add the argument bool for_preview to
+	discriminate the conversion to dvi preview with source specials.
+	* converter.{C,h} (runLaTeX): Add the argument string name to runLaTeX
+	to tell which is the tex file being latexed which now is different
+	from buffer.getLatexName() in the conversion tex->dvi with source
+	specials.
+	* LaTeX.C (startscript): add the command line switch for source specials
+	to latex in startscript.
+	* outputparams.{C,h}: nem member bool srcspecials.
+	* lyxrc.C: add configuration option \source_specials_switch.
+	* lyxfunc.C: fix LFUN_GOTOFILEROW.
+
 2005-06-21  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* buffer.C: format incremented to 242. There is no file format per
Index: src/converter.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/converter.h,v
retrieving revision 1.40
diff -u -r1.40 converter.h
--- src/converter.h	2005/01/14 19:13:17	1.40
+++ src/converter.h	2005/07/10 09:46:21
@@ -107,12 +107,13 @@
 	bool convert(Buffer const * buffer,
 		     std::string const & from_file, std::string const & to_file_base,
 		     std::string const & from_format, std::string const & to_format,
-                     std::string & to_file, bool try_default = false);
+		     std::string & to_file, bool try_default = false,
+		     bool for_preview = false);
 	///
 	bool convert(Buffer const * buffer,
 		     std::string const & from_file, std::string const & to_file_base,
 		     std::string const & from_format, std::string const & to_format,
-                     bool try_default = false);
+                     bool try_default = false, bool for_preview = false);
 	///
 	void update(Formats const & formats);
 	///
@@ -137,7 +138,7 @@
 		     std::string const & filename);
 	///
 	bool runLaTeX(Buffer const & buffer, std::string const & command,
-		      OutputParams const &);
+		      std::string const & name, OutputParams const &);
 	///
 	ConverterList converterlist_;
 	///
Index: src/converter.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/converter.C,v
retrieving revision 1.106
diff -u -r1.106 converter.C
--- src/converter.C	2005/06/09 15:19:07	1.106
+++ src/converter.C	2005/07/10 09:46:22
@@ -281,7 +281,8 @@
 bool Converters::convert(Buffer const * buffer,
 			 string const & from_file, string const & to_file_base,
 			 string const & from_format, string const & to_format,
-			 string & to_file, bool try_default)
+			 string & to_file, bool try_default,
+			 bool for_preview)
 {
 	string const to_ext = formats.extension(to_format);
 	to_file = ChangeExtension(to_file_base, to_ext);
@@ -321,6 +322,7 @@
 	}
 	OutputParams runparams;
 	runparams.flavor = getFlavor(edgepath);
+	runparams.srcspecials = (for_preview && to_format == "dvi");
 	string path = OnlyPath(from_file);
 	Path p(path);
 
@@ -356,7 +358,7 @@
 			run_latex = true;
 			string const command = subst(conv.command, token_from, "");
 			lyxerr[Debug::FILES] << "Running " << command << endl;
-			if (!runLaTeX(*buffer, command, runparams))
+			if (!runLaTeX(*buffer, command, from_file, runparams))
 				return false;
 		} else {
 			if (conv.need_aux && !run_latex
@@ -364,7 +366,7 @@
 				lyxerr[Debug::FILES]
 					<< "Running " << latex_command_
 					<< " to update aux file"<<  endl;
-				runLaTeX(*buffer, latex_command_, runparams);
+				runLaTeX(*buffer, latex_command_, from_file, runparams);
 			}
 
 			string const infile2 = (conv.original_dir)
@@ -513,11 +515,11 @@
 bool Converters::convert(Buffer const * buffer,
 			 string const & from_file, string const & to_file_base,
 			 string const & from_format, string const & to_format,
-                         bool try_default)
+                         bool try_default, bool for_preview)
 {
 	string to_file;
 	return convert(buffer, from_file, to_file_base, from_format, to_format,
-		       to_file, try_default);
+		       to_file, try_default, for_preview);
 }
 
 
@@ -566,7 +568,7 @@
 
 
 bool Converters::runLaTeX(Buffer const & buffer, string const & command,
-			  OutputParams const & runparams)
+			  string const & name, OutputParams const & runparams)
 {
 	buffer.busy(true);
 	buffer.message(_("Running LaTeX..."));
@@ -574,7 +576,6 @@
 	runparams.document_language = buffer.params().language->babel();
 
 	// do the LaTeX run(s)
-	string const name = buffer.getLatexName();
 	LaTeX latex(command, runparams, name, buffer.filePath());
 	TeXErrors terr;
 	showMessage show(buffer);
Index: src/exporter.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/exporter.h,v
retrieving revision 1.22
diff -u -r1.22 exporter.h
--- src/exporter.h	2005/01/19 15:03:29	1.22
+++ src/exporter.h	2005/07/10 09:46:22
@@ -26,7 +26,8 @@
 	///
 	static
 	bool Export(Buffer * buffer, std::string const & format,
-		    bool put_in_tempdir, std::string & result_file);
+		    bool put_in_tempdir, std::string & result_file,
+		    bool for_preview = false);
 	///
 	static
 	bool Export(Buffer * buffer, std::string const & format,
Index: src/exporter.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/exporter.C,v
retrieving revision 1.60
diff -u -r1.60 exporter.C
--- src/exporter.C	2005/04/26 11:12:10	1.60
+++ src/exporter.C	2005/07/10 09:46:22
@@ -136,7 +136,8 @@
 
 
 bool Exporter::Export(Buffer * buffer, string const & format,
-		      bool put_in_tempdir, string & result_file)
+		      bool put_in_tempdir, string & result_file,
+		      bool for_preview)
 {
 	string backend_format;
 	OutputParams runparams;
@@ -164,6 +165,11 @@
 		backend_format = format;
 
 	string filename = buffer->getLatexName(false);
+	if(for_preview && format == "dvi") {
+		filename = ChangeExtension(filename, "");
+		filename += "_pre";
+		filename = ChangeExtension(filename, "tex");
+	}
 	filename = AddName(buffer->temppath(), filename);
 	filename = ChangeExtension(filename,
 				   formats.extension(backend_format));
@@ -196,7 +202,8 @@
 	}
 
 	if (!converters.convert(buffer, filename, filename,
-				backend_format, format, result_file))
+				backend_format, format, result_file,
+				false, for_preview))
 		return false;
 
 	if (!put_in_tempdir) {
@@ -246,7 +253,8 @@
 bool Exporter::Preview(Buffer * buffer, string const & format)
 {
 	string result_file;
-	if (!Export(buffer, format, true, result_file))
+	if (!Export(buffer, format, true, result_file,
+		    !lyxrc.source_specials_switch.empty()))
 		return false;
 	return formats.view(*buffer, result_file, format);
 }
Index: src/outputparams.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/outputparams.h,v
retrieving revision 1.13
diff -u -r1.13 outputparams.h
--- src/outputparams.h	2005/07/07 10:51:56	1.13
+++ src/outputparams.h	2005/07/10 09:46:22
@@ -89,6 +89,10 @@
 	    OutputParams instances.
 	*/
 	boost::shared_ptr<ExportData> exportdata;
+
+	/** Whether to insert or not source specials.
+	*/
+	bool srcspecials;
 };
 
 #endif // NOT OUTPUTPARAMS_H
Index: src/outputparams.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/outputparams.C,v
retrieving revision 1.3
diff -u -r1.3 outputparams.C
--- src/outputparams.C	2004/11/02 11:25:16	1.3
+++ src/outputparams.C	2005/07/10 09:46:22
@@ -18,7 +18,7 @@
 	: flavor(LATEX), nice(false), moving_arg(false),
 	  free_spacing(false), use_babel(false),
 	  linelen(0), depth(0),
-	  exportdata(new ExportData)
+	  exportdata(new ExportData), srcspecials(false)
 {}
 
 
Index: src/LaTeX.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/LaTeX.C,v
retrieving revision 1.109
diff -u -r1.109 LaTeX.C
--- src/LaTeX.C	2005/02/23 16:56:40	1.109
+++ src/LaTeX.C	2005/07/10 09:46:23
@@ -383,7 +383,8 @@
 
 int LaTeX::startscript()
 {
-	string tmp = cmd + ' ' + QuoteName(file) + " > " + os::nulldev();
+	string tmp = cmd + (runparams.srcspecials?(' ' + lyxrc.source_specials_switch):"") +
+		' ' + QuoteName(file) + " > " + os::nulldev();
 	Systemcall one;
 	return one.startscript(Systemcall::Wait, tmp);
 }
Index: src/lyxfunc.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.658
diff -u -r1.658 lyxfunc.C
--- src/lyxfunc.C	2005/05/31 14:40:24	1.658
+++ src/lyxfunc.C	2005/07/10 09:46:25
@@ -1097,10 +1097,8 @@
 			}
 
 			view()->setCursorFromRow(row);
-
 			view()->center();
-			// see BufferView_pimpl::center()
-			view()->updateScrollbar();
+			view()->update();
 			break;
 		}
 
@@ -1980,6 +1978,7 @@
 	case LyXRC::RC_SERVERPIPE:
 	case LyXRC::RC_SET_COLOR:
 	case LyXRC::RC_SHOW_BANNER:
+	case LyXRC::RC_SOURCE_SPECIALS_SWITCH:
 	case LyXRC::RC_SPELL_COMMAND:
 	case LyXRC::RC_TEMPDIRPATH:
 	case LyXRC::RC_TEMPLATEPATH:
Index: src/lyxrc.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxrc.h,v
retrieving revision 1.93
diff -u -r1.93 lyxrc.h
--- src/lyxrc.h	2005/03/25 15:27:29	1.93
+++ src/lyxrc.h	2005/07/10 09:46:25
@@ -120,6 +120,7 @@
 		RC_SERVERPIPE,
 		RC_SET_COLOR,
 		RC_SHOW_BANNER,
+		RC_SOURCE_SPECIALS_SWITCH,
 		RC_SPELL_COMMAND,
 		RC_TEMPDIRPATH,
 		RC_TEMPLATEPATH,
@@ -384,6 +385,10 @@
 	 *  The string is input, stored and output in native format.
 	 */
 	std::string path_prefix;
+	/** Which command line option to pass to latex for
+	 *  dvi with source information
+	 */
+	std::string source_specials_switch;
 };
 
 
Index: src/lyxrc.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxrc.C,v
retrieving revision 1.191
diff -u -r1.191 lyxrc.C
--- src/lyxrc.C	2005/06/18 00:18:28	1.191
+++ src/lyxrc.C	2005/07/10 09:46:29
@@ -155,6 +155,7 @@
 	{ "\\serverpipe", LyXRC::RC_SERVERPIPE },
 	{ "\\set_color", LyXRC::RC_SET_COLOR },
 	{ "\\show_banner", LyXRC::RC_SHOW_BANNER },
+	{ "\\source_specials_switch", LyXRC::RC_SOURCE_SPECIALS_SWITCH },
 	{ "\\spell_command", LyXRC::RC_SPELL_COMMAND },
 	{ "\\tempdir_path", LyXRC::RC_TEMPDIRPATH },
 	{ "\\template_path", LyXRC::RC_TEMPLATEPATH },
@@ -280,6 +281,7 @@
 	preview = PREVIEW_OFF;
 	preview_hashed_labels  = false;
 	preview_scale_factor = "0.9";
+	source_specials_switch = "";
 
 	user_name = lyx::support::user_name();
 
@@ -1150,6 +1152,11 @@
 				path_prefix = lexrc.getString();
 			break;
 
+		case RC_SOURCE_SPECIALS_SWITCH:
+			if (lexrc.next())
+				source_specials_switch = lexrc.getString();
+			break;
+
 		case RC_LAST: break; // this is just a dummy
 		}
 	}
@@ -1978,6 +1985,11 @@
 	case RC_VIEWER:
 		// Ignore it
 
+	case RC_SOURCE_SPECIALS_SWITCH:
+		if (ignore_system_lyxrc ||
+		    source_specials_switch != system_lyxrc.source_specials_switch)
+			os << "\\source_specials_switch " << '"' << source_specials_switch << '"' << '\n';
+
 		os << "\n#\n"
 		   << "# CONVERTERS SECTION ##########################\n"
 		   << "#\n\n";
@@ -2387,6 +2399,10 @@
 
 	case RC_SHOW_BANNER:
 		str = _("De-select if you don't want the startup banner.");
+		break;
+
+	case RC_SOURCE_SPECIALS_SWITCH:
+		str = _("LaTeX command line switch to enable source information in the dvi.");
 		break;
 
 	case RC_SPELL_COMMAND:
Index: src/insets/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1160
diff -u -r1.1160 ChangeLog
--- src/insets/ChangeLog	2005/07/08 15:43:45	1.1160
+++ src/insets/ChangeLog	2005/07/10 09:46:38
@@ -1,3 +1,9 @@
+2005-07-10  Joao Luis Meloni Assirati  <[EMAIL PROTECTED]>
+
+	* ExternalSupport.C (updateExternal):
+	* insetgraphics.C (prepareFile): adjust from argument changes in
+	converters.convert.
+
 2005-07-08  Georg Baum  <[EMAIL PROTECTED]>
 
 	* ExternalSupport.C (subst_path): new argument exclude_extension
Index: src/insets/ExternalSupport.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/ExternalSupport.C,v
retrieving revision 1.20
diff -u -r1.20 ExternalSupport.C
--- src/insets/ExternalSupport.C	2005/07/09 08:13:53	1.20
+++ src/insets/ExternalSupport.C	2005/07/10 09:46:38
@@ -294,7 +294,7 @@
 		support::ChangeExtension(to_file, string());
 	/* bool const success = */
 		converters.convert(&buffer, temp_file, to_file_base,
-				   from_format, to_format, true);
+				   from_format, to_format, true, false);
 	// return success
 }
 
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.281
diff -u -r1.281 insetgraphics.C
--- src/insets/insetgraphics.C	2005/07/08 15:43:45	1.281
+++ src/insets/insetgraphics.C	2005/07/10 09:46:43
@@ -702,7 +702,7 @@
 		<< "\tfile to convert = " << temp_file << '\n'
 		<< "\t from " << from << " to " << to << '\n';
 
-	if (converters.convert(&buf, temp_file, temp_file, from, to, true)) {
+	if (converters.convert(&buf, temp_file, temp_file, from, to, true, false)) {
 		runparams.exportdata->addExternalFile("latex",
 				to_file, output_to_file);
 		runparams.exportdata->addExternalFile("dvi",
Index: lib/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/lib/ChangeLog,v
retrieving revision 1.714
diff -u -r1.714 ChangeLog
--- lib/ChangeLog	2005/07/07 10:51:54	1.714
+++ lib/ChangeLog	2005/07/10 09:59:01
@@ -1,3 +1,9 @@
+2005-07-10  Joao Luis Meloni Assirati  <[EMAIL PROTECTED]>
+
+	* configure.m4: add code to check if latex can do source specials.
+	Write the command line switch to lyxrc.defaults under the option
+	\source_specials_switch.
+
 2005-06-16  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
 
 	* languages: remove language "frenchb"; with language "french"
Index: lib/configure.m4
===================================================================
RCS file: /cvs/lyx/lyx-devel/lib/configure.m4,v
retrieving revision 1.101
diff -u -r1.101 configure.m4
--- lib/configure.m4	2005/06/14 10:29:46	1.101
+++ lib/configure.m4	2005/07/10 09:59:01
@@ -230,6 +230,29 @@
 latex_to_dvi=$LATEX
 test -z "$latex_to_dvi" && latex_to_dvi="none"
 
+echo -n "Checking if $LATEX can do source specials... "
+cat  >chksp.tex <<EOF
+\\nonstopmode
+\\documentclass{article}
+\\begin{document}
+Source specials test.
+\\end{document}
+EOF
+# Is there any other known switch for source specials
+# besides --src-specials?
+for opt in --src-specials; do
+  if $LATEX $opt chksp.tex </dev/null 1>/dev/null 2>&1; then
+    source_specials_switch=$opt
+    break
+  fi
+done
+if test "$source_specials_switch"; then
+  echo "yes with $source_specials_switch."
+else
+  echo "no."
+fi
+rm -f chksp.{tex,log,aux,dvi}
+
 # Search for pdflatex
 if test ${lyx_check_config} = no ; then
   latex_to_pdf=none
@@ -692,6 +715,7 @@
 $rc_entries
 \\font_encoding "$chk_fontenc"
 \\tex_allows_spaces $tex_allows_spaces
+\\source_specials_switch "$source_specials_switch"
 EOF
 
 if [ "x$use_cygwin_path_fix" != "x" ]

Reply via email to