]> git.lyx.org Git - lyx.git/commitdiff
Fix computation of InsetLayout arguments for InsetText
authorGuillaume MM <gm@lyx.org>
Fri, 12 May 2017 22:51:21 +0000 (00:51 +0200)
committerGuillaume MM <gm@lyx.org>
Sat, 13 May 2017 14:12:25 +0000 (16:12 +0200)
Do not take the optional arguments from the first paragraph, but from the
paragraphs whose layout have no arguments, consistently with the code in
InsetArgument::updateBuffer (i.e. what was shown on screen).

src/Layout.cpp
src/Layout.h
src/insets/InsetArgument.cpp
src/insets/InsetText.cpp
src/output_latex.cpp
src/output_latex.h

index b9674772e22abdcebebf72cfee6630fdedc2da65..3d1d78136018f859af6d41d801ab3854443b37c1 100644 (file)
@@ -1424,6 +1424,13 @@ void Layout::write(ostream & os) const
 }
 
 
+bool Layout::hasArgs() const
+{
+       return !latexargs_.empty() || !postcommandargs_.empty() ||
+               !itemargs_.empty();
+}
+
+
 Layout::LaTeXArgMap Layout::args() const
 {
        LaTeXArgMap args = latexargs_;
index 184711b3b4b9c48c2af1e642b6e229b4c17fd111..ba4d26fb37c76a475a280f1bf2a91c5bde7615a0 100644 (file)
@@ -117,6 +117,9 @@ public:
        LaTeXArgMap const & postcommandargs() const { return postcommandargs_; }
        ///
        LaTeXArgMap const & itemargs() const { return itemargs_; }
+       /// Returns true is the layout has arguments. If false, then an
+       /// InsetArgument in this layout stands for the parent InsetText.
+       bool hasArgs() const;
        /// Returns latexargs() + postcommandargs() + itemargs().
        /// But note that it returns a *copy*, not a reference, so do not do
        /// anything like:
index cff8cec4fe1695e63d4f0399f128ce3fc2d9a2c7..e22bcdeb4e59385078a0547293c5d788096b4d31 100644 (file)
@@ -63,13 +63,11 @@ void InsetArgument::read(Lexer & lex)
 
 void InsetArgument::updateBuffer(ParIterator const & it, UpdateType utype)
 {
-       Layout::LaTeXArgMap args = it.paragraph().layout().args();
-       pass_thru_context_ = it.paragraph().layout().pass_thru;
-       bool const insetlayout = args.empty();
-       if (insetlayout) {
-               args = it.inset().getLayout().args();
-               pass_thru_context_ = it.inset().getLayout().isPassThru();
-       }
+       bool const insetlayout = !it.paragraph().layout().hasArgs();
+       Layout::LaTeXArgMap const args = insetlayout ?
+               it.inset().getLayout().args() : it.paragraph().layout().args();
+       pass_thru_context_ = insetlayout ?
+               it.inset().getLayout().isPassThru() : it.paragraph().layout().pass_thru;
 
        // Handle pre 2.1 ArgInsets (lyx2lyx cannot classify them)
        if (name_ == "999") {
index afa672dbcffa8e109420fdc5a2c81db08ed35291..7680ee5fa925d8e06d4b0402c5bf143aa4ce12a5 100644 (file)
@@ -653,6 +653,7 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
        return docstring();
 }
 
+
 void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
                        bool const post) const
 {
@@ -662,9 +663,11 @@ void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
        if (isPassThru())
                runparams.pass_thru = true;
        if (post)
-               latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:");
+               latexArgInsetsForParent(paragraphs(), os, runparams,
+                                       getLayout().postcommandargs(), "post:");
        else
-               latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
+               latexArgInsetsForParent(paragraphs(), os, runparams,
+                                       getLayout().latexargs());
 }
 
 
index 0f79ca1838265c96e82ed40b21c3728bec5a1e80..e2924421438f191c318d3a747d43024a69088ddc 100644 (file)
@@ -610,6 +610,24 @@ void latexArgInsets(ParagraphList const & pars,
 }
 
 
+void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os,
+                             OutputParams const & runparams,
+                             Layout::LaTeXArgMap const & latexargs,
+                             string const & prefix)
+{
+       map<int, InsetArgument const *> ilist;
+       vector<string> required;
+
+       for (Paragraph const & par : pars) {
+               if (par.layout().hasArgs())
+                       // The InsetArguments inside this paragraph refer to this paragraph
+                       continue;
+               addArgInsets(par, prefix, latexargs, ilist, required);
+       }
+       getArgInsets(os, runparams, latexargs, ilist, required, prefix);
+}
+
+
 namespace {
 
 // output the proper paragraph start according to latextype.
index fdbc38febb327ab4ea28ac822de3b2f3fd6c3930..31125f788de0b1820f11a0b0a97decf94363bc71 100644 (file)
@@ -42,14 +42,20 @@ void popPolyglossiaLang();
     Non-existing required arguments are output empty: {}.
  */
 void latexArgInsets(Paragraph const & par,
-               otexstream & os, OutputParams const & runparams,
-               Layout::LaTeXArgMap const & latexargs,
-               std::string const & prefix = std::string());
-/// Same for multi-par sequences (e.g. merged environments or InsetLayouts)
-void latexArgInsets(ParagraphList const & pars, ParagraphList::const_iterator pit,
-               otexstream & os, OutputParams const & runparams,
-               Layout::LaTeXArgMap const & latexargs,
-               std::string const & prefix = std::string());
+                    otexstream & os, OutputParams const & runparams,
+                    Layout::LaTeXArgMap const & latexargs,
+                    std::string const & prefix = std::string());
+/// Same for merged environments
+void latexArgInsets(ParagraphList const & pars,
+                    ParagraphList::const_iterator pit,
+                    otexstream & os, OutputParams const & runparams,
+                    Layout::LaTeXArgMap const & latexargs,
+                    std::string const & prefix = std::string());
+/// Same for InsetLayouts
+void latexArgInsetsForParent(ParagraphList const & pars, otexstream & os,
+                             OutputParams const & runparams,
+                             Layout::LaTeXArgMap const & latexargs,
+                             std::string const & prefix = std::string());
 /** Export \p paragraphs of buffer \p buf to LaTeX.
     Don't use a temporary stringstream for \p os if the final output is
     supposed to go to a file.