From: Juergen Spitzmueller Date: Sun, 21 Apr 2019 14:44:29 +0000 (+0200) Subject: \cprotect some content in captions X-Git-Tag: lyx-2.4.0dev-acb2ca7b~2119 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c9432ccbbc2ec0029d9ac59ed8da126f4a02a910;p=features.git \cprotect some content in captions Fixes: #6243 --- diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index a41fe6728f..59cfa64576 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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; } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index ce69bef255..9cc3e002d2 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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(); diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 41bfa18367..2552f10967 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -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: ///