[LyX/2.3.x] Improve reporting of undefined control sequences in preamble

Juergen Spitzmueller spitz at lyx.org
Sun Apr 19 15:11:37 UTC 2020


commit a80ecb3820f9dc076b3c817303cf3382e69e99b2
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sun Apr 19 10:55:32 2020 +0200

    Improve reporting of undefined control sequences in preamble
    
    Fixes #11844
    
    (cherry picked from commit 05c7c65d9345c4cd88b9c34b8e30beb96a268963)
---
 src/LaTeX.cpp |   17 +++++++++++++++++
 status.23x    |   17 ++++++++++-------
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index e541361..4be0dad 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -840,10 +840,15 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 			// get the next line
 			string tmp;
 			int count = 0;
+			// We also collect intermediate lines
+			// This is needed for errors in preamble
+			string intermediate;
 			do {
 				if (!getline(ifs, tmp))
 					break;
 				tmp = rtrim(tmp, "\r");
+				if (!prefixIs(tmp, "l."))
+					intermediate += tmp;
 				// 15 is somewhat arbitrarily chosen, based on practice.
 				// We used 10 for 14 years and increased it to 15 when we
 				// saw one case.
@@ -865,6 +870,15 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 				sscanf(tmp.c_str(), "l.%d", &line);
 				// get the rest of the message:
 				string errstr(tmp, tmp.find(' '));
+				bool preamble_error = false;
+				if (suffixIs(errstr, "\\begin{document}")) {
+					// this is an error in preamble
+					// the real error is in the
+					// intermediate lines
+					errstr = intermediate;
+					tmp = intermediate;
+					preamble_error = true;
+				}
 				errstr += '\n';
 				getline(ifs, tmp);
 				tmp = rtrim(tmp, "\r");
@@ -877,6 +891,9 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 					getline(ifs, tmp);
 					tmp = rtrim(tmp, "\r");
 				}
+				if (preamble_error)
+					// Add a note that the error is to be found in preamble
+					errstr += "\n" + to_utf8(_("(NOTE: The erroneous command is in the preamble)"));
 				LYXERR(Debug::LATEX, "line: " << line << '\n'
 					<< "Desc: " << desc << '\n' << "Text: " << errstr);
 				if (line == last_line)
diff --git a/status.23x b/status.23x
index a6ead19..5a8ec3c 100644
--- a/status.23x
+++ b/status.23x
@@ -76,6 +76,14 @@ What's new
 
 * USER INTERFACE
 
+- Avoid crash in some cases where a dialog is shown during operation
+  (bug 11763).
+
+- Fix crash with nested insets when spaces are removed automatically (bug 11777).
+
+- Fix a crash reported on lyx users.
+  There was an uninitialized buffer member of MathData in LFUN dispatch.
+
 - Fix backspace deletion of selected items with change tracking (bug 11630).
 
 - Fix display glitch where the change tracking cue blinks with the cursor
@@ -85,9 +93,6 @@ What's new
 
 - Properly resize columns of child document table widget.
 
-- Fix a crash reported on lyx users.
-  There was an uninitialized buffer member of MathData in LFUN dispatch.
-
 - Fix problem with validation of InsetLayout.
 
 - Fix over-hasty resetting of dialog in Child Documents settings (bug 11564).
@@ -103,13 +108,11 @@ What's new
 - Disallow adding columns with gathered environment as this is not
   supported (bug 11812).
 
-- Preserve paragarph spacing when breaking a paragraph at the start
+- Preserve paragraph spacing when breaking a paragraph at the start
   (bug 11817).
 
-- Avoid crash in some cases where a dialog is shown during operation
-  (bug 11763).
+- Improve reporting of undefined control sequences in preamble (bug 11844).
 
-- Fix crash with nested insets when spaces are removed automatically (bug 11777).
 
 * INTERNALS
 


More information about the lyx-cvs mailing list