diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index d92d385271..76d31ca26e 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -20,11 +20,14 @@ #include "sgml.h" #include "TocBackend.h" +#include "support/docstream.h" #include "support/gettext.h" +#include "support/lstrings.h" #include using namespace std; +using namespace lyx::support; namespace lyx { @@ -45,9 +48,16 @@ int InsetIndex::latex(odocstream & os, { os << "\\index"; os << '{'; - if (hasFontChanges()) { - InsetText::plaintext(os, runparams); - os << '@'; + odocstringstream ods; + InsetText::latex(ods, runparams); + // correctly sort macros and formatted strings + // if we do find a command, prepend a plain text + // version of the content to get sorting right, + // e.g. \index{LyX@\LyX}, \index{text@\textbf{text}} + // Don't do that if the user entered '@' himself, though. + if (contains(ods.str(), '\\') && !contains(ods.str(), '@')) { + if (InsetText::plaintext(os, runparams) > 0) + os << '@'; } int i = InsetText::latex(os, runparams); os << '}'; @@ -83,16 +93,6 @@ void InsetIndex::addToToc(ParConstIterator const & cpit) const } -bool InsetIndex::hasFontChanges() const -{ - // we only have one par - Paragraph par = paragraphs().back(); - FontSpan const font_span = par.fontSpan(0); - Font firstfont = par.getFirstFontSettings(buffer().params()); - return (firstfont.fontInfo() != inherit_font || par.size() > font_span.last + 1); -} - - ///////////////////////////////////////////////////////////////////// // // InsetPrintIndex diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 1d8f045af4..513a0eb2d1 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -44,8 +44,6 @@ private: void addToToc(ParConstIterator const &) const; /// Inset * clone() const { return new InsetIndex(*this); } - /// - bool hasFontChanges() const; };