>> > InsetPrintNomencl is an InsetCommand. So if latex is not implemented in
>> > InsetPrintNomencl itself, InsetCommand::latex is called
>>
>> But latex is implemented in InsetPrintNomencl but it is still not called.
>
> Did you change the function to an int?

Yes, see the attached patch.

regards Uwe
Index: insets/InsetNomencl.cpp
===================================================================
--- insets/InsetNomencl.cpp	(revision 29765)
+++ insets/InsetNomencl.cpp	(working copy)
@@ -17,10 +17,12 @@
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "InsetIterator.h"
+#include "InsetList.h"
 #include "LaTeXFeatures.h"
 #include "MetricsInfo.h"
 #include "sgml.h"
 
+#include "support/convert.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -116,16 +118,15 @@
 /////////////////////////////////////////////////////////////////////
 
 InsetPrintNomencl::InsetPrintNomencl(InsetCommandParams const & p)
-	: InsetCommand(p, string())
+	: InsetCommand(p, "printnomenclature")
 {}
 
 
 ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
 {
 	static ParamInfo param_info_;
-	if (param_info_.empty()) {
-		param_info_.add("labelwidth", ParamInfo::LATEX_REQUIRED);
-	}
+	//if (param_info_.empty())
+	//	param_info_.add("symbolwidth", ParamInfo::LATEX_OPTIONAL);
 	return param_info_;
 }
 
@@ -160,6 +161,53 @@
 }
 
 
+docstring nomenclWidest(Buffer const & buffer)
+{
+	// nomenclWidest() determines and returns the widest used nomenclature
+	// symbol in the document
+
+	int w = 0;
+	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;
+		Inset * inset = it->insetList().begin()->inset;
+		if (inset->lyxCode() != NOMENCL_CODE)
+			continue;
+		nomencl = static_cast<InsetNomencl const *>(inset);
+		docstring const symbol = nomencl->getParam("symbol");
+		int const wx = symbol.size();
+		if (wx > w)
+			w = wx;
+	}
+
+	// return the widest symbol otherwise return an empty string
+	docstring const symb = nomencl ?
+		nomencl->getParam("symbol") : docstring();
+	return symb;
+}
+
+
+int InsetPrintNomencl::latex(Buffer const & buffer, odocstream & os,
+							 OutputParams const &) const
+{
+	int lines = 0;
+	// this must be output before the command \printnomenclature
+	if (!nomenclWidest(buffer).empty()) {
+		// set the label width via nomencl's command \nomlabelwidth
+		os << "\\settowidth{\nomlabelwidth}{";
+		os << nomenclWidest(buffer) <<"}\n";
+		++lines;
+	}
+	os << getCommand();
+	return lines;
+}
+
+
 void InsetPrintNomencl::validate(LaTeXFeatures & features) const
 {
 	features.require("nomencl");
Index: insets/InsetNomencl.h
===================================================================
--- insets/InsetNomencl.h	(revision 29765)
+++ insets/InsetNomencl.h	(working copy)
@@ -61,10 +61,6 @@
 	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,11 +76,18 @@
 	///
 	static bool isCompatibleCommand(std::string const & s) 
 		{ return s == "printnomenclature"; }
+	///
+	int latex(Buffer const &, 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
 
 #endif

Reply via email to