Enrico Forestieri wrote:
Dov,
Hi Enrico! Thanks for taking a look at this... :)
this is what I did. Without your patch applied, I started a new document, so the language is english, and then activated "View Source". I wrote "bla bla bla ", then switched the language to italian and wrote "BLA BLA BLA". Now I inserted a footnote and wrote "bla bla bla". At this point, this is what I saw in the "LaTeX Source" window: (Point 1a) bla bla bla \foreignlanguage{italian}{BLA BLA BLA}% \footnote{\selectlanguage{italian} bla bla bla\selectlanguage{english} % } Now I pressed backspace until I deleted the last "bla bla bla" I wrote. The following is what the "LaTeX Source" window was showing at this point: (Point 2a) bla bla bla \foreignlanguage{italian}{BLA BLA BLA}% \footnote{% } Writing again "bla bla bla", I got: (Point 3a) bla bla bla \foreignlanguage{italian}{BLA BLA BLA}% \footnote{bla bla bla% } which lacks the \selectlanguage commands, meaning that I obtain different results after backspacing and writing again!
I think this is purely a GUI issue, and has got to do with the current_font stuff. I believe that the second time around, the language you are typing in is Italian, not English. You can make sure by turning on the "mark foreign language" preference. (I realize now that I have the advantage of working with Hebrew and English, which use totally different alphabets; so I very easily can tell when I'm in which language...).
Now I applied your patch and repeated the previous steps. The results I was getting at the same points as before, are the following: (Point 1b) bla bla bla \foreignlanguage{italian}{BLA BLA BLA}% \footnote{bla bla bla\selectlanguage{english} % } Note that a \selectlanguage{italian} is missing here wrt Point 1a.
Right. It is not needed, because latex will "remember" the current language inside the footnote --- you're already in Italian. (Again, working with Hebrew has the advantage that if I'm typing one language when latex thinks it's the other, it just won't compile...).
(Point 2b) bla bla bla \foreignlanguage{italian}{BLA BLA BLA}% \footnote{\selectlanguage{english} % } Note that a \selectlanguage{english} is still here wrt Point 2a.
This is also correct, and is exactly the flip side of what you saw earlier: since the GUI is updating the language after having deleted everything, so you are now "in english". In order for latex to register that, you need the selectlanguage command, and that's why it's there.
(Point 3b) bla bla bla \foreignlanguage{italian}{BLA BLA BLA}% \footnote{\selectlanguage{english} bla bla bla% } Note that what I wrote now was coming after \selectlanguage{english} I think that now I am more confused than you... Without your patch, LyX seems correctly translating to LaTeX after backspacing and writing again in the footnote, as the text in the foreign language is the argument of \foreignlanguage, so it should not apply to the footnote. With your patch applied, there's only a \selectlanguage{english} in the footnote, so it should always be correct without the need of backspacing. Anyway, with or without your patch I am concerned about obtaining different results after simply backspacing and writing again in the footnote.
To sum up: we have to separate between the GUI's behavior and the backend. The GUI is doing funny stuff, and that's what's causing the differences that you are seeing when backspacing. What's important, though, is that the backend generate latex which matches the state of the buffer, which it currently is not, and that's what my patch attempts to achieve.
Again, I only now realize why this hasn't been taken care of before: for most European languages, the "language" doesn't really matter that much, because the encodings and alphabets are more or less the same; so even if the language is incorrect, you may not notice... With Hebrew, this is not the case: as sson as there's a mismatch, I see trouble...
Regarding the state of my patch: I'm realizing that I can't separate the two parts. If the patch doesn't do everything correctly, there are regressions relative to the current behavior with some cases, while other cases are fixed by the patch. So I've almost got a working patch which seems to pass all of my tests. But, it's not simple... And I shudder to think of making a lyx2lyx for it.
I'll send in the patch, as well as the example files I'm working with, soon...
Dov