]> git.lyx.org Git - features.git/commitdiff
\cprotect some content in captions
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 21 Apr 2019 14:44:29 +0000 (16:44 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 21 Apr 2019 14:44:29 +0000 (16:44 +0200)
Fixes: #6243
src/Paragraph.cpp
src/insets/InsetText.cpp
src/insets/InsetText.h

index a41fe6728fec0d045798a85e847c6e56c336e5ec..59cfa6457674363a652c7373dd3fbe66b4418810 100644 (file)
@@ -1647,6 +1647,8 @@ void Paragraph::validate(LaTeXFeatures & features) const
        d->validate(features);
        bool fragile = features.runparams().moving_arg;
        fragile |= layout().needprotect;
+       if (inInset().getLayout().isNeedProtect())
+               fragile = true;
        if (needsCProtection(fragile))
                features.require("cprotect");
 }
@@ -3435,10 +3437,31 @@ bool Paragraph::needsCProtection(bool const fragile) const
        }
 
        // now check whether we have insets that need cprotection
-       pos_type size = d->text_.size();
-       for (pos_type i = 0; i < size; ++i)
-               if (isInset(i) && getInset(i)->needsCProtection(maintext, fragile))
+       pos_type size = pos_type(d->text_.size());
+       for (pos_type i = 0; i < size; ++i) {
+               if (!isInset(i))
+                       continue;
+               Inset const * ins = getInset(i);
+               if (ins->needsCProtection(maintext, fragile))
+                       return true;
+               if (ins->getLayout().latextype() == InsetLayout::ENVIRONMENT)
+                       // Environments need cprotection regardless the content
+                       return true;
+               // Now check math environments
+               InsetMath const * im = getInset(i)->asInsetMath();
+               if (!im || im->cell(0).empty())
+                       continue;
+               switch(im->cell(0)[0]->lyxCode()) {
+               case MATH_AMSARRAY_CODE:
+               case MATH_SUBSTACK_CODE:
+               case MATH_ENV_CODE:
+               case MATH_XYMATRIX_CODE:
+                       // these need cprotection
                        return true;
+               default:
+                       break;
+               }
+       }
 
        return false;
 }
index ce69bef2554ee3fb954da62c1fa6a4feecb6fb07..9cc3e002d284dfd0c66c6c34a24ce9e87928bfa2 100644 (file)
@@ -769,12 +769,13 @@ ParagraphList & InsetText::paragraphs()
 }
 
 
-bool InsetText::hasCProtectContent(bool const fragile) const
+bool InsetText::hasCProtectContent(bool fragile) const
 {
+       fragile |= getLayout().isNeedProtect();
        ParagraphList const & pars = paragraphs();
-       pit_type pend = paragraphs().size();
+       pit_type pend = pit_type(paragraphs().size());
        for (pit_type pit = 0; pit != pend; ++pit) {
-               Paragraph const & par = pars[pit];
+               Paragraph const & par = pars[size_type(pit)];
                if (par.needsCProtection(fragile))
                        return true;
        }
@@ -1127,10 +1128,10 @@ bool InsetText::needsCProtection(bool const maintext, bool const fragile) const
                '&', '_', '$', '%', '#', '^', '{', '}', '\\'};
 
        ParagraphList const & pars = paragraphs();
-       pit_type pend = paragraphs().size();
+       pit_type pend = pit_type(paragraphs().size());
 
        for (pit_type pit = 0; pit != pend; ++pit) {
-               Paragraph const & par = pars[pit];
+               Paragraph const & par = pars[size_type(pit)];
                if (par.needsCProtection(fragile))
                        return true;
                docstring const pars = par.asString();
index 41bfa183671f664bef0141244b024ee6246ba447..2552f1096719fb76266a5f1c47b7e563bf094a4f 100644 (file)
@@ -227,7 +227,7 @@ public:
        bool needsCProtection(bool const maintext = false,
                              bool const fragile = false) const;
        ///
-       bool hasCProtectContent(bool const fragile = false) const;
+       bool hasCProtectContent(bool fragile = false) const;
 
 protected:
        ///