commit c9432ccbbc2ec0029d9ac59ed8da126f4a02a910
Author: Juergen Spitzmueller <[email protected]>
Date: Sun Apr 21 16:44:29 2019 +0200
\cprotect some content in captions
Fixes: #6243
---
src/Paragraph.cpp | 29 ++++++++++++++++++++++++++---
src/insets/InsetText.cpp | 11 ++++++-----
src/insets/InsetText.h | 2 +-
3 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index a41fe67..59cfa64 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 ce69bef..9cc3e00 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 41bfa18..2552f10 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:
///