From 05c7c65d9345c4cd88b9c34b8e30beb96a268963 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 19 Apr 2020 10:55:32 +0200 Subject: [PATCH 1/1] Improve reporting of undefined control sequences in preamble Fixes #11844 --- src/LaTeX.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp index 5333c7fbae..be94654954 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) -- 2.39.2