Minted does not have a language option but it is possible to enter
this option in the LyX interface for compatibility with the listings
package, and also for letting to enter a language not present in the
gui. So, this option is only used for properly specifying a language
in a listing, unless it is entered in the document settings dialog.
This case was not foreseen and thus the option was being passed to
the package as is, causing havoc. With this commit the option is
still available but is used to set a default language for a new
listing in place of the default "tex" language used so far.

(cherry picked from commit 16ca5290c0)
This commit is contained in:
Enrico Forestieri 2018-07-22 22:22:13 +02:00
parent ae196dd70c
commit 4862e00c1f
4 changed files with 41 additions and 7 deletions

View File

@ -2269,7 +2269,18 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
else
os << "\\usepackage{listings}\n";
}
if (!listings_params.empty()) {
string lst_params = listings_params;
// If minted, do not output the language option (bug 11203)
if (use_minted && contains(lst_params, "language=")) {
vector<string> opts =
getVectorFromString(lst_params, ",", false);
for (size_t i = 0; i < opts.size(); ++i) {
if (prefixIs(opts[i], "language="))
opts.erase(opts.begin() + i--);
}
lst_params = getStringFromVector(opts, ",");
}
if (!lst_params.empty()) {
if (use_minted)
os << "\\setminted{";
else
@ -2277,7 +2288,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
// do not test validity because listings_params is
// supposed to be valid
string par =
InsetListingsParams(listings_params).separatedParams(true);
InsetListingsParams(lst_params).separatedParams(true);
os << from_utf8(par);
os << "}\n";
}

View File

@ -320,9 +320,18 @@ string GuiListings::construct_params()
InsetListingsParams par;
par.setMinted(use_minted);
if (use_minted) {
if (language == "no language" && !contains(extra, "language="))
par.addParam("language", "TeX");
else
if (language == "no language" && !contains(extra, "language=")) {
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;
par.addParam("language", blp.substr(start, len));
} else
par.addParam("language", "TeX");
} else
par.addParam("language", language);
} else if (language != "no language" && !contains(extra, "language=")) {
if (dialect.empty())

View File

@ -169,8 +169,20 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const
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

View File

@ -62,6 +62,8 @@ What's new
- Fix loss of citation list after Undo (bug 9158).
- Fix document-wide language setting with minted (bug 11203).
* INTERNALS