+namespace {
+docstring nomenclWidest(Buffer const & buffer, OutputParams const & runparams)
+{
+ // nomenclWidest() determines and returns the widest used
+ // nomenclature symbol in the document
+
+ int w = 0;
+ docstring symb;
+ InsetNomencl const * nomencl = 0;
+ ParagraphList::const_iterator it = buffer.paragraphs().begin();
+ ParagraphList::const_iterator end = buffer.paragraphs().end();
+
+ for (; it != end; ++it) {
+ if (it->insetList().empty())
+ continue;
+ InsetList::const_iterator iit = it->insetList().begin();
+ InsetList::const_iterator eend = it->insetList().end();
+ for (; iit != eend; ++iit) {
+ Inset * inset = iit->inset;
+ if (inset->lyxCode() != NOMENCL_CODE)
+ continue;
+ nomencl = static_cast<InsetNomencl const *>(inset);
+ docstring const symbol =
+ nomencl->getParam("symbol");
+ // This is only an approximation,
+ // but the best we can get.
+ int const wx = use_gui ?
+ theFontMetrics(Font()).width(symbol) :
+ symbol.size();
+ if (wx > w) {
+ w = wx;
+ symb = symbol;
+ }
+ }
+ }
+ // return the widest (or an empty) string
+ if (symb.empty())
+ return symb;
+
+ // we have to encode the string properly
+ docstring latex_symb;
+ for (size_t n = 0; n < symb.size(); ++n) {
+ try {
+ latex_symb += runparams.encoding->latexChar(symb[n]);
+ } catch (EncodingException & /* e */) {
+ if (runparams.dryrun) {
+ latex_symb += "<" + _("LyX Warning: ")
+ + _("uncodable character") + " '";
+ latex_symb += docstring(1, symb[n]);
+ latex_symb += "'>";
+ }
+ }
+ }
+ return latex_symb;
+}
+} // namespace anon
+
+
+int InsetPrintNomencl::latex(odocstream & os, OutputParams const & runparams_in) const
+{
+ OutputParams runparams = runparams_in;
+ int lines = 0;
+ if (getParam("set_width") == "auto") {
+ docstring widest = nomenclWidest(buffer(), runparams);
+ // Set the label width via nomencl's command \nomlabelwidth.
+ // This must be output before the command \printnomenclature
+ if (!widest.empty()) {
+ os << "\\settowidth{\\nomlabelwidth}{"
+ << widest
+ << "}\n";
+ ++lines;
+ }
+ } else if (getParam("set_width") == "custom") {
+ // custom length as optional arg of \printnomenclature
+ string const width =
+ Length(to_ascii(getParam("width"))).asLatexString();
+ os << '\\'
+ << from_ascii(getCmdName())
+ << '['
+ << from_ascii(width)
+ << "]{}";
+ return lines;
+ }
+ // output the command \printnomenclature
+ os << getCommand(runparams);
+ return lines;
+}
+
+