Dear Scott,

thanks for the patch.

On 2015-10-31, Scott Kostyshak wrote:
> On Sat, Oct 31, 2015 at 05:57:46PM -0400, Scott Kostyshak wrote:
>> On Sat, Oct 31, 2015 at 09:21:15PM +0000, Guenter Milde wrote:

> Does the attached patch look good?

It looks like a step in the right direction. However, this is just a
prerequisite for solving the encoding problems, not the fix yet.

Therefore, it is to be expected that this patch does not cure any of the
export tests (they just fail for another reason).

> We need to do something similar for the other FIXMEs you put in
> 1523fc60, right?

This depends on what you mean with "similar". AFAIK, the problem there is
not about PDFstrings and hence the solution also different.

> Scott

> [-- Type: text/plain, Encoding: , Filename: 
> 0001-Improve-XeTeX-LuaTeX-with-TeX-fonts-9740.patch --]

> From ef7d21fc35679683f537c186ce9200cba232a8b3 Mon Sep 17 00:00:00 2001
> From: Scott Kostyshak <skost...@lyx.org>
> Date: Sat, 31 Oct 2015 18:59:23 -0400
> Subject: [PATCH] Improve XeTeX/LuaTeX with TeX fonts, #9740

This is not about XeTex/LuaTeX with TeX fonts:

The problem fixed is "ensure \inputencoding is defined before using it in
the document preamble".

Conditions where this applies are "inputencoding ascii", "inputencoding
(default without inputenc)" and "cjk without utf8" and a non-encodable
character in the PDF info (most of them are currently not tested).

* As XeTeX with TeX fonts requires "inputencoding ascii", it is
  affected indirectly. 

* LuaTeX works fine (as it loads luainputenc which defines \inputencoding).


> More fixes are needed to solve the FIXMEs in 1523fc60.

More fixes are needed to solve the errors with non-encodable characters in
the PDF info fields.

> --- a/src/BufferParams.cpp
> +++ b/src/BufferParams.cpp
> @@ -1577,7 +1577,8 @@ bool BufferParams::writeLaTeX(otexstream & os, 
> LaTeXFeatures & features,
>       }

>       // handle inputenc etc.
> -     writeEncodingPreamble(os, features);
> +     bool const ie = writeEncodingPreamble(os, features);
> +     bool const inputenc_loaded = ie || features.isProvided("inputenc");

As features.isProvided("inputenc") is also tested in writeEncodingPreamble,
we could move this test there and write here simply:

        bool const inputenc_loaded = writeEncodingPreamble(os, features);


> -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 ret = false;

Why not 

        bool inputenc_provided = features.isProvided("inputenc");

>       if (inputenc == "auto") {
>               string const doc_encoding =
>                       language->encoding()->latexName();
> @@ -2955,6 +2957,7 @@ void BufferParams::writeEncodingPreamble(otexstream & 
> os,
>                   && !features.isRequired("japanese")
>                   && !features.isProvided("inputenc")) {
>                       os << "\\usepackage[";
> +                     ret = true;
>                       set<string>::const_iterator it = encodings.begin();
>                       set<string>::const_iterator const end = encodings.end();
>                       if (it != end) {

Place the "ret = ..." line rather below the complete loading command, not
inbetween.

> @@ -2993,6 +2996,7 @@ void BufferParams::writeEncodingPreamble(otexstream & 
> os,
>                           || features.isProvided("inputenc"))
>                               break;
>                       os << "\\usepackage[" << 
> from_ascii(encoding().latexName());
> +                     ret = true;
>                       if (features.runparams().flavor == OutputParams::LUATEX
>                           || features.runparams().flavor == 
> OutputParams::DVILUATEX)
>                               os << "]{luainputenc}\n";
> @@ -3017,6 +3021,7 @@ void BufferParams::writeEncodingPreamble(otexstream & 
> os,
>                               os << "\\usepackage{CJK}\n";
>               }
>       }
> +     return ret;
>  }

...


>  void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os,
> -                         bool hyperref_already_provided) const
> +                         bool hyperref_already_provided, bool 
> inputenc_loaded) const
>  {
>       // FIXME Unicode
>       string opt;
> @@ -178,15 +178,12 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, 
> otexstream & os,
>       // 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

        // and the inputenc package is loaded.
        
> -     // 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!

We need to switch the Encoding
(but not write the \\inputencoding line) with XeTeX.

        if (need_unicode && enc && enc->iconvName() != "UTF-8") {
          if (inputenc_loaded)
                os << "\\inputencoding{utf8}\n"
                   << setEncoding("UTF-8");
          else if (runparams.isFullUnicode()) // Xe/LuaTeX support UTF-8 
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)
        }
        
> @@ -204,9 +201,8 @@ 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") {
> +       if (inputenc_loaded) 
                os << setEncoding(enc->iconvName())
                   << "\\inputencoding{" << from_ascii(enc->latexName()) << 
"}\n";
          else if (runparams.isFullUnicode()) // Xe/LuaTeX, reset encoding
                os << setEncoding(enc->iconvName());
        }
        

I hope you get the idea.

Thanks again,

Günter

Reply via email to