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.
void BufferParams::writeEncodingPreamble(otexstream & os,
LaTeXFeatures & features) 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)
- // 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 =
if (inputenc == "auto") {
string const doc_encoding =
Encoding::Package const package =
language->encoding()->package();
Encoding::Package const package =
language->encoding()->package();
- // Create a list with all the input encodings used
- // in the document
- set<string> encodings =
- features.getEncodingSet(doc_encoding);
+ // Create list of inputenc options:
+ set<string> 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.
// If the "japanese" package (i.e. pLaTeX) is used,
// inputenc must be omitted.
+ // FIXME: skip this for XeTeX/LuaTeX? With nonTeXfonts or always?
if (language()->encoding()->package() == Encoding::CJK) {
pair<bool, int> const c = switchEncoding(os, bparams,
runparams, *(language()->encoding()));
if (language()->encoding()->package() == Encoding::CJK) {
pair<bool, int> const c = switchEncoding(os, bparams,
runparams, *(language()->encoding()));
void LaTeXFeatures::getFontEncodings(vector<string> & encodings) const
{
void LaTeXFeatures::getFontEncodings(vector<string> & 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"))
if (mustProvide("textgreek"))
encodings.insert(encodings.begin(), "LGR");
if (mustProvide("textcyr"))
if (allowcust && d->endTeXParParams(bparams, os, runparams)
&& runparams.encoding != prev_encoding) {
runparams.encoding = prev_encoding;
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);
}
LYXERR(Debug::LATEX, "Paragraph::latex... done " << this);
state->prev_env_language_ = data.par_language;
if (runparams.encoding != data.prev_encoding) {
runparams.encoding = data.prev_encoding;
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());
state->prev_env_language_ = data.par_language;
if (runparams.encoding != data.prev_encoding) {
runparams.encoding = data.prev_encoding;
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());
// encoding, since this only affects the position of the outputted
// \inputencoding command; the encoding switch will occur when necessary
if (bparams.inputenc == "auto"
// 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,
&& runparams.encoding->package() != Encoding::none) {
// Look ahead for future encoding changes.
// We try to output them at the beginning of the paragraph,
latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
if (runparams.encoding != prev_encoding) {
runparams.encoding = prev_encoding;
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());
}
// If this is the last paragraph, and a local_font was set upon entering
}
// 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.
// 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")
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());
) {
runparams_in.encoding = runparams_in.local_font->language()->encoding();
os << setEncoding(runparams_in.encoding->iconvName());
OutputParams const & runparams, Encoding const & newEnc,
bool force)
{
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
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