+ bool encoding_switched = false;
+ Encoding const * const save_enc = runparams.encoding;
+ // 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().encoding().package() == Encoding::japanese
+ && 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 =
+ (runparams.local_font != 0) ?
+ runparams.local_font->language()
+ : buffer().params().language;
+ // We try if there's a singlebyte encoding for the current
+ // language; if not, fall back to latin1.
+ Encoding const * const lstenc =
+ (outer_language->encoding()->hasFixedWidth()) ?
+ outer_language->encoding()
+ : encodings.fromLyXName("iso8859-1");
+ switchEncoding(os.os(), buffer().params(), runparams, *lstenc, true);
+ runparams.encoding = lstenc;
+ encoding_switched = true;
+ }
+