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 if (InsetText::plaintext(os, runparams) > 0) {
65 // if a hierarchy tag '!' is used, ommit this in the post-@ part.
66 if (sorted && contains(ods.str(), '!')) {
69 os << from_utf8(rsplit(to_utf8(ods.str()), dummy, '!'));
71 i = InsetText::latex(os, runparams);
77 int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
79 os << "<indexterm><primary>";
80 int const i = InsetText::docbook(os, runparams);
81 os << "</primary></indexterm>";
86 void InsetIndex::write(ostream & os) const
88 os << to_utf8(name()) << "\n";
89 InsetCollapsable::write(os);
93 void InsetIndex::addToToc(ParConstIterator const & cpit) const
95 ParConstIterator pit = cpit;
98 Toc & toc = buffer().tocBackend().toc("index");
100 str = getNewLabel(str);
101 toc.push_back(TocItem(pit, 0, str));
105 /////////////////////////////////////////////////////////////////////
109 ///////////////////////////////////////////////////////////////////////
111 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
112 : InsetCommand(p, string())
116 ParamInfo const & InsetPrintIndex::findInfo(string const & /* cmdName */)
118 static ParamInfo param_info_;
119 if (param_info_.empty())
120 param_info_.add("name", ParamInfo::LATEX_REQUIRED);
125 docstring InsetPrintIndex::screenLabel() const
131 void InsetPrintIndex::validate(LaTeXFeatures & features) const
133 features.require("makeidx");
137 InsetCode InsetPrintIndex::lyxCode() const
139 return INDEX_PRINT_CODE;