Introduce NeedCProtect -1 layout option

It turns out beamer frame does not allow \cprotect and errors if it is
used. Hence we need to prevent it in this context entirely.
This commit is contained in:
Juergen Spitzmueller 2024-05-12 07:52:16 +02:00
parent fe4f0dbf0b
commit 207eaeee90
7 changed files with 31 additions and 8 deletions

View File

@ -553,6 +553,7 @@ Style Frame
ExampleBlock,AlertBlock,Bibliography,Quotation,Quote,Verse,Corollary,Definition,Definitions, ExampleBlock,AlertBlock,Bibliography,Quotation,Quote,Verse,Corollary,Definition,Definitions,
Example,Examples,Fact,Lemma,Proof,Theorem,LyX-Code Example,Examples,Fact,Lemma,Proof,Theorem,LyX-Code
EndAutoNests EndAutoNests
NeedCProtect -1
End End
Style PlainFrame Style PlainFrame

View File

@ -162,6 +162,7 @@ Layout::Layout()
inpreamble = false; inpreamble = false;
needprotect = false; needprotect = false;
needcprotect = false; needcprotect = false;
nocprotect = false;
needmboxprotect = false; needmboxprotect = false;
keepempty = false; keepempty = false;
font = inherit_font; font = inherit_font;
@ -465,9 +466,17 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass,
lex >> needprotect; lex >> needprotect;
break; break;
case LT_NEED_CPROTECT: case LT_NEED_CPROTECT: {
lex >> needcprotect; int i;
lex >> i;
nocprotect = false;
needcprotect = false;
if (i == -1)
nocprotect = true;
else if (i == 1)
needcprotect = true;
break; break;
}
case LT_NEED_MBOXPROTECT: case LT_NEED_MBOXPROTECT:
lex >> needmboxprotect; lex >> needmboxprotect;

View File

@ -400,6 +400,9 @@ public:
/** true when the verbatim stuff of this layout needs to be /** true when the verbatim stuff of this layout needs to be
\cprotect'ed. */ \cprotect'ed. */
bool needcprotect; bool needcprotect;
/** true when the verbatim stuff of this layout never should be
\cprotect'ed. */
bool nocprotect;
/** true when specific commands in this paragraph need to be /** true when specific commands in this paragraph need to be
protected in an \mbox. */ protected in an \mbox. */
bool needmboxprotect; bool needmboxprotect;

View File

