3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
12 #include "InsetIndex.h"
15 #include "DispatchResult.h"
16 #include "FuncRequest.h"
17 #include "FuncStatus.h"
18 #include "LaTeXFeatures.h"
19 #include "MetricsInfo.h"
21 #include "TocBackend.h"
23 #include "support/docstream.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
30 using namespace lyx::support;
34 /////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////
41 InsetIndex::InsetIndex(Buffer const & buf)
42 : InsetCollapsable(buf)
46 int InsetIndex::latex(odocstream & os,
47 OutputParams const & runparams) const
52 int i = InsetText::latex(ods, runparams);
54 // correctly sort macros and formatted strings
55 // if we do find a command, prepend a plain text
56 // version of the content to get sorting right,
57 // e.g. \index{LyX@\LyX}, \index{text@\textbf{text}}
58 // Don't do that if the user entered '@' himself, though.
59 if (contains(ods.str(), '\\') && !contains(ods.str(), '@')) {
60 odocstringstream odss;
61 if (InsetText::plaintext(odss, runparams) > 0) {
62 // remove remaining \'s for the sorting part
63 os << subst(odss.str(), from_ascii("\\"), docstring());
68 // if a hierarchy tag '!' is used, ommit this in the post-@ part.
69 if (sorted && contains(ods.str(), '!')) {
72 os << from_utf8(rsplit(to_utf8(ods.str()), dummy, '!'));
74 i = InsetText::latex(os, runparams);
80 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
82 os << "<indexterm><primary>";
83 int const i = InsetText::docbook(os, runparams);
84 os << "</primary></indexterm>";
89 void InsetIndex::write(ostream & os) const
91 os << to_utf8(name()) << "\n";
92 InsetCollapsable::write(os);
96 void InsetIndex::addToToc(DocIterator const & cpit)
98 DocIterator pit = cpit;
99 pit.push_back(CursorSlice(*this));
101 Toc & toc = buffer().tocBackend().toc("index");
103 str = getNewLabel(str);
104 toc.push_back(TocItem(pit, 0, str));
108 /////////////////////////////////////////////////////////////////////
112 ///////////////////////////////////////////////////////////////////////
114 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
115 : InsetCommand(p, string())
119 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
121 static ParamInfo param_info_;
122 if (param_info_.empty())
123 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
128 docstring InsetPrintIndex::screenLabel() const
134 void InsetPrintIndex::validate(LaTeXFeatures & features) const
136 features.require("makeidx");
140 InsetCode InsetPrintIndex::lyxCode() const
142 return INDEX_PRINT_CODE;