]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Russian layouttranslations reviewed by Yuriy, Dec 13 2017.
[lyx.git] / src / output_latex.cpp
index 4ef1d456243f87ad140c8973b6ac299210a6b299..5bb21cc2ac8bc3466904f3d1eaa34f81854d63b0 100644 (file)
@@ -532,6 +532,14 @@ void popLanguageName()
 }
 
 
+string const & openLanguageName()
+{
+       OutputState * state = getOutputState();
+
+       return openLanguageName(state);
+}
+
+
 namespace {
 
 void addArgInsets(Paragraph const & par, string const & prefix,
@@ -804,6 +812,14 @@ void TeXOnePar(Buffer const & buf,
        bool const using_begin_end = use_polyglossia ||
                                        !lang_end_command.empty();
 
+       // For InTitle commands, we need to switch the language inside the command
+       // (see #10849); thus open the command here.
+       bool const intitle_command = style.intitle && style.latextype == LATEX_COMMAND;
+       if (intitle_command) {
+               parStartCommand(par, os, runparams, style);
+               os << '{';
+       }
+
        // In some insets (such as Arguments), we cannot use \selectlanguage
        bool const localswitch = text.inset().forceLocalFontSwitch()
                        || (using_begin_end && text.inset().forcePlainLayout());
@@ -882,7 +898,7 @@ void TeXOnePar(Buffer const & buf,
                        }
                        // With CJK, the CJK tag has to be closed first (see below)
                        if (runparams.encoding->package() != Encoding::CJK
-                           && par_lang != openLanguageName(state)
+                           && (par_lang != openLanguageName(state) || localswitch)
                            && !par_lang.empty()) {
                                string bc = use_polyglossia ?
                                          getPolyglossiaBegin(lang_begin_command, par_lang, par_language->polyglossiaOpts())
@@ -967,19 +983,34 @@ void TeXOnePar(Buffer const & buf,
                        os << "\n\\appendix\n";
                }
 
-               if (!par.params().spacing().isDefault()
-                       && (pit == 0 || !priorpar->hasSameLayout(par)))
-               {
-                       os << from_ascii(par.params().spacing().writeEnvirBegin(useSetSpace))
-                           << '\n';
-               }
+               // InTitle commands must use switches (not environments)
+               // inside the commands (see #9332)
+               if (style.intitle) {
+                       if (!par.params().spacing().isDefault())
+                       {
+                               if (runparams.moving_arg)
+                                       os << "\\protect";
+                               os << from_ascii(par.params().spacing().writeCmd(useSetSpace));
+                       }
+               } else {
+                       if (!par.params().spacing().isDefault()
+                               && (pit == 0 || !priorpar->hasSameLayout(par)))
+                       {
+                               os << from_ascii(par.params().spacing().writeEnvirBegin(useSetSpace))
+                                   << '\n';
+                       }
 
-               if (style.isCommand()) {
-                       os << '\n';
+                       if (style.isCommand()) {
+                               os << '\n';
+                       }
                }
        }
 
-       parStartCommand(par, os, runparams, style);
+       // For InTitle commands, we already started the command before
+       // the language switch
+       if (!intitle_command)
+               parStartCommand(par, os, runparams, style);
+
        Font const outerfont = text.outerFont(pit);
 
        // FIXME UNICODE
@@ -992,13 +1023,16 @@ void TeXOnePar(Buffer const & buf,
 
        bool const is_command = style.isCommand();
 
-       if (is_command) {
-               os << '}';
-               if (!style.postcommandargs().empty())
-                       latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
-               if (runparams.encoding != prev_encoding) {
-                       runparams.encoding = prev_encoding;
-                       os << setEncoding(prev_encoding->iconvName());
+       // InTitle commands need to be closed after the language has been closed.
+       if (!intitle_command) {
+               if (is_command) {
+                       os << '}';
+                       if (!style.postcommandargs().empty())
+                               latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
+                       if (runparams.encoding != prev_encoding) {
+                               runparams.encoding = prev_encoding;
+                               os << setEncoding(prev_encoding->iconvName());
+                       }
                }
        }
 
@@ -1028,15 +1062,16 @@ void TeXOnePar(Buffer const & buf,
                        break;
                }
        }
-
-       // fall through possible
+       // possible
+       // fall through
        default:
-               // we don't need it for the last paragraph!!!
-               if (nextpar)
+               // we don't need it for the last paragraph and in InTitle commands!!!
+               if (nextpar && !intitle_command)
                        pending_newline = true;
        }
 
-       if (par.allowParagraphCustomization()) {
+       // InTitle commands use switches (not environments) for space settings
+       if (par.allowParagraphCustomization() && !style.intitle) {
                if (!par.params().spacing().isDefault()
                        && (runparams.isLastPar || !nextpar->hasSameLayout(par))) {
                        if (pending_newline)
@@ -1052,9 +1087,10 @@ void TeXOnePar(Buffer const & buf,
                }
        }
 
-       // Closing the language is needed for the last paragraph; it is also
-       // needed if we're within an \L or \R that we may have opened above (not
-       // necessarily in this paragraph) and are about to close.
+       // Closing the language is needed for the last paragraph in a given language
+       // as well as for any InTitleCommand (since these set the language locally);
+       // it is also needed if we're within an \L or \R that we may have opened above
+       // (not necessarily in this paragraph) and are about to close.
        bool closing_rtl_ltr_environment = !using_begin_end
                // not for ArabTeX
                && (par_language->lang() != "arabic_arabtex"
@@ -1066,7 +1102,8 @@ void TeXOnePar(Buffer const & buf,
                &&((nextpar && par_lang != nextpar_lang)
                   || (runparams.isLastPar && par_lang != outer_lang));
 
-       if (closing_rtl_ltr_environment
+       if ((intitle_command && using_begin_end)
+           || closing_rtl_ltr_environment
            || ((runparams.isLastPar || close_lang_switch)
                && (par_lang != outer_lang || (using_begin_end
                                                && style.isEnvironment()
@@ -1137,6 +1174,19 @@ void TeXOnePar(Buffer const & buf,
        if (closing_rtl_ltr_environment)
                os << "}";
 
+       // InTitle commands need to be closed after the language has been closed.
+       if (intitle_command) {
+               if (is_command) {
+                       os << '}';
+                       if (!style.postcommandargs().empty())
+                               latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
+                       if (runparams.encoding != prev_encoding) {
+                               runparams.encoding = prev_encoding;
+                               os << setEncoding(prev_encoding->iconvName());
+                       }
+               }
+       }
+
        bool const last_was_separator =
                par.size() > 0 && par.isEnvSeparator(par.size() - 1);