Partial fix for #9740 "XeTeX/LuaTeX with TeX fonts problems".

Fixes output for 3 of the 4 test lyx-files.

Includes "FIXME"s at places where further action is required to get the XeTeX
export right but I don't know how.
This commit is contained in:
Günter Milde 2015-10-20 19:14:39 +02:00
parent 9d7c3a4876
commit 1523fc6023
5 changed files with 40 additions and 37 deletions

View File

@ -1586,10 +1586,10 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
{
OutputParams runparams = runparams_in;
// This is necessary for LuaTeX/XeTeX with tex fonts.
// See FIXME in BufferParams::encoding()
if (runparams.isFullUnicode())
runparams.encoding = encodings.fromLyXName("utf8-plain");
// XeTeX with TeX fonts is only safe with ASCII encoding,
// See #9740 and FIXME in BufferParams::encoding()
if (params().useNonTeXFonts && (runparams.flavor == OutputParams::XETEX))
runparams.encoding = encodings.fromLyXName("ascii");
string const encoding = runparams.encoding->iconvName();
LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << ", fname=" << fname.realPath());
@ -1673,10 +1673,10 @@ void Buffer::writeLaTeXSource(otexstream & os,
OutputParams runparams = runparams_in;
// This is necessary for LuaTeX/XeTeX with tex fonts.
// See FIXME in BufferParams::encoding()
if (runparams.isFullUnicode())
runparams.encoding = encodings.fromLyXName("utf8-plain");
// XeTeX with TeX fonts is only safe with ASCII encoding,
// See #9740 and FIXME in BufferParams::encoding()
if (params().useNonTeXFonts && (runparams.flavor == OutputParams::XETEX))
runparams.encoding = encodings.fromLyXName("ascii");
// If we are compiling a file standalone, even if this is the
// child of some other buffer, let's cut the link here, so the

View File

@ -2307,7 +2307,7 @@ string BufferParams::bufferFormat() const
string format = documentClass().outputFormat();
if (format == "latex") {
if (useNonTeXFonts)
return "xetex";
return "xetex"; // FIXME: why not "luatex"?
if (encoding().package() == Encoding::japanese)
return "platex";
}
@ -2927,20 +2927,16 @@ docstring BufferParams::getGraphicsDriver(string const & package) const
void BufferParams::writeEncodingPreamble(otexstream & os,
LaTeXFeatures & features) const
{
// XeTeX does not need this
// "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)
return;
// LuaTeX neither, but with tex fonts, we need to load
// the luainputenc package.
if (features.runparams().flavor == OutputParams::LUATEX
|| features.runparams().flavor == OutputParams::DVILUATEX) {
if (!useNonTeXFonts && inputenc != "default"
&& ((inputenc == "auto" && language->encoding()->package() == Encoding::inputenc)
|| (inputenc != "auto" && encoding().package() == Encoding::inputenc))) {
os << "\\usepackage[utf8]{luainputenc}\n";
}
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 =
language->encoding()->latexName();
@ -2972,7 +2968,11 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
os << ',';
os << from_ascii(doc_encoding);
}
os << "]{inputenc}\n";
if (features.runparams().flavor == OutputParams::LUATEX
|| features.runparams().flavor == OutputParams::DVILUATEX)
os << "]{luainputenc}\n";
else
os << "]{inputenc}\n";
}
if (package == Encoding::CJK || features.mustProvide("CJK")) {
if (language->encoding()->name() == "utf8-cjk"
@ -2992,8 +2992,12 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
if (features.isRequired("japanese")
|| features.isProvided("inputenc"))
break;
os << "\\usepackage[" << from_ascii(encoding().latexName())
<< "]{inputenc}\n";
os << "\\usepackage[" << from_ascii(encoding().latexName());
if (features.runparams().flavor == OutputParams::LUATEX
|| features.runparams().flavor == OutputParams::DVILUATEX)
os << "]{luainputenc}\n";
else
os << "]{inputenc}\n";
break;
case Encoding::CJK:
if (encoding().name() == "utf8-cjk"
@ -3123,10 +3127,10 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
Encoding const & BufferParams::encoding() const
{
// FIXME: actually, we should check for the flavor
// or runparams.isFullyUnicode() here:
// This check will not work with XeTeX/LuaTeX and tex fonts.
// Thus we have to reset the encoding in Buffer::makeLaTeXFile
// FIXME: additionally, we must check for runparams().flavor == XeTeX
// or runparams.isFullUnicode() to care for the combination
// of XeTeX and TeX-fonts (see #9740).
// Currently, we reset the encoding in Buffer::makeLaTeXFile
// (for export) and Buffer::writeLaTeXSource (for preview).
if (useNonTeXFonts)
return *(encodings.fromLyXName("utf8-plain"));

View File

@ -176,7 +176,7 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os,
// hyperref expects utf8!
if (need_unicode && enc && enc->iconvName() != "UTF-8"
&&!runparams.isFullUnicode()) {
&&!runparams.isFullUnicode()) { // FIXME: check must be done for useNonTeXFonts!
os << "\\inputencoding{utf8}\n"
<< setEncoding("UTF-8");
}
@ -196,7 +196,7 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os,
os << from_utf8(opt);
if (need_unicode && enc && enc->iconvName() != "UTF-8"
&&!runparams.isFullUnicode()) {
&&!runparams.isFullUnicode()) { // FIXME: check for useNonTeXFonts!
os << setEncoding(enc->iconvName())
<< "\\inputencoding{" << from_ascii(enc->latexName()) << "}\n";
}

View File

@ -2567,7 +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.isFullUnicode())
if (!runparams.isFullUnicode()) // FIXME: test for UseTeXFonts
os << setEncoding(prev_encoding->iconvName());
}

View File

@ -248,7 +248,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.isFullUnicode())
if (!runparams.isFullUnicode()) // FIXME: test for UseTeXFonts
os << setEncoding(data.prev_encoding->iconvName());
}
}
@ -258,7 +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.isFullUnicode())
if (!runparams.isFullUnicode()) // FIXME: test for UseTeXFonts
os << setEncoding(data.prev_encoding->iconvName());
}
}
@ -878,7 +878,7 @@ void TeXOnePar(Buffer const & buf,
latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
if (runparams.encoding != prev_encoding) {
runparams.encoding = prev_encoding;
if (!runparams.isFullUnicode())
if (!runparams.isFullUnicode()) // FIXME: test for UseTeXFonts
os << setEncoding(prev_encoding->iconvName());
}
}
@ -1040,12 +1040,11 @@ 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
// should be set back to that local_font's encoding.
// However, do not change the encoding when a fully unicode aware backend
// such as XeTeX is used.
// 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.isFullUnicode())) {
&& (!runparams.isFullUnicode())) { // FIXME: test for UseTeXFonts
runparams_in.encoding = runparams_in.local_font->language()->encoding();
os << setEncoding(runparams_in.encoding->iconvName());
}