[LyX/master] Improved synctex support

Stephan Witt switt at lyx.org
Sat Aug 13 11:34:01 UTC 2022


commit f426470a5403a956606a3f0f4df38e0c7407ab40
Author: Stephan Witt <switt at lyx.org>
Date:   Sat Aug 13 14:20:03 2022 +0200

    Improved synctex support
    
    - Add check for converter with active synctex support to check for synchronized output for activate forward search.
---
 src/Buffer.cpp               |   16 ++++++++++++++++
 src/Buffer.h                 |    5 +++++
 src/frontends/qt/GuiView.cpp |    2 +-
 3 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 96005b9..da630da 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1110,6 +1110,22 @@ bool Buffer::readDocument(Lexer & lex)
 }
 
 
+bool Buffer::isSyncTeXenabled() const
+{
+	bool enabled = params().output_sync;
+
+	if (!enabled)
+		for (auto const & c : theConverters()) {
+			const string dest = c.to().substr(0,3);
+			if (dest == "dvi" || dest == "pdf") {
+				const string cmd = c.command();
+				enabled |= cmd.find("--synctex=1") != string::npos;
+				if (enabled) break;
+			}
+		}
+	return enabled;
+}
+
 bool Buffer::importString(string const & format, docstring const & contents, ErrorList & errorList)
 {
 	Format const * fmt = theFormats().getFormat(format);
diff --git a/src/Buffer.h b/src/Buffer.h
index 7f40351..ba066f7 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -221,6 +221,11 @@ public:
 	int readHeader(Lexer & lex);
 
 	double fontScalingFactor() const;
+	/// check for active synctex support:
+	/// - either the document has synchronize output enabled or
+	/// - there is a converter to dvi or pdf defined with synctex command line argument
+	///   this is the "expert mode", false positives are possible
+	bool isSyncTeXenabled() const;
 
 private:
 	///
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 4492e75..d03fe3b 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -2681,7 +2681,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 		break;
 	case LFUN_FORWARD_SEARCH:
 		enable = !(lyxrc.forward_search_dvi.empty() && lyxrc.forward_search_pdf.empty()) &&
-			doc_buffer && doc_buffer->params().output_sync;
+			doc_buffer && doc_buffer->isSyncTeXenabled();
 		break;
 
 	case LFUN_FILE_INSERT_PLAINTEXT:


More information about the lyx-cvs mailing list