From f995fba310c203fdba6a55f0ad62830a7d2d704c Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 14 Aug 2019 14:00:29 +0200 Subject: [PATCH] Fix cprotect with Slovak babel-slovak makes ^ active, though cprotect relies on it being catcode 9 ("ignored"). Thus we locally change the catcode with Slovak. --- lib/languages | 2 +- src/insets/InsetBox.cpp | 13 +++++++++++-- src/insets/InsetText.cpp | 12 ++++++++++-- src/output_latex.cpp | 21 ++++++++++++++++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/lib/languages b/lib/languages index 65e2d33b5d..9cadbe7b45 100644 --- a/lib/languages +++ b/lib/languages @@ -1336,7 +1336,7 @@ Language slovak BabelName slovak PolyglossiaName slovak QuoteStyle german - ActiveChars - + ActiveChars -^ Encoding iso8859-2 FontEncoding T1|OT1 DateFormats "d. MMMM yyyy|d. MMM yyyy|d.M.yyyy" diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index 7711277e0a..86e35f745f 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -396,6 +396,7 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const if (stdwidth && !(buffer().params().paragraph_separation)) os << "\\noindent"; + bool needendgroup = false; switch (btype) { case Frameless: break; @@ -439,8 +440,14 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const } else { if (params_.framecolor != "black" || params_.backgroundcolor != "none") os << "\\fcolorbox{" << params_.framecolor << "}{" << params_.backgroundcolor << "}"; - else + else { + if (!cprotect.empty() && contains(runparams.active_chars, '^')) { + // cprotect relies on ^ being ignored + os << "\\begingroup\\catcode`\\^=9"; + needendgroup = true; + } os << cprotect << "\\fbox"; + } } os << "{"; break; @@ -590,8 +597,10 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const if (!params_.inner_box && !width_string.empty() && (params_.framecolor != "black" || params_.backgroundcolor != "none")) os << "}"; - if (separation_string != defaultSep || thickness_string != defaultThick) + if (separation_string != defaultSep || thickness_string != defaultThick) os << "}"; + if (needendgroup) + os << "\\endgroup"; break; case ovalbox: os << "}"; diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index 9cc3e002d2..d264b2f59f 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -454,14 +454,20 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const InsetLayout const & il = getLayout(); if (il.forceOwnlines()) os << breakln; + bool needendgroup = false; if (!il.latexname().empty()) { if (il.latextype() == InsetLayout::COMMAND) { // FIXME UNICODE // FIXME \protect should only be used for fragile // commands, but we do not provide this information yet. - if (hasCProtectContent(runparams.moving_arg)) + if (hasCProtectContent(runparams.moving_arg)) { + if (contains(runparams.active_chars, '^')) { + // cprotect relies on ^ being ignored + os << "\\begingroup\\catcode`\\^=9"; + needendgroup = true; + } os << "\\cprotect"; - else if (runparams.moving_arg) + } else if (runparams.moving_arg) os << "\\protect"; os << '\\' << from_utf8(il.latexname()); if (!il.latexargs().empty()) @@ -522,6 +528,8 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const os << "}"; if (!il.postcommandargs().empty()) getArgs(os, runparams, true); + if (needendgroup) + os << "\\endgroup"; } else if (il.latextype() == InsetLayout::ENVIRONMENT) { // A comment environment doesn't need a % before \n\end if (il.isDisplay() || runparams.inComment) diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 891e74cf17..ad4db9b527 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -679,8 +679,12 @@ void parStartCommand(Paragraph const & par, otexstream & os, { switch (style.latextype) { case LATEX_COMMAND: - if (par.needsCProtection(runparams.moving_arg)) + if (par.needsCProtection(runparams.moving_arg)) { + if (contains(runparams.active_chars, '^')) + // cprotect relies on ^ being ignored + os << "\\begingroup\\catcode`\\^=9"; os << "\\cprotect"; + } os << '\\' << from_ascii(style.latexname()); // Command arguments @@ -794,8 +798,13 @@ void TeXOnePar(Buffer const & buf, // I did not create a parEndCommand for this minuscule // task because in the other user of parStartCommand // the code is different (JMarc) - if (style.isCommand()) - os << "}\n"; + if (style.isCommand()) { + os << "}"; + if (par.needsCProtection(runparams.moving_arg) + && contains(runparams.active_chars, '^')) + os << "\\endgroup"; + os << "\n"; + } else os << '\n'; if (!style.parbreak_is_newline) { @@ -1116,6 +1125,9 @@ void TeXOnePar(Buffer const & buf, os << runparams.post_macro; runparams.post_macro.clear(); } + if (par.needsCProtection(runparams.moving_arg) + && contains(runparams.active_chars, '^')) + os << "\\endgroup"; if (runparams.encoding != prev_encoding) { runparams.encoding = prev_encoding; os << setEncoding(prev_encoding->iconvName()); @@ -1280,6 +1292,9 @@ void TeXOnePar(Buffer const & buf, os << runparams.post_macro; runparams.post_macro.clear(); } + if (par.needsCProtection(runparams.moving_arg) + && contains(runparams.active_chars, '^')) + os << "\\endgroup"; if (runparams.encoding != prev_encoding) { runparams.encoding = prev_encoding; os << setEncoding(prev_encoding->iconvName());