[LyX/master] Error if tex file has a preamble but no (accessible) \begin{document} (#13297)
Juergen Spitzmueller <[email protected]>
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit b1a75e7ffa969cfacc6c3fa7088476999d5b0ae0 Author: Juergen Spitzmueller <[email protected]> Date: Wed Apr 8 08:52:45 2026 +0200 Error if tex file has a preamble but no (accessible) \begin{document} (#13297) --- src/tex2lyx/Preamble.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 3ee922054b..3137e2df74 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -2762,6 +2762,10 @@ void Preamble::parse(Parser & p, string const & forceclass, class_set = true; } + // if we have a full document, check that we have + // a body (see #13297) + bool complete_preamble = false; + while (is_full_document && p.good()) { if (detectEncoding && h_inputencoding != "auto-legacy" && h_inputencoding != "auto-legacy-plain") @@ -3546,8 +3550,10 @@ void Preamble::parse(Parser & p, string const & forceclass, if (t.cs() == "begin") { string const name = p.getArg('{', '}'); - if (name == "document") + if (name == "document") { + complete_preamble = true; break; + } h_preamble << "\\begin{" << name << "}"; continue; } @@ -3765,6 +3771,11 @@ void Preamble::parse(Parser & p, string const & forceclass, } } + if (is_full_document && !complete_preamble) { + error_message("Found preamble but not \\begin{document}. Aborting!"); + exit(EXIT_FAILURE); + } + // set textclass if not yet done (snippets without \documentclass and forced class) if (!class_set) setTextClass(h_textclass, tc); -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs