On 2015-11-11, Kornel Benko wrote: > Am Mittwoch, 11. November 2015 um 00:11:26, schrieb Günter Milde >> commit 9894e0be23dafe3ad195d483ed7a0dd44cabf847 >> Author: Günter Milde <mi...@lyx.org> >> Date: Wed Nov 11 00:10:06 2015 +0100
>> Fix 480937a103708a651/lyxgit. See also #9740. >> Actually, the changed tests were used to prevent overwriting the >> encoding changed in Buffer::writeLaTeX with a language-default >> encoding. This is still required for XeTeX with TeX-fonts unless a >> proper solution is found. >> Documents with more than one encoding and TeX-fonts fail with LuaTeX, >> as "luainputenc" can only handle one encoding. > Dear Günter, > after this commit there are 344 failing export tests (previously 132). > All of the new 212 failing are of type luatex + non tex font. > dvi3_systemF 104 > pdf5_systemF 108 This is bad news. But I have also good news: I found the reason // XeTeX/LuaTeX use only one encoding per document: // * with useNonTeXFonts: "utf8plain", // * with XeTeX and TeX fonts: "ascii" (inputenc fails), // * with LuaTeX and TeX fonts: only one encoding accepted by luainputenc. and I finally found a not-so-hackish solution: Instead of changing the encoding for and back, the patch below prevents encoding changes whenever the TeX engine is XeTeX or LuaTeX: +1 no needless encoding switches +1 runparams.encoding matches the correct encoding at any time +1 less complicated code As a bonus, LuaTeX & TeX fonts now also works for files with two or more languages with different encodings - with inputenc == "auto", the complete document is set to the encoding of the global document language. I hope this will cure the recent regression and solve some of the currently inverted or failing "Lua+TeXF" tests. Could you try the patch below? Günter Exec: git 'diff' 2>&1 Dir: /usr/local/src/lyx/src/ diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index c7ec167..dd75573 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -2941,15 +2941,13 @@ docstring BufferParams::getGraphicsDriver(string const & package) const void BufferParams::writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const { - // "inputenc" package not required with non-TeX fonts. - if (useNonTeXFonts) - return; - // "inputenc" fails with XeTeX (even in 8-bit compatiblitly mode) and with TeX fonts, - // (this is a bug in the "inputenc" package see #9740). - if (features.runparams().flavor == OutputParams::XETEX) + // XeTeX/LuaTeX: (see also #9740) + // With Unicode fonts we use utf8-plain without encoding package. + // With TeX fonts, we cannot use utf8-plain, but "inputenc" fails. + // XeTeX must use ASCII encoding, for LuaTeX, we load + // "luainputenc" (see below). + if (useNonTeXFonts || features.runparams().flavor == OutputParams::XETEX) return; - // For LuaTeX with TeX fonts, we can load - // the "luainputenc" package with the specified encoding(s) (see below). if (inputenc == "auto") { string const doc_encoding = @@ -2957,10 +2955,12 @@ void BufferParams::writeEncodingPreamble(otexstream & os, Encoding::Package const package = language->encoding()->package(); - // Create a list with all the input encodings used - // in the document - set<string> encodings = - features.getEncodingSet(doc_encoding); + // Create list of inputenc options: + set<string> encodings; + // luainputenc fails with more than one encoding (see also ...) + if (!features.runparams().isFullUnicode()) // if we reach this point, this means LuaTeX with TeX fonts + // list all input encodings used in the document + encodings = features.getEncodingSet(doc_encoding); // If the "japanese" package (i.e. pLaTeX) is used, // inputenc must be omitted. diff --git a/src/Font.cpp b/src/Font.cpp index f0814a3..70bc255 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -327,6 +327,7 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, } } + // FIXME: skip this for XeTeX/LuaTeX? With nonTeXfonts or always? if (language()->encoding()->package() == Encoding::CJK) { pair<bool, int> const c = switchEncoding(os, bparams, runparams, *(language()->encoding())); diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 2d33918..ae2e6de 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2567,8 +2567,7 @@ void Paragraph::latex(BufferParams const & bparams, if (allowcust && d->endTeXParParams(bparams, os, runparams) && runparams.encoding != prev_encoding) { runparams.encoding = prev_encoding; - if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding - os << setEncoding(prev_encoding->iconvName()); + os << setEncoding(prev_encoding->iconvName()); } LYXERR(Debug::LATEX, "Paragraph::latex... done " << this); diff --git a/src/output_latex.cpp b/src/output_latex.cpp index db6b890..c158205 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -249,8 +249,7 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams, state->prev_env_language_ = data.par_language; if (runparams.encoding != data.prev_encoding) { runparams.encoding = data.prev_encoding; - if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding - os << setEncoding(data.prev_encoding->iconvName()); + os << setEncoding(data.prev_encoding->iconvName()); } } @@ -259,8 +258,7 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams, state->prev_env_language_ = data.par_language; if (runparams.encoding != data.prev_encoding) { runparams.encoding = data.prev_encoding; - if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding - os << setEncoding(data.prev_encoding->iconvName()); + os << setEncoding(data.prev_encoding->iconvName()); } } @@ -772,6 +770,7 @@ void TeXOnePar(Buffer const & buf, // encoding, since this only affects the position of the outputted // \inputencoding command; the encoding switch will occur when necessary if (bparams.inputenc == "auto" + && !runparams.isFullUnicode() // Xe/LuaTeX use one document-wide encoding && runparams.encoding->package() != Encoding::none) { // Look ahead for future encoding changes. // We try to output them at the beginning of the paragraph, @@ -884,8 +883,7 @@ void TeXOnePar(Buffer const & buf, latexArgInsets(par, os, runparams, style.postcommandargs(), "post:"); if (runparams.encoding != prev_encoding) { runparams.encoding = prev_encoding; - if (runparams.flavor != OutputParams::XETEX) // see BufferParams::encoding - os << setEncoding(prev_encoding->iconvName()); + os << setEncoding(prev_encoding->iconvName()); } } @@ -1043,13 +1041,13 @@ void TeXOnePar(Buffer const & buf, } // If this is the last paragraph, and a local_font was set upon entering - // the inset, and we're using "auto" or "default" encoding, the encoding + // the inset, and we're using "auto" or "default" encoding, and not + // compiling with XeTeX or LuaTeX, the encoding // should be set back to that local_font's encoding. - // However, do not change the encoding when non-TeX fonts are used. if (runparams.isLastPar && runparams_in.local_font != 0 && runparams_in.encoding != runparams_in.local_font->language()->encoding() && (bparams.inputenc == "auto" || bparams.inputenc == "default") - && runparams.flavor != OutputParams::XETEX // see BufferParams::encoding + && !runparams.isFullUnicode() ) { runparams_in.encoding = runparams_in.local_font->language()->encoding(); os << setEncoding(runparams_in.encoding->iconvName()); @@ -1288,6 +1286,13 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams, OutputParams const & runparams, Encoding const & newEnc, bool force) { + // XeTeX/LuaTeX use only one encoding per document: + // * with useNonTeXFonts: "utf8plain", + // * with XeTeX and TeX fonts: "ascii" (inputenc fails), + // * with LuaTeX and TeX fonts: only one encoding accepted by luainputenc. + if (runparams.isFullUnicode()) + return make_pair(false, 0); + Encoding const & oldEnc = *runparams.encoding; bool moving_arg = runparams.moving_arg; // If we switch from/to CJK, we need to switch anyway, despite custom inputenc