@ -108,6 +108,11 @@ public:
*/ */
bool moving_arg = false; bool moving_arg = false;
/** no_cprotect == true means that the layout in which this is
* does not allow \cprotect'ing.
*/
bool no_cprotect = false;
/** intitle == true means that the environment in which the /** intitle == true means that the environment in which the
inset is typeset is part of a title (before a \\maketitle). inset is typeset is part of a title (before a \\maketitle).
Footnotes in such environments have moving arguments. Footnotes in such environments have moving arguments.

View File

@ -1172,6 +1172,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
? textinset->hasCProtectContent(runparams.moving_arg) ? textinset->hasCProtectContent(runparams.moving_arg)
&& !textinset->text().isMainText() && !textinset->text().isMainText()
&& inset->lyxCode() != BRANCH_CODE && inset->lyxCode() != BRANCH_CODE
&& !runparams.no_cprotect
: false; : false;
unsigned int count2 = basefont.latexWriteStartChanges(os, bparams, unsigned int count2 = basefont.latexWriteStartChanges(os, bparams,
rp, running_font, rp, running_font,
@ -3014,6 +3015,7 @@ void Paragraph::latex(BufferParams const & bparams,
? textinset->hasCProtectContent(runparams.moving_arg) ? textinset->hasCProtectContent(runparams.moving_arg)
&& !textinset->text().isMainText() && !textinset->text().isMainText()
&& inInset().lyxCode() != BRANCH_CODE && inInset().lyxCode() != BRANCH_CODE
&& !runparams.no_cprotect
: false; : false;
column += current_font.latexWriteStartChanges(ots, bparams, column += current_font.latexWriteStartChanges(ots, bparams,
runparams, basefont, last_font, false, runparams, basefont, last_font, false,

View File

@ -500,7 +500,7 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
// FIXME UNICODE // FIXME UNICODE
// FIXME \protect should only be used for fragile // FIXME \protect should only be used for fragile
// commands, but we do not provide this information yet. // commands, but we do not provide this information yet.
if (hasCProtectContent(runparams.moving_arg)) { if (!runparams.no_cprotect && hasCProtectContent(runparams.moving_arg)) {
if (contains(runparams.active_chars, '^')) { if (contains(runparams.active_chars, '^')) {
// cprotect relies on ^ being on catcode 7 // cprotect relies on ^ being on catcode 7
os << "\\begingroup\\catcode`\\^=7"; os << "\\begingroup\\catcode`\\^=7";

View File

@ -404,7 +404,7 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams,
void TeXEnvironment(Buffer const & buf, Text const & text, void TeXEnvironment(Buffer const & buf, Text const & text,
OutputParams const & runparams, OutputParams const & runparams_in,
pit_type & pit, otexstream & os) pit_type & pit, otexstream & os)
{ {
ParagraphList const & paragraphs = text.paragraphs(); ParagraphList const & paragraphs = text.paragraphs();
@ -415,6 +415,9 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
depth_type const current_depth = ipar->params().depth(); depth_type const current_depth = ipar->params().depth();
Length const & current_left_indent = ipar->params().leftIndent(); Length const & current_left_indent = ipar->params().leftIndent();
OutputParams runparams = runparams_in;
runparams.no_cprotect = current_layout.nocprotect;
// This is for debugging purpose at the end. // This is for debugging purpose at the end.
pit_type const par_begin = pit; pit_type const par_begin = pit;
for (; pit < runparams.par_end; ++pit) { for (; pit < runparams.par_end; ++pit) {
@ -736,7 +739,7 @@ void parStartCommand(Paragraph const & par, otexstream & os,
{ {
switch (style.latextype) { switch (style.latextype) {
case LATEX_COMMAND: case LATEX_COMMAND:
if (par.needsCProtection(runparams.moving_arg)) { if (!runparams.no_cprotect && par.needsCProtection(runparams.moving_arg)) {
if (contains(runparams.active_chars, '^')) if (contains(runparams.active_chars, '^'))
// cprotect relies on ^ being on catcode 7 // cprotect relies on ^ being on catcode 7
os << "\\begingroup\\catcode`\\^=7"; os << "\\begingroup\\catcode`\\^=7";
@ -871,7 +874,7 @@ void TeXOnePar(Buffer const & buf,
// the code is different (JMarc) // the code is different (JMarc)
if (style.isCommand()) { if (style.isCommand()) {
os << "}"; os << "}";
if (par.needsCProtection(runparams.moving_arg) if (!runparams.no_cprotect && par.needsCProtection(runparams.moving_arg)
&& contains(runparams.active_chars, '^')) && contains(runparams.active_chars, '^'))
os << "\\endgroup"; os << "\\endgroup";
if (merged_par) if (merged_par)
@ -1234,7 +1237,7 @@ void TeXOnePar(Buffer const & buf,
os << runparams.post_macro; os << runparams.post_macro;
runparams.post_macro.clear(); runparams.post_macro.clear();
} }
if (par.needsCProtection(runparams.moving_arg) if (!runparams.no_cprotect && par.needsCProtection(runparams.moving_arg)
&& contains(runparams.active_chars, '^')) && contains(runparams.active_chars, '^'))
os << "\\endgroup"; os << "\\endgroup";
if (runparams.encoding != prev_encoding) { if (runparams.encoding != prev_encoding) {
@ -1405,7 +1408,7 @@ void TeXOnePar(Buffer const & buf,
os << runparams.post_macro; os << runparams.post_macro;
runparams.post_macro.clear(); runparams.post_macro.clear();
} }
if (par.needsCProtection(runparams.moving_arg) if (!runparams.no_cprotect && par.needsCProtection(runparams.moving_arg)
&& contains(runparams.active_chars, '^')) && contains(runparams.active_chars, '^'))
os << "\\endgroup"; os << "\\endgroup";
if (runparams.encoding != prev_encoding) { if (runparams.encoding != prev_encoding) {