]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIndex.cpp
More requires --> required, for C++2a.
[lyx.git] / src / insets / InsetIndex.cpp
index 584fb280c78d74396d77839092167861bc14f52f..f3fafce60b00d8af9d62813a074fa3314236634a 100644 (file)
@@ -59,11 +59,13 @@ InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params)
 {}
 
 
-void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
+void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) const
 {
        OutputParams runparams(runparams_in);
        runparams.inIndexEntry = true;
 
+       otexstringstream os;
+
        if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
            && params_.index != "idx") {
                os << "\\sindex[";
@@ -74,14 +76,19 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
                os << '{';
        }
 
-       // get contents of InsetText as LaTeX and plaintext
        odocstringstream ourlatex;
-       // FIXME: do Tex/Row correspondence (I don't currently understand what is
-       // being generated from latexstr below)
        otexstream ots(ourlatex);
        InsetText::latex(ots, runparams);
+       if (runparams.for_search) {
+               // No need for special handling, if we are only searching for some patterns
+               os << ourlatex.str() << "}";
+               return;
+       }
+       // get contents of InsetText as LaTeX and plaintext
        odocstringstream ourplain;
        InsetText::plaintext(ourplain, runparams);
+       // FIXME: do Tex/Row correspondence (I don't currently understand what is
+       // being generated from latexstr below)
        docstring latexstr = ourlatex.str();
        docstring plainstr = ourplain.str();
 
@@ -165,6 +172,13 @@ void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
                os << "|" << cmd;
        }
        os << '}';
+
+       // In macros with moving arguments, such as \section,
+       // we store the index and output it after the macro (#2154)
+       if (runparams_in.postpone_fragile_stuff)
+               runparams_in.post_macro += os.str();
+       else
+               ios << os.release();
 }
 
 
@@ -480,22 +494,22 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY: {
                if (cmd.argument() == from_ascii("toggle-subindex")) {
-                       string cmd = getCmdName();
-                       if (contains(cmd, "printindex"))
-                               cmd = subst(cmd, "printindex", "printsubindex");
+                       string scmd = getCmdName();
+                       if (contains(scmd, "printindex"))
+                               scmd = subst(scmd, "printindex", "printsubindex");
                        else
-                               cmd = subst(cmd, "printsubindex", "printindex");
+                               scmd = subst(scmd, "printsubindex", "printindex");
                        cur.recordUndo();
-                       setCmdName(cmd);
+                       setCmdName(scmd);
                        break;
                } else if (cmd.argument() == from_ascii("check-printindex*")) {
-                       string cmd = getCmdName();
-                       if (suffixIs(cmd, '*'))
+                       string scmd = getCmdName();
+                       if (suffixIs(scmd, '*'))
                                break;
-                       cmd += '*';
+                       scmd += '*';
                        cur.recordUndo();
                        setParam("type", docstring());
-                       setCmdName(cmd);
+                       setCmdName(scmd);
                        break;
                }
                InsetCommandParams p(INDEX_PRINT_CODE);