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;
174 ParagraphList::const_iterator it = buffer.paragraphs().begin();
175 ParagraphList::const_iterator end = buffer.paragraphs().end();
177 for (; it != end; ++it) {
178 if (it->insetList().empty())
180 InsetList::const_iterator iit = it->insetList().begin();
181 InsetList::const_iterator eend = it->insetList().end();
182 for (; iit != eend; ++iit) {
183 Inset * inset = iit->inset;
184 if (inset->lyxCode() != NOMENCL_CODE)
186 nomencl = static_cast<InsetNomencl const *>(inset);
187 docstring const symbol = nomencl->getParam("symbol");
188 // we can only check for the number of characters, since it is
189 // impossible to get the info that "iiiii" is smaller than "WW"
190 // we therefore output w times "W" as string ("W" is always the
192 int const wx = symbol.size();
197 // return the widest symbol as w times a "W"
198 for (int n = 1; n <= w; ++n)
204 int InsetPrintNomencl::latex(odocstream & os, OutputParams const &) const
207 docstring widest = nomenclWidest(buffer());
208 // set the label width via nomencl's command \nomlabelwidth
209 // this must be output before the command \printnomenclature
210 if (!widest.empty()) {
211 // assure that the width is never below the predefined value of 1 cm
212 os << "\\settowidth{\\nomlabelwidth}{" << widest <<"}\n";
213 os << "\\ifthenelse{%\n \\lengthtest{\\nomlabelwidth < 1cm}}\n";
214 os << " {\\setlength{\\nomlabelwidth}{1cm}}\n {}\n";
217 // output the command \printnomenclature
223 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
225 features.require("nomencl");
226 // needed for InsetPrintNomencl::latex
227 features.require("ifthen");
231 InsetCode InsetPrintNomencl::lyxCode() const
233 return NOMENCL_PRINT_CODE;