\cprotect some content in captions

Fixes: #6243
This commit is contained in:
Juergen Spitzmueller 2019-04-21 16:44:29 +02:00
parent 3663f9d0db
commit c9432ccbbc
3 changed files with 33 additions and 9 deletions

View 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;
}

View 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();

View 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:
///