commit dd6340cfcca284074becccdf7fa2a23263ad0db6
Author: Juergen Spitzmueller <[email protected]>
Date: Tue Nov 17 10:28:10 2015 +0100
Do not switch listings to singlebyte encoding with pLateX/Japanese
Also improve Listings warning about uncodable characters
if the encoding has been switched by LyX.
Fixes: #8439
diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
index 566636d..ac31d28 100644
--- a/src/insets/InsetListings.cpp
+++ b/src/insets/InsetListings.cpp
@@ -122,13 +122,16 @@ void InsetListings::latex(otexstream & os, OutputParams
const & runparams) const
bool encoding_switched = false;
Encoding const * const save_enc = runparams.encoding;
-
- if (!runparams.isFullUnicode()
- && !runparams.encoding->hasFixedWidth()) {
- // We need to switch to a singlebyte encoding, since the
- // listings package cannot deal with multi-byte-encoded
- // glyphs (not needed with full-unicode aware backends
- // such as XeTeX).
+ // The listings package cannot deal with multi-byte-encoded
+ // glyphs, except if full-unicode aware backends
+ // such as XeTeX or LuaTeX are used, and with pLaTeX.
+ bool const multibyte_possible = runparams.isFullUnicode()
+ || (buffer().params().bufferFormat() == "platex"
+ && runparams.encoding->package() == Encoding::japanese);
+
+ if (!multibyte_possible && !runparams.encoding->hasFixedWidth()) {
+ // We need to switch to a singlebyte encoding, due to
+ // the restrictions of the listings package (see above).
// This needs to be consistent with
// LaTeXFeatures::getTClassI18nPreamble().
Language const * const outer_language =
@@ -242,10 +245,20 @@ void InsetListings::latex(otexstream & os, OutputParams
const & runparams) const
if (!uncodable.empty() && !runparams.silent) {
// issue a warning about omitted characters
// FIXME: should be passed to the error dialog
- frontend::Alert::warning(_("Uncodable characters in listings
inset"),
- bformat(_("The following characters in one of the
program listings are\n"
- "not representable in the current encoding
and have been omitted:\n%1$s."),
- uncodable));
+ if (!multibyte_possible && !runparams.encoding->hasFixedWidth())
+ frontend::Alert::warning(_("Uncodable characters in
listings inset"),
+ bformat(_("The following characters in one of
the program listings are\n"
+ "not representable in the current
encoding and have been omitted:\n%1$s.\n"
+ "This is due to a restriction of the
listings package, which does\n"
+ "not support your encoding '%2$s'.\n"
+ "Toggling 'Use non-TeX fonts' in
Document > Settings...\n"
+ "might help."),
+ uncodable, _(runparams.encoding->guiName())));
+ else
+ frontend::Alert::warning(_("Uncodable characters in
listings inset"),
+ bformat(_("The following characters in one of
the program listings are\n"
+ "not representable in the current
encoding and have been omitted:\n%1$s."),
+ uncodable));
}
}