Group the switch of encoding for listings in utf8 documents

Else, \cprotect'ed documents fail.
This commit is contained in:
Juergen Spitzmueller 2018-05-01 14:21:05 +02:00
parent efd29cc200
commit 2009469219
3 changed files with 11 additions and 6 deletions

View File

@ -120,7 +120,7 @@ void InsetListings::read(Lexer & lex)
Encoding const * InsetListings::forcedEncoding(Encoding const * inner_enc,
Encoding const * outer_enc) const
Encoding const * outer_enc) const
{
// The listings package cannot deal with multi-byte-encoded
// glyphs, except if full-unicode aware backends
@ -192,6 +192,9 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
// the restrictions of the listings package (see above).
// This needs to be consistent with
// LaTeXFeatures::getTClassI18nPreamble().
// We need to put this into a group in order to prevent encoding leaks
// (happens with cprotect).
os << "\\bgroup";
switchEncoding(os.os(), buffer().params(), runparams, *fixedlstenc, true);
runparams.encoding = fixedlstenc;
encoding_switched = true;
@ -332,12 +335,14 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
}
os << from_utf8(param_string) << "]\n";
}
os << code << breakln << "\\end{lstlisting}\n";
os << code << "\\end{lstlisting}\n";
}
if (encoding_switched){
// Switch back
switchEncoding(os.os(), buffer().params(), runparams, *save_enc, true);
switchEncoding(os.os(), buffer().params(),
runparams, *save_enc, true, true);
os << "\\egroup" << breakln;
runparams.encoding = save_enc;
}

View File

@ -1543,7 +1543,7 @@ void latexParagraphs(Buffer const & buf,
pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
OutputParams const & runparams, Encoding const & newEnc,
bool force)
bool force, bool noswitchmacro)
{
// XeTeX/LuaTeX use only one encoding per document:
// * with useNonTeXFonts: "utf8plain",
@ -1612,7 +1612,7 @@ pair<bool, int> switchEncoding(odocstream & os, BufferParams const & bparams,
state->open_encoding_ = inputenc;
}
// with the japanese option, inputenc is omitted.
if (runparams.use_japanese)
if (runparams.use_japanese || noswitchmacro)
return make_pair(true, count);
os << "\\inputencoding{" << inputenc_arg << '}';
return make_pair(true, count + 16);

View File

@ -82,7 +82,7 @@ void latexParagraphs(Buffer const & buf,
std::pair<bool, int> switchEncoding(odocstream & os,
BufferParams const & bparams,
OutputParams const &, Encoding const & newEnc,
bool force = false);
bool force = false, bool noswitchmacro = false);
/// FIXME: this should not be visible.
void TeXOnePar(Buffer const & buf,