From: Juergen Spitzmueller Date: Sun, 19 Apr 2020 08:55:32 +0000 (+0200) Subject: Improve reporting of undefined control sequences in preamble X-Git-Tag: lyx-2.4.0dev-acb2ca7b~987 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=05c7c65d9345c4cd88b9c34b8e30beb96a268963;hp=3f89dd0b4864eff14db44fe8325d20124875d991;p=features.git Improve reporting of undefined control sequences in preamble Fixes #11844 --- 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)