[LyX/master] Improve reporting of undefined control sequences in preamble

Juergen Spitzmueller spitz at lyx.org
Sun Apr 19 08:36:17 UTC 2020


commit 05c7c65d9345c4cd88b9c34b8e30beb96a268963
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
---
 src/LaTeX.cpp |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index 5333c7f..be94654 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -1051,10 +1051,15 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 
 			// get the next line
 			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.
@@ -1076,6 +1081,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");
@@ -1088,6 +1102,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)


More information about the lyx-cvs mailing list