On 2015-11-05, Kornel Benko wrote: > Am Mittwoch, 4. November 2015 um 22:02:52, schrieb Guenter Milde > <mi...@users.sf.net>
>> the patch below solves some of the unresolved FIXMES in the >> "Partial fix for #9740 "XeTeX/LuaTeX with TeX fonts problems" >> 1523fc6023440f10ca0/lyxgit >> Testing shows, that this improves LuaTeX export with the minimal example of >> ticket #6216 that triggered the code containing the FIXMES: >> http://www.lyx.org/trac/raw-attachment/ticket/6216/6216.lyx Actually, the problem is deeper: the attached test document shows that there are still problems: * with the current state, XeTeX export works but LuaTeX export fails. * with the patch, LuaTeX works but XeTeX fails. Conditions triggering the problem: * TeX fonts * "LaTeX encoding" set to "language default". * an active inset (footnote, margin note, table, box, comment). * non-ASCII characters in the document part following the inset. Result: Error when exporting, compilation error (missing character), or wrong character in the output. Hypothesis ========== Language changes may change a re-set of the active encoding. If the language change is limited to the inset, there is no need to re-set the language in LaTeX. However, the encoding must be reset in LyX. This is done in Paragraph.cpp and output_latex.cpp for various insets/environments based on a stored "prev_encoding". prev_encoding is set to the value of a call to BufferParams::encoding() The preceding test for Xe/LuaTeX is just to speed up: with nonTeX fonts, the encoding of the complete document is utf8-plain. (A better speed-up possibility would be to check for a document-wide encoding (any inputencoding setting other than "auto" or "default").) The current implementation gets this wrong - testing for the flavor, not the use TeX fonts. This fails with LuaTeX + TeX-fonts + "auto" encoding and is fixed with - if (!runparams.isFullUnicode()) // FIXME: test for UseTeXFonts + if (!bparams.useNonTeXFonts) os << setEncoding(prev_encoding->iconvName()); XeTeX with TeX-fonts uses a document-wide encoding (ASCII) and hence works fine without the patch. Why does it fail after patching? The export target is not a buffer parameter but only known at runtime. Export with XeTeX and TeX-fonts requires ASCII encoding, but in BufferParams::encoding(), the runparams are not known. The setting of ASCII encoding is currently postponed to Buffer::makeLaTeXFile (for export) and Buffer::writeLaTeXSource (for preview). (see the FIXME there and #9740). However, BufferParams::encoding() returns the wrong value for export with XeTeX and TeX-fonts when called to set the prev_encoding. Possible ways out: 1. test for both, nonTeXFonts and XeTeX at the 5 places currently testing ifFullUnicode: + if (!bparams.useNonTeXFonts + && runparams().flavor != OutputParams::XETEX) +1 simple -1 hackish (not fixing the problem but the symptom: BufferParams::encoding() still returns the wrong encoding 2. fix BufferParams::encoding() pass "LaTeXFeatures & features" as argument and test for "features.runparams().flavor == OutputParams::XETEX" (cf. BufferParams::writeEncodingPreamble(). Alternatively, pass and use just "runparams". +1 solves the FIXME +1 logic at one place +1 calling BufferParams::encoding() returns the correct encoding +1 remove hack and FIXME from Buffer.cpp (2 instances). -3 all calls must be changed to hand over an instance of "LaTeXFeatures" or "runparams". I need both, advise on which way to go and a helping hand with the actual implementation. > Next 12 tests with changed outcome :) How many reversions? (or is XeTeX+Tex-fonts export now suspended) Günter