From e4ef8ddc0f820290a2fead1149e1e950bd947832 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 3 Jul 2020 16:18:53 +0200 Subject: [PATCH] Properly fix handling of title layouts within insets (#11787) --- src/OutputParams.cpp | 7 ++++--- src/OutputParams.h | 9 +++++++++ src/Paragraph.cpp | 4 ++++ src/insets/InsetBranch.cpp | 3 +++ src/insets/InsetText.cpp | 3 +++ src/output_latex.cpp | 22 +++++++++++----------- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index 9381bd5cda..0409634be3 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -20,9 +20,10 @@ namespace lyx { OutputParams::OutputParams(Encoding const * enc) : flavor(LATEX), math_flavor(NotApplicable), nice(false), is_child(false), - moving_arg(false), intitle(false), inbranch(false), inulemcmd(0), - local_font(nullptr),master_language(nullptr), encoding(enc), free_spacing(false), - use_babel(false), use_polyglossia(false), use_hyperref(false), use_CJK(false), + moving_arg(false), intitle(false), need_maketitle(false), have_maketitle(false), + inbranch(false), inulemcmd(0), local_font(nullptr),master_language(nullptr), + encoding(enc), free_spacing(false), use_babel(false), use_polyglossia(false), + use_hyperref(false), use_CJK(false), use_indices(false), use_japanese(false), linelen(0), depth(0), exportdata(new ExportData), postpone_fragile_stuff(false), inDisplayMath(false), wasDisplayMath(false), inComment(false), openbtUnit(false), only_childbibs(false), diff --git a/src/OutputParams.h b/src/OutputParams.h index 46495fe66e..177832178a 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -112,6 +112,15 @@ public: */ bool intitle; + /** need_maketitle == true means that the last layout was a title layout + * this is to track when \maketitle needs to be output. + */ + mutable bool need_maketitle; + + /** have_maketitle == true means that \maketitle already hase been output. + */ + mutable bool have_maketitle; + /** inbranch == true means that the environment being typeset is inside an active branch inset. */ diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index fa99c1af81..5d1a7fe820 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2812,6 +2812,10 @@ void Paragraph::latex(BufferParams const & bparams, // command is ever executed but its opening was recorded. runparams.inulemcmd = rp.inulemcmd; + // These need to be passed upstream as well + runparams.need_maketitle = rp.need_maketitle; + runparams.have_maketitle = rp.have_maketitle; + // And finally, pass the post_macros upstream runparams.post_macro = rp.post_macro; } diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 6d87af7fae..db987ba0d3 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -311,6 +311,9 @@ void InsetBranch::latex(otexstream & os, OutputParams const & runparams) const OutputParams rp = runparams; rp.inbranch = true; InsetText::latex(os, rp); + // These need to be passed upstream + runparams.need_maketitle = rp.need_maketitle; + runparams.have_maketitle = rp.have_maketitle; } } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index ac10443d00..ba716aeba3 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -529,6 +529,9 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const runparams.encoding = rp.encoding; // Pass the post_macros upstream runparams.post_macro = rp.post_macro; + // These need to be passed upstream as well + runparams.need_maketitle = rp.need_maketitle; + runparams.have_maketitle = rp.have_maketitle; if (!il.rightdelim().empty()) os << il.rightdelim(); diff --git a/src/output_latex.cpp b/src/output_latex.cpp index f23fbda293..d567ecc53c 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -1442,6 +1442,9 @@ void TeXOnePar(Buffer const & buf, // Also pass the post_macros upstream runparams_in.post_macro = runparams.post_macro; + // These need to be passed upstream as well + runparams_in.need_maketitle = runparams.need_maketitle; + runparams_in.have_maketitle = runparams.have_maketitle; // we don't need a newline for the last paragraph!!! @@ -1592,9 +1595,6 @@ void latexParagraphs(Buffer const & buf, pit_type pit = runparams.par_begin; // lastpit is for the language check after the loop. pit_type lastpit = pit; - // variables used in the loop: - bool was_title = false; - bool already_title = false; DocumentClass const & tclass = bparams.documentClass(); // Did we already warn about inTitle layout mixing? (we only warn once) @@ -1609,7 +1609,7 @@ void latexParagraphs(Buffer const & buf, tclass.plainLayout() : par->layout(); if (layout.intitle) { - if (already_title) { + if (runparams.have_maketitle) { if (!gave_layout_warning && !runparams.dryrun) { gave_layout_warning = true; frontend::Alert::warning(_("Error in latexParagraphs"), @@ -1619,15 +1619,15 @@ void latexParagraphs(Buffer const & buf, "could lead to missing or incorrect output." ), layout.name())); } - } else if (!was_title) { - was_title = true; + } else if (!runparams.need_maketitle) { + runparams.need_maketitle = true; if (tclass.titletype() == TITLE_ENVIRONMENT) { os << "\\begin{" << from_ascii(tclass.titlename()) << "}\n"; } } - } else if (was_title && !already_title && !layout.inpreamble) { + } else if (runparams.need_maketitle && !runparams.have_maketitle && !layout.inpreamble) { if (tclass.titletype() == TITLE_ENVIRONMENT) { os << "\\end{" << from_ascii(tclass.titlename()) << "}\n"; @@ -1636,8 +1636,8 @@ void latexParagraphs(Buffer const & buf, os << "\\" << from_ascii(tclass.titlename()) << "\n"; } - already_title = true; - was_title = false; + runparams.have_maketitle = true; + runparams.need_maketitle = false; } if (layout.isCommand() && !layout.latexname().empty() @@ -1689,10 +1689,10 @@ void latexParagraphs(Buffer const & buf, } // It might be that we only have a title in this document. - // But if we're in a branch, this is not the end of + // But if we're in an inset, this is not the end of // the document. (There may be some other checks of this // kind that are needed.) - if (was_title && !already_title && !runparams.inbranch) { + if (runparams.need_maketitle && !runparams.have_maketitle && maintext) { if (tclass.titletype() == TITLE_ENVIRONMENT) { os << "\\end{" << from_ascii(tclass.titlename()) << "}\n"; -- 2.39.5