]> git.lyx.org Git - features.git/commitdiff
Properly fix handling of title layouts within insets (#11787)
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 3 Jul 2020 14:18:53 +0000 (16:18 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 4 Jul 2020 07:44:31 +0000 (09:44 +0200)
(cherry picked from commit e4ef8ddc0f820290a2fead1149e1e950bd947832)

src/OutputParams.cpp
src/OutputParams.h
src/Paragraph.cpp
src/insets/InsetBranch.cpp
src/insets/InsetText.cpp
src/output_latex.cpp
status.23x

index d203761059bc0305b51f181f3c7b9ff9d99be139..a1bedbc1c50adb26e304f20e40c8e16254360164 100644 (file)
@@ -20,9 +20,9 @@ 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(0), master_language(0), encoding(enc), free_spacing(false),
-         use_babel(false), use_polyglossia(false), use_hyperref(false),
+         moving_arg(false), intitle(false), need_maketitle(false), have_maketitle(false),
+         inbranch(false), inulemcmd(0), local_font(0), master_language(0), encoding(enc),
+         free_spacing(false), use_babel(false), use_polyglossia(false), use_hyperref(false),
          use_indices(false), use_japanese(false), linelen(0), depth(0),
          exportdata(new ExportData), inDisplayMath(false), wasDisplayMath(false),
          inComment(false), openbtUnit(false), only_childbibs(false),
index 6366422c16c374b3526537099efb29c5654573ab..56e698c873ea0bc5160c04098fae0331ae0a215f 100644 (file)
@@ -102,6 +102,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.
        */
index e66474eecc8d5ffb085b43025327e0fc2650679d..5b5a94490cfd8a0de709ad2b71e5a9f9c50bf700 100644 (file)
@@ -2784,6 +2784,10 @@ void Paragraph::latex(BufferParams const & bparams,
                // such as Note that do not produce any output, so that no
                // 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;
        }
 
        // If we have an open font definition, we have to close it
index 4330504a6e8a968e6c544bcaa6dd00496c4ddd8d..460240f078996b7169a6f8bcfbf5db6e8b837def 100644 (file)
@@ -297,6 +297,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;
        }
 }
 
index da195b04ec71ed7cee40b18ee1b16746b58a41e3..d0a37d673200e82e0c889bf38eb191d6c05f7c10 100644 (file)
@@ -501,6 +501,9 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
        // Output the contents of the inset
        latexParagraphs(buffer(), text_, os, rp);
        runparams.encoding = rp.encoding;
+       // 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();
index 08958aabb22288945b20ab6d6e5224891f60e6f7..c382050680ef25f3fc689579b0cb68f6ad2e210d 100644 (file)
@@ -1318,6 +1318,9 @@ void TeXOnePar(Buffer const & buf,
        else
                runparams_in.encoding = runparams.encoding;
 
+       // 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!!!
        // Note from JMarc: we will re-add a \n explicitly in
@@ -1461,9 +1464,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)
@@ -1478,7 +1478,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"),
@@ -1488,15 +1488,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";
@@ -1505,8 +1505,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()
@@ -1541,10 +1541,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";
index 92a3fe637f276731246784cb155eb09a7b7e6141..1bf9d58c4ed1d02463a025829cb974f1b50a9d71 100644 (file)
@@ -45,8 +45,7 @@ What's new
 
 * DOCUMENT INPUT/OUTPUT
 
-- Fix wrong output of quotation marks in headings and captions with hyperref
-  enabled (bug 11889).
+- Fix output of titles in branches and other insets (follow-up to bug 11787).
 
 
 * USER INTERFACE