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-23 05:47:40 +00:00
|
|
|
#include "LyX.h"
|
2010-02-13 13:23:59 +00:00
|
|
|
#include "OutputParams.h"
|
2019-05-09 23:35:40 +00:00
|
|
|
#include "xml.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"
|
2020-08-03 12:15:09 +00:00
|
|
|
#include "support/Length.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),
|
2019-05-09 23:35:40 +00:00
|
|
|
nomenclature_entry_id(xml::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
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetNomencl::docbook(XMLStream & xs, OutputParams const &) const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2020-06-08 21:27:49 +00:00
|
|
|
docstring attr = "linkend=\"" + nomenclature_entry_id + "\"";
|
|
|
|
xs << xml::StartTag("glossterm", attr);
|
|
|
|
xs << xml::escapeString(getParam("symbol"));
|
|
|
|
xs << xml::EndTag("glossterm");
|
2006-11-04 17:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetNomencl::xhtml(XMLStream &, OutputParams const &) const
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 {
|
2020-10-05 10:38:09 +00:00
|
|
|
NomenclEntry() : par(nullptr) {}
|
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;
|
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetPrintNomencl::xhtml(XMLStream &, OutputParams const & op) const
|
2013-03-27 23:30:30 +00:00
|
|
|
{
|
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;
|
2019-05-09 23:35:40 +00:00
|
|
|
XMLStream 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());
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::StartTag("div", "class='nomencl'")
|
|
|
|
<< xml::StartTag(tag, "class='nomencl'")
|
2017-07-03 17:53:14 +00:00
|
|
|
<< toclabel
|
2019-05-09 23:35:40 +00:00
|
|
|
<< xml::EndTag(tag)
|
|
|
|
<< xml::CR()
|
|
|
|
<< xml::StartTag("dl")
|
|
|
|
<< xml::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();
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::StartTag("dt")
|
|
|
|
<< xml::StartTag("a", "href='#" + parid + "' class='nomencl'")
|
2013-03-27 23:30:30 +00:00
|
|
|
<< ne.symbol
|
2019-05-09 23:35:40 +00:00
|
|
|
<< xml::EndTag("a")
|
|
|
|
<< xml::EndTag("dt")
|
|
|
|
<< xml::CR()
|
|
|
|
<< xml::StartTag("dd")
|
2013-03-27 23:30:30 +00:00
|
|
|
<< ne.desc
|
2019-05-09 23:35:40 +00:00
|
|
|
<< xml::EndTag("dd")
|
|
|
|
<< xml::CR();
|
2013-03-27 23:30:30 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::EndTag("dl")
|
|
|
|
<< xml::CR()
|
|
|
|
<< xml::EndTag("div")
|
|
|
|
<< xml::CR();
|
2013-03-27 23:30:30 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetPrintNomencl::docbook(XMLStream & xs, OutputParams const & runparams) const
|
2006-11-04 17:55:36 +00:00
|
|
|
{
|
2020-06-08 21:27:49 +00:00
|
|
|
shared_ptr<Toc const> toc = buffer().tocBackend().toc("nomencl");
|
|
|
|
|
|
|
|
EntryMap entries;
|
|
|
|
Toc::const_iterator it = toc->begin();
|
|
|
|
Toc::const_iterator const en = toc->end();
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
DocIterator dit = it->dit();
|
|
|
|
Paragraph const & par = dit.innerParagraph();
|
|
|
|
Inset const * inset = par.getInset(dit.top().pos());
|
|
|
|
if (!inset)
|
|
|
|
return;
|
|
|
|
InsetCommand const * ic = inset->asInsetCommand();
|
|
|
|
if (!ic)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
entries[sortas] = NomenclEntry(symbol, desc, &par);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entries.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// As opposed to XHTML, no need to defer everything until the end of time, so write directly to xs.
|
|
|
|
// TODO: At least, that's what was done before...
|
|
|
|
|
|
|
|
docstring toclabel = translateIfPossible(from_ascii("Nomenclature"),
|
|
|
|
runparams.local_font->language()->lang());
|
|
|
|
|
|
|
|
xs << xml::StartTag("glossary");
|
|
|
|
xs << xml::CR();
|
|
|
|
xs << xml::StartTag("title");
|
|
|
|
xs << toclabel;
|
|
|
|
xs << xml::EndTag("title");
|
|
|
|
xs << xml::CR();
|
|
|
|
|
|
|
|
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 << xml::StartTag("glossentry", "xml:id=\"" + parid + "\"");
|
|
|
|
xs << xml::CR();
|
|
|
|
xs << xml::StartTag("glossterm");
|
|
|
|
xs << ne.symbol;
|
|
|
|
xs << xml::EndTag("glossterm");
|
|
|
|
xs << xml::CR();
|
|
|
|
xs << xml::StartTag("glossdef");
|
|
|
|
xs << xml::CR();
|
|
|
|
xs << xml::StartTag("para");
|
|
|
|
xs << ne.desc;
|
|
|
|
xs << xml::EndTag("para");
|
|
|
|
xs << xml::CR();
|
|
|
|
xs << xml::EndTag("glossdef");
|
|
|
|
xs << xml::CR();
|
|
|
|
xs << xml::EndTag("glossentry");
|
|
|
|
xs << xml::CR();
|
2006-11-10 15:45:42 +00:00
|
|
|
}
|
2020-06-08 21:27:49 +00:00
|
|
|
|
|
|
|
xs << xml::EndTag("glossary");
|
|
|
|
xs << xml::CR();
|
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;
|
2020-10-05 10:38:09 +00:00
|
|
|
InsetNomencl const * nomencl = nullptr;
|
2009-05-21 19:33:09 +00:00
|
|
|
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
|