Inset::DisplayType InsetListings::display() const
{
- return params().isInline() || params().isFloat() ? Inline : AlignLeft;
+ return params().isInline() || params().isFloat() ? Inline : Display | AlignLeft;
}
}
+Encoding const * InsetListings::forcedEncoding(Encoding const * inner_enc,
+ Encoding const * outer_enc) const
+{
+ // 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.
+ // Minted can deal with all encodings.
+ if (buffer().params().use_minted
+ || inner_enc->name() == "utf8-plain"
+ || (buffer().params().encoding().package() == Encoding::japanese
+ && inner_enc->package() == Encoding::japanese)
+ || inner_enc->hasFixedWidth())
+ return 0;
+
+ // We try if there's a singlebyte encoding for the outer
+ // language; if not, fall back to latin1.
+ return (outer_enc->hasFixedWidth()) ?
+ outer_enc : encodings.fromLyXName("iso8859-1");
+}
+
+
void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
{
string param_string = params().params();
param_string = getStringFromVector(opts, ",");
}
// Minted needs a language specification
- if (minted_language.empty())
- minted_language = "TeX";
+ if (minted_language.empty()) {
+ // If a language has been set globally, use that,
+ // otherwise use TeX by default
+ string const & blp = buffer().params().listings_params;
+ size_t start = blp.find("language=");
+ if (start != string::npos) {
+ start += strlen("language=");
+ size_t len = blp.find(",", start);
+ if (len != string::npos)
+ len -= start;
+ minted_language = blp.substr(start, len);
+ } else
+ minted_language = "TeX";
+ }
// get the paragraphs. We can not output them directly to given odocstream
// because we can not yet determine the delimiter character of \lstinline
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 = use_minted || runparams.isFullUnicode()
- || (buffer().params().encoding().package() == Encoding::japanese
- && runparams.encoding->package() == Encoding::japanese);
- if (!multibyte_possible && !runparams.encoding->hasFixedWidth()) {
+ Encoding const * const outer_encoding =
+ (runparams.local_font != 0) ?
+ runparams.local_font->language()->encoding()
+ : buffer().params().language->encoding();
+ Encoding const * fixedlstenc = forcedEncoding(runparams.encoding, outer_encoding);
+ if (fixedlstenc) {
// 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;
+ // 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;
}
&& par->getInset(0)->lyxCode() == CAPTION_CODE;
while (par != end) {
- pos_type siz = par->size();
+ pos_type const siz = par->size();
bool captionline = false;
for (pos_type i = 0; i < siz; ++i) {
if (i == 0 && par->isInset(i) && i + 1 == siz)
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;
}
if (!uncodable.empty() && !runparams.silent) {
// issue a warning about omitted characters
// FIXME: should be passed to the error dialog
- if (!multibyte_possible && !runparams.encoding->hasFixedWidth())
+ if (fixedlstenc)
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"
return true;
}
}
+ // fall through
default:
return InsetCaptionable::getStatus(cur, cmd, status);
}