On 2015-10-28, Scott Kostyshak wrote:
> On Wed, Oct 28, 2015 at 09:31:50AM +0000, Guenter Milde wrote:
>> On 2015-10-26, Guenter Milde wrote:
>> > On 2015-10-26, Scott Kostyshak wrote:
>> >> Has anything changed in the last couple of days?

>> I'l commit an updated FIXME.

> This does indeed sound tricky. Can you figure out the necessary items to
> condition on from BufferParams or is not everything stored in there?

It became a bit simpler after going through the alternatives:

In pseudo-code:

if (PDFinfo has unencodable characters):
  
  if (inputenc or luainputenc is loaded):
        os << "\\inputencoding{utf8}\n"
           << setEncoding("UTF-8");
  else if (Xe/LuaTeX) // support UTF-8 also without inputenc
        os << setEncoding("UTF-8");
  else
        convert with lib/unicodesymbols or report an error
     
Checking for availability of the \inputencoding command is nontrivial. 
I tried to get the relevant info from
BufferParams::writeEncodingPreamble
and put them in an expanded FIXME
(but did not test under which name they are available in PDFOptions.cpp).

Günter

Here is a patch:

Exec: git 'diff' 'PDFOptions.cpp' 2>&1
Dir: /usr/local/src/lyx/src/

diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp
index 6646888..729ee10 100644
--- a/src/PDFOptions.cpp
+++ b/src/PDFOptions.cpp
@@ -175,20 +175,25 @@ 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.
+       // 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");
+       if (need_unicode && enc && enc->iconvName() != "UTF-8") {
+         // FIXME check for loading of inputenc or luainputenc package
+         //       (See BufferParams::writeEncodingPreamble and 
runparams.encoding->package().)
+         //       Dont forget to keep the check for the re-set below in sync!
+         // if (encoding().package() == Encoding::inputenc
+         //       && inputencoding != "default" && inputencoding != "ascii"
+         //     && !encodings.empty() && !features.isRequired("japanese")
+         //    ) // inputenc or luainputenc package provided
+                       os << "\\inputencoding{utf8}\n"
+                          << setEncoding("UTF-8");
+         // else if (runparams.isFullUnicode()) // Xe/LuaTeX support UTF-8 
also without inputenc
+         //            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)
@@ -204,11 +209,18 @@ 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()) {
+       if (need_unicode && enc && enc->iconvName() != "UTF-8") {
+         // FIXME check for loading of inputenc or luainputenc package
+         //       (See BufferParams::writeEncodingPreamble and 
runparams.encoding->package().)
+         //       Dont forget to keep this check in sync with the check above!
+         // if (encoding().package() == Encoding::inputenc
+         //       && inputencoding != "default" && inputencoding != "ascii"
+         //     && !encodings.empty() && !features.isRequired("japanese")
+         //    ) // inputenc or luainputenc package provided
                os << setEncoding(enc->iconvName())
                   << "\\inputencoding{" << from_ascii(enc->latexName()) << 
"}\n";
+         // else if (runparams.isFullUnicode()) // Xe/LuaTeX, reset encoding
+         //    os << setEncoding(enc->iconvName());
        }
 }
 



Reply via email to