Properly escape splitindex shortcut and try to encode splitindex name properly (part of bug #8227)

This commit is contained in:
Juergen Spitzmueller 2012-06-30 13:34:49 +02:00
parent 51d591d168
commit 5eb9ece39e
2 changed files with 20 additions and 13 deletions

View File

@ -1744,10 +1744,20 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
IndicesList::const_iterator iit = indiceslist().begin(); IndicesList::const_iterator iit = indiceslist().begin();
IndicesList::const_iterator iend = indiceslist().end(); IndicesList::const_iterator iend = indiceslist().end();
for (; iit != iend; ++iit) { for (; iit != iend; ++iit) {
pair<docstring, docstring> indexname_latex =
features.runparams().encoding->latexString(iit->index(), features.runparams().dryrun);
if (!indexname_latex.second.empty()) {
// issue a warning about omitted characters
// FIXME: should be passed to the error dialog
frontend::Alert::warning(_("Uncodable characters"),
bformat(_("The following characters that are used in an index name are not\n"
"representable in the current encoding and therefore have been omitted:\n%1$s."),
indexname_latex.second));
}
lyxpreamble += "\\newindex["; lyxpreamble += "\\newindex[";
lyxpreamble += iit->index(); lyxpreamble += indexname_latex.first;
lyxpreamble += "]{"; lyxpreamble += "]{";
lyxpreamble += iit->shortcut(); lyxpreamble += escape(iit->shortcut());
lyxpreamble += "}\n"; lyxpreamble += "}\n";
} }
} }

View File

@ -65,7 +65,7 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty() if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
&& params_.index != "idx") { && params_.index != "idx") {
os << "\\sindex["; os << "\\sindex[";
os << params_.index; os << escape(params_.index);
os << "]{"; os << "]{";
} else { } else {
os << "\\index"; os << "\\index";
@ -134,15 +134,11 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
// the sorting part are representable in the current // the sorting part are representable in the current
// encoding. If not try the LaTeX macro which might // encoding. If not try the LaTeX macro which might
// or might not be a good choice, and issue a warning. // or might not be a good choice, and issue a warning.
docstring spart2; pair<docstring, docstring> spart_latexed =
for (size_t n = 0; n < spart.size(); ++n) { runparams.encoding->latexString(spart, runparams.dryrun);
try { if (!spart_latexed.second.empty())
spart2 += runparams.encoding->latexChar(spart[n]).first;
} catch (EncodingException & /* e */) {
LYXERR0("Uncodable character in index entry. Sorting might be wrong!"); LYXERR0("Uncodable character in index entry. Sorting might be wrong!");
} if (spart != spart_latexed.first && !runparams.dryrun) {
}
if (spart != spart2 && !runparams.dryrun) {
// FIXME: warning should be passed to the error dialog // FIXME: warning should be passed to the error dialog
frontend::Alert::warning(_("Index sorting failed"), frontend::Alert::warning(_("Index sorting failed"),
bformat(_("LyX's automatic index sorting algorithm faced\n" bformat(_("LyX's automatic index sorting algorithm faced\n"
@ -152,7 +148,7 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
} }
// remove remaining \'s for the sorting part // remove remaining \'s for the sorting part
docstring const ppart = docstring const ppart =
subst(spart2, from_ascii("\\"), docstring()); subst(spart_latexed.first, from_ascii("\\"), docstring());
os << ppart; os << ppart;
os << '@'; os << '@';
} }
@ -429,7 +425,8 @@ ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
{ {
static ParamInfo param_info_; static ParamInfo param_info_;
if (param_info_.empty()) { if (param_info_.empty()) {
param_info_.add("type", ParamInfo::LATEX_OPTIONAL); param_info_.add("type", ParamInfo::LATEX_OPTIONAL,
ParamInfo::HANDLING_ESCAPE);
param_info_.add("name", ParamInfo::LATEX_REQUIRED); param_info_.add("name", ParamInfo::LATEX_REQUIRED);
} }
return param_info_; return param_info_;