2006-11-04 17:55:36 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetNomencl.cpp
|
2006-11-04 17:55:36 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2006-11-04 17:55:36 +00:00
|
|
|
* \author O. U. Baran
|
2009-05-21 19:33:09 +00:00
|
|
|
* \author Uwe Stöhr
|
|
|
|
* \author Jürgen Spitzmüller
|
2006-11-04 17:55:36 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetNomencl.h"
|
|
|
|
#include "InsetNote.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2009-05-22 09:25:31 +00:00
|
|
|
#include "Font.h"
|
2010-02-13 13:23:59 +00:00
|
|
|
#include "Encoding.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2009-05-22 16:26:15 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "InsetIterator.h"
|
2009-05-21 19:33:09 +00:00
|
|
|
#include "InsetList.h"
|
2013-03-27 23:30:30 +00:00
|
|
|
#include "Language.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2009-05-22 16:26:15 +00:00
|
|
|
#include "Length.h"
|
2009-05-23 05:47:40 +00:00
|
|
|
#include "LyX.h"
|
2010-02-13 13:23:59 +00:00
|
|
|
#include "OutputParams.h"
|
2009-11-21 23:29:29 +00:00
|
|
|
#include "output_xhtml.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
#include "sgml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2013-03-27 22:40:08 +00:00
|
|
|
#include "TocBackend.h"
|
2006-11-04 17:55:36 +00:00
|
|
|
|
2009-05-22 09:25:31 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
|
2012-06-30 11:30:48 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/gettext.h"
|
2008-08-23 15:02:44 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2008-08-23 15:02:44 +00:00
|
|
|
using namespace lyx::support;
|
2006-11-04 17:55:36 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2008-08-23 15:02:44 +00:00
|
|
|
// InsetNomencl
|
2008-02-27 20:43:16 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetNomencl::InsetNomencl(Buffer * buf, InsetCommandParams const & p)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p),
|
2007-04-29 22:21:00 +00:00
|
|
|
nomenclature_entry_id(sgml::uniqueID(from_ascii("nomen")))
|
2006-11-04 17:55:36 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetNomencl::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
param_info_.add("prefix", ParamInfo::LATEX_OPTIONAL);
|
2010-02-13 13:23:59 +00:00
|
|
|
param_info_.add("symbol", ParamInfo::LATEX_REQUIRED,
|
2017-12-03 10:36:09 +00:00
|
|
|
ParamInfo::ParamHandling(ParamInfo::HANDLING_LATEXIFY
|
2017-12-01 12:39:38 +00:00
|
|
|
| ParamInfo::HANDLING_INDEX_ESCAPE));
|
2010-02-13 13:23:59 +00:00
|
|
|
param_info_.add("description", ParamInfo::LATEX_REQUIRED,
|
2017-12-03 10:36:09 +00:00
|
|
|
ParamInfo::ParamHandling(ParamInfo::HANDLING_LATEXIFY
|
2017-12-01 12:39:38 +00:00
|
|
|
| ParamInfo::HANDLING_INDEX_ESCAPE));
|
2017-01-30 06:44:55 +00:00
|
|
|
param_info_.add("literal", ParamInfo::LYX_INTERNAL);
|
2008-02-23 22:01:02 +00:00
|
|
|
}
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetNomencl::screenLabel() const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2008-08-22 16:12:29 +00:00
|
|
|
size_t const maxLabelChars = 25;
|
|
|
|
docstring label = _("Nom: ") + getParam("symbol");
|
2015-10-04 18:38:47 +00:00
|
|
|
support::truncateWithEllipsis(label, maxLabelChars);
|
2008-08-22 16:12:29 +00:00
|
|
|
return label;
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-23 15:02:44 +00:00
|
|
|
docstring InsetNomencl::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
|
|
|
|
{
|
|
|
|
docstring tip = _("Nomenclature Symbol: ") + getParam("symbol") + "\n";
|
|
|
|
tip += _("Description: ") + "\t"
|
|
|
|
+ subst(getParam("description"), from_ascii("\\\\"), from_ascii("\n\t"));
|
|
|
|
if (!getParam("prefix").empty())
|
|
|
|
tip += "\n" + _("Sorting: ") + getParam("prefix");
|
|
|
|
return tip;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-29 10:32:51 +00:00
|
|
|
int InsetNomencl::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) const
|
|
|
|
{
|
|
|
|
docstring s = "[" + getParam("symbol") + ": " + getParam("description") + "]";
|
|
|
|
os << s;
|
|
|
|
return s.size();
|
|
|
|
}
|
|
|
|
|
2008-08-23 15:02:44 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetNomencl::docbook(odocstream & os, OutputParams const &) const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2007-04-29 22:21:00 +00:00
|
|
|
os << "<glossterm linkend=\"" << nomenclature_entry_id << "\">"
|
2006-11-04 17:55:36 +00:00
|
|
|
<< sgml::escapeString(getParam("symbol"))
|
2006-11-10 15:45:42 +00:00
|
|
|
<< "</glossterm>";
|
2006-11-04 17:55:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 23:29:29 +00:00
|
|
|
docstring InsetNomencl::xhtml(XHTMLStream &, OutputParams const &) const
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-10 15:45:42 +00:00
|
|
|
int InsetNomencl::docbookGlossary(odocstream & os) const
|
|
|
|
{
|
2007-04-29 22:21:00 +00:00
|
|
|
os << "<glossentry id=\"" << nomenclature_entry_id << "\">\n"
|
2006-11-10 15:45:42 +00:00
|
|
|
<< "<glossterm>"
|
|
|
|
<< sgml::escapeString(getParam("symbol"))
|
|
|
|
<< "</glossterm>\n"
|
|
|
|
<< "<glossdef><para>"
|
|
|
|
<< sgml::escapeString(getParam("description"))
|
|
|
|
<< "</para></glossdef>\n"
|
|
|
|
<<"</glossentry>\n";
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
void InsetNomencl::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
features.require("nomencl");
|
2017-01-30 06:44:55 +00:00
|
|
|
InsetCommand::validate(features);
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetNomencl::addToToc(DocIterator const & cpit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType, TocBackend & backend) const
|
2013-03-27 22:40:08 +00:00
|
|
|
{
|
|
|
|
docstring const str = getParam("symbol");
|
2017-01-13 10:06:48 +00:00
|
|
|
TocBuilder & b = backend.builder("nomencl");
|
2017-01-09 16:37:50 +00:00
|
|
|
b.pushItem(cpit, str, output_active);
|
|
|
|
b.pop();
|
2013-03-27 22:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetPrintNomencl
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetPrintNomencl::InsetPrintNomencl(Buffer * buf, InsetCommandParams const & p)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p)
|
2006-11-04 17:55:36 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetPrintNomencl::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
// The symbol width is set via nomencl's \nomlabelwidth in
|
2009-05-22 08:31:43 +00:00
|
|
|
// InsetPrintNomencl::latex and not as optional parameter of
|
|
|
|
// \printnomenclature
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
2009-05-22 08:31:43 +00:00
|
|
|
if (param_info_.empty()) {
|
|
|
|
// how is the width set?
|
2009-05-22 16:26:15 +00:00
|
|
|
// values: none|auto|custom
|
2009-05-22 08:31:43 +00:00
|
|
|
param_info_.add("set_width", ParamInfo::LYX_INTERNAL);
|
2009-05-22 16:26:15 +00:00
|
|
|
// custom width
|
|
|
|
param_info_.add("width", ParamInfo::LYX_INTERNAL);
|
2009-05-22 08:31:43 +00:00
|
|
|
}
|
2008-02-23 22:01:02 +00:00
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetPrintNomencl::screenLabel() const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2007-04-29 22:21:00 +00:00
|
|
|
return _("Nomenclature");
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
struct NomenclEntry {
|
2016-06-12 03:39:45 +00:00
|
|
|
NomenclEntry() : par(0) {}
|
2013-03-27 23:30:30 +00:00
|
|
|
NomenclEntry(docstring s, docstring d, Paragraph const * p)
|
|
|
|
: symbol(s), desc(d), par(p)
|
|
|
|
{}
|
|
|
|
|
|
|
|
docstring symbol;
|
|
|
|
docstring desc;
|
|
|
|
Paragraph const * par;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef map<docstring, NomenclEntry > EntryMap;
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetPrintNomencl::xhtml(XHTMLStream &, OutputParams const & op) const
|
|
|
|
{
|
2015-09-01 16:08:35 +00:00
|
|
|
shared_ptr<Toc const> toc = buffer().tocBackend().toc("nomencl");
|
2013-03-27 23:30:30 +00:00
|
|
|
|
|
|
|
EntryMap entries;
|
2015-09-01 16:08:35 +00:00
|
|
|
Toc::const_iterator it = toc->begin();
|
|
|
|
Toc::const_iterator const en = toc->end();
|
2013-03-27 23:30:30 +00:00
|
|
|
for (; it != en; ++it) {
|
|
|
|
DocIterator dit = it->dit();
|
|
|
|
Paragraph const & par = dit.innerParagraph();
|
|
|
|
Inset const * inset = par.getInset(dit.top().pos());
|
|
|
|
if (!inset)
|
|
|
|
return docstring();
|
|
|
|
InsetCommand const * ic = inset->asInsetCommand();
|
|
|
|
if (!ic)
|
|
|
|
return docstring();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
// FIXME We need a link to the paragraph here, so we
|
|
|
|
// need some kind of struct.
|
|
|
|
docstring const symbol = ic->getParam("symbol");
|
|
|
|
docstring const desc = ic->getParam("description");
|
|
|
|
docstring const prefix = ic->getParam("prefix");
|
|
|
|
docstring const sortas = prefix.empty() ? symbol : prefix;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
entries[sortas] = NomenclEntry(symbol, desc, &par);
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
if (entries.empty())
|
|
|
|
return docstring();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
// we'll use our own stream, because we are going to defer everything.
|
|
|
|
// that's how we deal with the fact that we're probably inside a standard
|
|
|
|
// paragraph, and we don't want to be.
|
|
|
|
odocstringstream ods;
|
|
|
|
XHTMLStream xs(ods);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
InsetLayout const & il = getLayout();
|
|
|
|
string const & tag = il.htmltag();
|
|
|
|
docstring toclabel = translateIfPossible(from_ascii("Nomenclature"),
|
|
|
|
op.local_font->language()->lang());
|
|
|
|
|
|
|
|
xs << html::StartTag("div", "class='nomencl'")
|
|
|
|
<< html::StartTag(tag, "class='nomencl'")
|
2017-07-03 17:53:14 +00:00
|
|
|
<< toclabel
|
2013-03-27 23:30:30 +00:00
|
|
|
<< html::EndTag(tag)
|
|
|
|
<< html::CR()
|
|
|
|
<< html::StartTag("dl")
|
|
|
|
<< html::CR();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2013-03-27 23:30:30 +00:00
|
|
|
EntryMap::const_iterator eit = entries.begin();
|
|
|
|
EntryMap::const_iterator const een = entries.end();
|
|
|
|
for (; eit != een; ++eit) {
|
|
|
|
NomenclEntry const & ne = eit->second;
|
|
|
|
string const parid = ne.par->magicLabel();
|
|
|
|
xs << html::StartTag("dt")
|
|
|
|
<< html::StartTag("a", "href='#" + parid + "' class='nomencl'")
|
|
|
|
<< ne.symbol
|
|
|
|
<< html::EndTag("a")
|
|
|
|
<< html::EndTag("dt")
|
|
|
|
<< html::CR()
|
|
|
|
<< html::StartTag("dd")
|
|
|
|
<< ne.desc
|
|
|
|
<< html::EndTag("dd")
|
|
|
|
<< html::CR();
|
|
|
|
}
|
|
|
|
|
|
|
|
xs << html::EndTag("dl")
|
|
|
|
<< html::CR()
|
|
|
|
<< html::EndTag("div")
|
|
|
|
<< html::CR();
|
|
|
|
|
|
|
|
return ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 16:26:15 +00:00
|
|
|
void InsetPrintNomencl::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-05-22 16:26:15 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetCommandParams p(NOMENCL_PRINT_CODE);
|
|
|
|
// FIXME UNICODE
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2009-05-22 16:26:15 +00:00
|
|
|
if (p.getCmdName().empty()) {
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2009-05-22 16:26:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-12-08 09:24:04 +00:00
|
|
|
|
|
|
|
cur.recordUndo();
|
2009-05-22 16:26:15 +00:00
|
|
|
setParams(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetPrintNomencl::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-05-22 16:26:15 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
status.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCommand::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 22:29:41 +00:00
|
|
|
// FIXME This should be changed to use the TOC. Perhaps
|
|
|
|
// that could be done when XHTML output is added.
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetPrintNomencl::docbook(odocstream & os, OutputParams const &) const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2006-11-10 15:45:42 +00:00
|
|
|
os << "<glossary>\n";
|
|
|
|
int newlines = 2;
|
2008-04-23 18:49:55 +00:00
|
|
|
InsetIterator it = inset_iterator_begin(buffer().inset());
|
|
|
|
while (it) {
|
2007-10-13 09:04:52 +00:00
|
|
|
if (it->lyxCode() == NOMENCL_CODE) {
|
2006-11-10 15:45:42 +00:00
|
|
|
newlines += static_cast<InsetNomencl const &>(*it).docbookGlossary(os);
|
|
|
|
++it;
|
2008-04-23 13:00:57 +00:00
|
|
|
} else if (!it->producesOutput()) {
|
|
|
|
// Ignore contents of insets that are not in output
|
2006-11-10 15:45:42 +00:00
|
|
|
size_t const depth = it.depth();
|
|
|
|
++it;
|
|
|
|
while (it.depth() > depth)
|
|
|
|
++it;
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os << "</glossary>\n";
|
|
|
|
return newlines;
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-22 08:31:43 +00:00
|
|
|
namespace {
|
2010-02-13 13:23:59 +00:00
|
|
|
docstring nomenclWidest(Buffer const & buffer, OutputParams const & runparams)
|
2009-05-21 19:33:09 +00:00
|
|
|
{
|
2009-05-22 08:31:43 +00:00
|
|
|
// nomenclWidest() determines and returns the widest used
|
|
|
|
// nomenclature symbol in the document
|
2009-05-21 19:33:09 +00:00
|
|
|
|
|
|
|
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);
|
2017-12-03 11:04:39 +00:00
|
|
|
// Use proper formatting. We do not escape makeindex chars here
|
|
|
|
docstring const symbol = nomencl ?
|
2017-12-03 10:57:11 +00:00
|
|
|
nomencl->params().prepareCommand(runparams, nomencl->getParam("symbol"),
|
2017-12-03 11:04:39 +00:00
|
|
|
ParamInfo::HANDLING_LATEXIFY)
|
|
|
|
: docstring();
|
2009-05-22 09:25:31 +00:00
|
|
|
// This is only an approximation,
|
|
|
|
// but the best we can get.
|
2009-05-23 05:47:40 +00:00
|
|
|
int const wx = use_gui ?
|
|
|
|
theFontMetrics(Font()).width(symbol) :
|
|
|
|
symbol.size();
|
2009-05-22 09:25:31 +00:00
|
|
|
if (wx > w) {
|
2009-05-21 19:33:09 +00:00
|
|
|
w = wx;
|
2009-05-22 09:25:31 +00:00
|
|
|
symb = symbol;
|
|
|
|
}
|
2009-05-21 19:33:09 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-22 09:25:31 +00:00
|
|
|
// return the widest (or an empty) string
|
2017-12-03 10:57:11 +00:00
|
|
|
return symb;
|
2009-05-22 08:31:43 +00:00
|
|
|
}
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2009-05-21 19:33:09 +00:00
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetPrintNomencl::latex(otexstream & os, OutputParams const & runparams_in) const
|
2009-05-21 19:33:09 +00:00
|
|
|
{
|
2010-02-13 13:23:59 +00:00
|
|
|
OutputParams runparams = runparams_in;
|
2009-05-22 08:31:43 +00:00
|
|
|
if (getParam("set_width") == "auto") {
|
2010-02-13 13:23:59 +00:00
|
|
|
docstring widest = nomenclWidest(buffer(), runparams);
|
2009-05-22 23:23:09 +00:00
|
|
|
// Set the label width via nomencl's command \nomlabelwidth.
|
2009-05-23 14:39:30 +00:00
|
|
|
// This must be output before the command \printnomenclature
|
2009-05-22 08:31:43 +00:00
|
|
|
if (!widest.empty()) {
|
2009-05-23 14:39:30 +00:00
|
|
|
os << "\\settowidth{\\nomlabelwidth}{"
|
2009-05-22 08:31:43 +00:00
|
|
|
<< widest
|
|
|
|
<< "}\n";
|
|
|
|
}
|
2009-05-22 16:26:15 +00:00
|
|
|
} 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)
|
2016-12-16 09:20:25 +00:00
|
|
|
<< "]"
|
|
|
|
<< termcmd;
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2009-05-21 19:33:09 +00:00
|
|
|
}
|
|
|
|
// output the command \printnomenclature
|
2010-02-13 13:08:32 +00:00
|
|
|
os << getCommand(runparams);
|
2009-05-21 19:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
void InsetPrintNomencl::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2017-12-01 09:10:06 +00:00
|
|
|
features.useInsetLayout(getLayout());
|
2006-11-04 17:55:36 +00:00
|
|
|
features.require("nomencl");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
InsetCode InsetPrintNomencl::lyxCode() const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2007-10-13 09:04:52 +00:00
|
|
|
return NOMENCL_PRINT_CODE;
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetPrintNomencl::contextMenuName() const
|
2009-05-22 16:26:15 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-nomenclprint";
|
2009-05-22 16:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-04 17:55:36 +00:00
|
|
|
} // namespace lyx
|