From 0eb9477be7998f8d66b4fe5c8948de5a22261e1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnter=20Milde?= Date: Thu, 12 Nov 2015 16:55:04 +0100 Subject: [PATCH] Fix 480937a103708a651/lyxgit, second attempt. Prevent encoding changes whenever the TeX engine is XeTeX or LuaTeX, as 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. +1 no needless encoding switches +1 runparams.encoding matches the correct encoding at any time +1 less complicated code. -1 there may still be problems with CJK (possibly impossible to solve for Xe/LuaTeX with TeX fonts). For LuaTeX & TeX fonts, the complete document uses the encoding of the global document language. See also #9740. --- src/BufferParams.cpp | 24 ++++++++++++------------ src/Font.cpp | 1 + src/LaTeXFeatures.cpp | 5 +++-- src/Paragraph.cpp | 3 +-- src/output_latex.cpp | 23 ++++++++++++++--------- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index c7ec167709..fa2f97bb87 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 encodings = - features.getEncodingSet(doc_encoding); + // Create list of inputenc options: + set encodings; + // luainputenc fails with more than one encoding + 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 f0814a3a3e..70bc25578b 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 const c = switchEncoding(os, bparams, runparams, *(language()->encoding())); diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 5405ce0faf..feab837699 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -711,8 +711,9 @@ set LaTeXFeatures::getEncodingSet(string const & doc_encoding) const void LaTeXFeatures::getFontEncodings(vector & encodings) const { - // these must be loaded if glyphs of this script - // are used (notwithstanding the language) + // these must be loaded if glyphs of this script are used + // unless a language providing them is used in the document + // FIXME: currently the option is written twice in this case if (mustProvide("textgreek")) encodings.insert(encodings.begin(), "LGR"); if (mustProvide("textcyr")) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 2d3391885d..ae2e6def1f 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 db6b890f14..ee6fc31320 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 (see also switchEncoding()) && 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 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 -- 2.39.2