From ec5e4b26f5a7023a17ab6f9031d93e3dd873a4d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Thu, 21 May 2009 19:33:09 +0000 Subject: [PATCH] InsetNomencl: calculate the needed symbol width for \printnomenclature, fixes #5909 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29770 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetNomencl.cpp | 64 ++++++++++++++++++++++++++++++++++--- src/insets/InsetNomencl.h | 11 ++++--- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index eae20721ac..bc2e0bb00a 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -5,6 +5,8 @@ * * \author Lars Gullik Bjønnes * \author O. U. Baran + * \author Uwe Stöhr + * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. */ @@ -17,6 +19,7 @@ #include "DispatchResult.h" #include "FuncRequest.h" #include "InsetIterator.h" +#include "InsetList.h" #include "LaTeXFeatures.h" #include "MetricsInfo.h" #include "sgml.h" @@ -116,16 +119,16 @@ void InsetNomencl::validate(LaTeXFeatures & features) const ///////////////////////////////////////////////////////////////////// InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p) - : InsetCommand(p, string()) + : InsetCommand(p, "printnomenclature") {} ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */) { + // there are no parameters to give because the symbol width is set via + // nomencl's \nomlabelwidth in InsetPrintNomencl::latex and not as + // optional parameter of \printnomenclature static ParamInfo param_info_; - if (param_info_.empty()) { - param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED); - } return param_info_; } @@ -160,6 +163,59 @@ int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const } +docstring nomenclWidest(Buffer const & buffer) +{ + // 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(inset); + docstring const symbol = nomencl->getParam("symbol"); + int const wx = symbol.size(); + if (wx > w) { + w = wx; + symb = symbol; + } + } + } + + // return the widest symbol + return symb; +} + + +int InsetPrintNomencl::latex(odocstream & os, OutputParams const &) const +{ + int lines = 0; + // this must be output before the command \printnomenclature + docstring widest = nomenclWidest(buffer()); + if (!widest.empty()) { + // set the label width via nomencl's command \nomlabelwidth + os << "\\settowidth{\\nomlabelwidth}{"; + os << widest <<"}\n"; + ++lines; + } + // output the command \printnomenclature + os << getCommand(); + return lines; +} + + void InsetPrintNomencl::validate(LaTeXFeatures & features) const { features.require("nomencl"); diff --git a/src/insets/InsetNomencl.h b/src/insets/InsetNomencl.h index d63e99c249..c81657157f 100644 --- a/src/insets/InsetNomencl.h +++ b/src/insets/InsetNomencl.h @@ -61,10 +61,6 @@ public: InsetPrintNomencl(InsetCommandParams const &); /// Updates needed features for this inset. void validate(LaTeXFeatures & features) const; - // FIXME: This should be editable to set the label width (stored - // in params_["labelwidth"]). - // Currently the width can be read from file and written, but not - // changed. /// int docbook(odocstream &, OutputParams const &) const; /// @@ -80,10 +76,17 @@ public: /// static bool isCompatibleCommand(std::string const & s) { return s == "printnomenclature"; } + /// + int latex(odocstream &, OutputParams const &) const; private: Inset * clone() const { return new InsetPrintNomencl(*this); } + /// + friend docstring nomenclWidest(Buffer const & buffer); }; +/// return the widest symbol of all nomenclature entries of the document +docstring nomenclWidest(Buffer const &); + } // namespace lyx -- 2.39.2