]> git.lyx.org Git - features.git/commitdiff
Fix cprotect with Slovak
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 14 Aug 2019 12:00:29 +0000 (14:00 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:43 +0000 (15:48 +0200)
babel-slovak makes ^ active, though cprotect relies on it being
catcode 9 ("ignored"). Thus we locally change the catcode with Slovak.

lib/languages
src/insets/InsetBox.cpp
src/insets/InsetText.cpp
src/output_latex.cpp

index 65e2d33b5d28afe4d971b7a24da827ff42ae873e..9cadbe7b45f5ffe0c3317c3a17107788525d474c 100644 (file)
@@ -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"
index 7711277e0a90f2d6c22348fc8ebb1e3188ad19f2..86e35f745f69bfbc3739e068d3e73a1834a02a3a 100644 (file)
@@ -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 << "}";
index 9cc3e002d284dfd0c66c6c34a24ce9e87928bfa2..d264b2f59fdc3a088207887dd62d943c3b72793c 100644 (file)
@@ -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)
index 891e74cf17e56cbedb179b940a73257689d8338d..ad4db9b5270b75f2821706dc5928eda1642d3784 100644 (file)
@@ -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());