2 * \file InsetNomencl.cpp
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
9 * \author Jürgen Spitzmüller
11 * Full author contact details are available in file CREDITS.
15 #include "InsetNomencl.h"
16 #include "InsetNote.h"
19 #include "DispatchResult.h"
20 #include "FuncRequest.h"
21 #include "InsetIterator.h"
22 #include "InsetList.h"
23 #include "LaTeXFeatures.h"
24 #include "MetricsInfo.h"
27 #include "support/docstream.h"
28 #include "support/gettext.h"
29 #include "support/lstrings.h"
32 using namespace lyx::support;
37 /////////////////////////////////////////////////////////////////////
41 /////////////////////////////////////////////////////////////////////
43 InsetNomencl::InsetNomencl(InsetCommandParams const & p)
44 : InsetCommand(p, "nomenclature"),
45 nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
49 ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
51 static ParamInfo param_info_;
52 if (param_info_.empty()) {
53 param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
54 param_info_.add("symbol", ParamInfo::LATEX_REQUIRED);
55 param_info_.add("description", ParamInfo::LATEX_REQUIRED);
61 docstring InsetNomencl::screenLabel() const
63 size_t const maxLabelChars = 25;
65 docstring label = _("Nom: ") + getParam("symbol");
66 if (label.size() > maxLabelChars) {
67 label.erase(maxLabelChars - 3);
74 docstring InsetNomencl::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
76 docstring tip = _("Nomenclature Symbol: ") + getParam("symbol") + "\n";
77 tip += _("Description: ") + "\t"
78 + subst(getParam("description"), from_ascii("\\\\"), from_ascii("\n\t"));
79 if (!getParam("prefix").empty())
80 tip += "\n" + _("Sorting: ") + getParam("prefix");
86 int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
88 os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
89 << sgml::escapeString(getParam("symbol"))
95 int InsetNomencl::docbookGlossary(odocstream & os) const
97 os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
99 << sgml::escapeString(getParam("symbol"))
101 << "<glossdef><para>"
102 << sgml::escapeString(getParam("description"))
103 << "</para></glossdef>\n"
109 void InsetNomencl::validate(LaTeXFeatures & features) const
111 features.require("nomencl");
115 /////////////////////////////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////
121 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
122 : InsetCommand(p, "printnomenclature")
126 ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
128 // there are no parameters to give because the symbol width is set via
129 // nomencl's \nomlabelwidth in InsetPrintNomencl::latex and not as
130 // optional parameter of \printnomenclature
131 static ParamInfo param_info_;
136 docstring InsetPrintNomencl::screenLabel() const
138 return _("Nomenclature");
142 int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
144 os << "<glossary>\n";
146 InsetIterator it = inset_iterator_begin(buffer().inset());
148 if (it->lyxCode() == NOMENCL_CODE) {
149 newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
151 } else if (!it->producesOutput()) {
152 // Ignore contents of insets that are not in output
153 size_t const depth = it.depth();
155 while (it.depth() > depth)
161 os << "</glossary>\n";
166 docstring nomenclWidest(Buffer const & buffer)
168 // nomenclWidest() determines and returns the widest used nomenclature
169 // symbol in the document
173 InsetNomencl const * nomencl = 0;
175 ParagraphList::const_iterator it = buffer.paragraphs().begin();
176 ParagraphList::const_iterator end = buffer.paragraphs().end();
178 for (; it != end; ++it) {
179 if (it->insetList().empty())
181 InsetList::const_iterator iit = it->insetList().begin();
182 InsetList::const_iterator eend = it->insetList().end();
183 for (; iit != eend; ++iit) {
184 Inset * inset = iit->inset;
185 if (inset->lyxCode() != NOMENCL_CODE)
187 nomencl = static_cast<InsetNomencl const *>(inset);
188 docstring const symbol = nomencl->getParam("symbol");
189 int const wx = symbol.size();
197 // return the widest symbol
202 int InsetPrintNomencl::latex(odocstream & os, OutputParams const &) const
205 // this must be output before the command \printnomenclature
206 docstring widest = nomenclWidest(buffer());
207 if (!widest.empty()) {
208 // set the label width via nomencl's command \nomlabelwidth
209 os << "\\settowidth{\\nomlabelwidth}{";
210 os << widest <<"}\n";
213 // output the command \printnomenclature
219 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
221 features.require("nomencl");
225 InsetCode InsetPrintNomencl::lyxCode() const
227 return NOMENCL_PRINT_CODE;