Hi!

Attached find a patch for bug 1820, which has resisted solution for a long time. After a lot of work done by others to tidy up the output_latex code in the past few months, the infrastructure was now in place so that finally we can provide a solution. It would be good if this could still make it in to 1.5.0, though I realize that this is deep inside the latex output, and therefore may be too risky at this point... :(

I suspect something similar should be done in TexEnvironment, though I haven't run into a case where it matters, yet, so I've left that alone for now.

This is still only a patch, not a true solution. It only works for one level (e.g., try inserting a comment inside the footnote, and trouble starts all over again...), but it's better than the current situation, I believe. The real solution requires some kind of stack (either implicit, through the calling stack, or explicit) for storing the encoding and/or language as we enter each new inset level.


Please try applying it and see that it doesn't break anything! Attached also is an example file which requires this patch, two other examples are attached in bugzilla (though I'm having trouble downloading attachments from bugzilla, at the moment, anyone know anything about this?)

Dov

Attachment: bug1820.lyx
Description: application/lyx

Index: src/output_latex.cpp
===================================================================
--- src/output_latex.cpp        (revision 19004)
+++ src/output_latex.cpp        (working copy)
@@ -259,14 +259,19 @@
        OutputParams runparams = runparams_in;
        runparams.moving_arg |= style->needprotect;
 
+       // The previous language is the language of the previous paragraph, 
+       // if it exists; if this is the first paragraph, the previous 
+       // language is the local language upon entering the inset, if it
+       // is set; otherwise, it's the document's language.
        Language const * const par_language = pit->getParLanguage(bparams);
        Language const * const doc_language = bparams.language;
-       Language const * const prev_par_language =
-               (pit != paragraphs.begin())
-               ? boost::prior(pit)->getParLanguage(bparams)
-               : doc_language;
+       Language const * const prev_language =
+               (pit != paragraphs.begin()) ?
+                       boost::prior(pit)->getParLanguage(bparams) :
+                               (runparams.local_font != 0) ?
+                                       runparams.local_font->language() : 
doc_language;
 
-       if (par_language->babel() != prev_par_language->babel()
+       if (par_language->babel() != prev_language->babel()
            // check if we already put language command in TeXEnvironment()
            && !(style->isEnvironment()
                 && (pit == paragraphs.begin() ||
@@ -275,12 +280,12 @@
                     || boost::prior(pit)->getDepth() < pit->getDepth())))
        {
                if (!lyxrc.language_command_end.empty() &&
-                   prev_par_language->babel() != doc_language->babel() &&
-                   !prev_par_language->babel().empty())
+                   prev_language->babel() != doc_language->babel() &&
+                   !prev_language->babel().empty())
                {
                        os << from_ascii(subst(lyxrc.language_command_end,
                                "$$lang",
-                               prev_par_language->babel()))
+                               prev_language->babel()))
                           << '\n';
                        texrow.newline();
                }
@@ -488,8 +493,21 @@
                os << '\n';
                texrow.newline();
        }
-       runparams_in.encoding = runparams.encoding;
 
+       // If this is the last paragraph, and a local_font was set upon entering
+       // the inset, the encoding should be set back to that local_font's 
+       // encoding. We don't use switchEncoding(), because no explicit encoding
+       // switch command is needed, since latex will automatically revert to it
+       // when this inset closes.
+       if (boost::next(pit) == paragraphs.end() && runparams_in.local_font != 
0) {
+               runparams_in.encoding = 
runparams_in.local_font->language()->encoding();
+               os << setEncoding(runparams_in.encoding->iconvName());
+       }
+       // Otherwise, the current encoding should be set for the next paragraph.
+       else
+               runparams_in.encoding = runparams.encoding;
+
+
        // we don't need it for the last paragraph!!!
        // Note from JMarc: we will re-add a \n explicitely in
        // TeXEnvironment, because it is needed in this case

Reply via email to