OK, here's my original patch for bug 1820 (without the second part, identical to what I originally sent in). It solves most cases, as far as I can determine is safe (I tried it on my documents with complex bidi / encoding / language transitions), and it does not constitute a format change, IMO.

If possible, it would be nice if this could go in to 1.5.0, preferably after some other developers test it (no real active testing needed --- just apply and make sure it doesn't break anything, specifically in terms of language / encoding transitions). If not, I guess it's not the end of the world, because since it doesn't constitute a format change, we can apply it in 1.5.1.

Regarding the remaining test case which this doesn't solve: it's really part of a separate problem, that of *nested* language transitions. I'm still working on it, I'm close to some sort of patch, I hope to send it in soon. However, this part *is* a format change, so an accompanying lyx2lyx would be necessary, and I haven't gotten to that yet. So if I am able to get this all in on-time, great. But don't hold up the release for this --- at the worst, I have a workaround for this test case using ERT...

Finally, there's the issue of bug 3613. It is due to some format change from long ago which never had an accompanying lyx2lyx made for it (I have nothing to do with that... ;) ). If possible, we should fix this (i.e., create a lyx2lyx fix) before 1.5.0. I can provide more details if necessary, if anyone thinks they can help...

Thanks!
Dov

have a patch for that in the works, which I just want to touch up, and hopefully send in later tonight
Index: src/output_latex.cpp
===================================================================
--- src/output_latex.cpp        (revision 19062)
+++ 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