On 2015-11-01, Guenter Milde wrote: > Dear Scott, > thanks for the patch.
I modified it to use UTF8 with XeTeX without the \inputencoding commands. A short test here showed that this helps with Umlauts or Cyrillic charactes in the PDF Info. Give it a try. Günter Exec: git 'diff' 2>&1 Dir: /usr/local/src/lyx diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 537178e..de39309 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -1577,7 +1577,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, } // handle inputenc etc. - writeEncodingPreamble(os, features); + bool const inputenc_loaded = writeEncodingPreamble(os, features); // includeonly if (!features.runparams().includeall && !included_children_.empty()) { @@ -1903,7 +1903,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, OutputParams tmp_params = features.runparams(); pdfoptions().writeLaTeX(tmp_params, os, - features.isProvided("hyperref")); + features.isProvided("hyperref"), inputenc_loaded); // set back for the rest lyxpreamble.clear(); // correctly break URLs with hyperref and dvi output @@ -2924,19 +2924,20 @@ docstring BufferParams::getGraphicsDriver(string const & package) const } -void BufferParams::writeEncodingPreamble(otexstream & os, +bool BufferParams::writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const { // "inputenc" package not required with non-TeX fonts. if (useNonTeXFonts) - return; + return false; // "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) - return; + return false; // For LuaTeX with TeX fonts, we can load // the "luainputenc" package with the specified encoding(s) (see below). + bool use_inputenc = features.isProvided("inputenc"); if (inputenc == "auto") { string const doc_encoding = language->encoding()->latexName(); @@ -2973,6 +2974,7 @@ void BufferParams::writeEncodingPreamble(otexstream & os, os << "]{luainputenc}\n"; else os << "]{inputenc}\n"; + use_inputenc = true; } if (package == Encoding::CJK || features.mustProvide("CJK")) { if (language->encoding()->name() == "utf8-cjk" @@ -2998,6 +3000,7 @@ void BufferParams::writeEncodingPreamble(otexstream & os, os << "]{luainputenc}\n"; else os << "]{inputenc}\n"; + use_inputenc = true; break; case Encoding::CJK: if (encoding().name() == "utf8-cjk" @@ -3017,6 +3020,7 @@ void BufferParams::writeEncodingPreamble(otexstream & os, os << "\\usepackage{CJK}\n"; } } + return use_inputenc; } diff --git a/src/BufferParams.h b/src/BufferParams.h index b5ab65e..e3ff4f1 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -412,7 +412,8 @@ public: /// return supported drivers for specific packages docstring getGraphicsDriver(std::string const & package) const; /// handle inputenc etc. - void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const; + /// return true if (lua)inputenc is written here or already provided + bool writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const; /// std::string const parseFontName(std::string const & name) const; /// set up the document fonts diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp index 6646888..b4e91df 100644 --- a/src/PDFOptions.cpp +++ b/src/PDFOptions.cpp @@ -90,7 +90,7 @@ void PDFOptions::writeFile(ostream & os) const void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os, - bool hyperref_already_provided) const + bool hyperref_already_provided, bool inputenc_loaded) const { // FIXME Unicode string opt; @@ -176,20 +176,21 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os, // hyperref expects LICR macros for non-ASCII chars. With Xe/LuaTeX utf-8 works, too. // Usually, "(lua)inputenc" converts the input to LICR. - // As hyperref provides good coverage for \inputencoding{utf8}, we can try - // this if the current input encoding does not support a character. - // FIXME: inputenc (part 1 of 2) - // Replace the "FullUnicode" check with - // check for loading of inputenc or luainputenc package - // (see BufferParams::writeEncodingPreamble and runparams.encoding->package()). - // Otherwise \inputencoding is not defined - // (e.g. if "latex-encoding" is set to "ascii"). - // Dont forget to keep the check below (part 2) in sync! - if (need_unicode && enc && enc->iconvName() != "UTF-8" - &&!runparams.isFullUnicode()) { - os << "\\inputencoding{utf8}\n" - << setEncoding("UTF-8"); - } + // As hyperref provides good coverage for \inputencoding{utf8}, + // we can try this if the current input encoding does not support + // a character and inputenc or luainputenc is loaded: + if (need_unicode && enc && enc->iconvName() != "UTF-8") { + if (inputenc_loaded) + os << "\\inputencoding{utf8}\n" + << setEncoding("UTF-8"); + else if (runparams.isFullUnicode() // XeTeX natively supports UTF-8 + )// FIXME: && inputencoding setting != ascii + os << setEncoding("UTF-8"); + // else + // FIXME: convert with lib/unicodesymbols or report an error! + // (cf. the check and report for unencodable character + // in the user preamble in BufferParams.cpp) + } // If hyperref is loaded by the document class, we output // \hypersetup \AtBeginDocument if hypersetup is not (yet) // defined. In this case, the class loads hyperref late @@ -204,11 +205,10 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os, << "\\fi\n"; } else os << from_utf8(opt); - // FIXME: inputenc (part 2 of 2) - if (need_unicode && enc && enc->iconvName() != "UTF-8" - &&!runparams.isFullUnicode()) { - os << setEncoding(enc->iconvName()) - << "\\inputencoding{" << from_ascii(enc->latexName()) << "}\n"; + if (need_unicode && enc && enc->iconvName() != "UTF-8") { + os << setEncoding(enc->iconvName()); + if (inputenc_loaded) + os << "\\inputencoding{" << from_ascii(enc->latexName()) << "}\n"; } } diff --git a/src/PDFOptions.h b/src/PDFOptions.h index d74caf4..70dddaf 100644 --- a/src/PDFOptions.h +++ b/src/PDFOptions.h @@ -37,7 +37,7 @@ public: void writeFile(std::ostream &) const; /// output to tex header void writeLaTeX(OutputParams &, otexstream &, - bool hyperref_already_provided) const; + bool hyperref_already_provided, bool inputenc_loaded) const; /// read tokens from lyx header std::string readToken(Lexer &lex, std::string const & token); /// set implicit settings for hyperref