2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathHull.cpp
|
2003-08-19 13:00:56 +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 André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-11-07 12:54:08 +00:00
|
|
|
#include "InsetMathHull.h"
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathChar.h"
|
|
|
|
#include "InsetMathColor.h"
|
2015-06-14 16:10:29 +00:00
|
|
|
#include "InsetMathFrac.h"
|
|
|
|
#include "InsetMathNest.h"
|
|
|
|
#include "InsetMathScript.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathExtern.h"
|
|
|
|
#include "MathFactory.h"
|
|
|
|
#include "MathStream.h"
|
|
|
|
#include "MathSupport.h"
|
2006-09-16 18:11:38 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2004-01-16 12:36:23 +00:00
|
|
|
#include "BufferView.h"
|
2010-02-05 18:34:01 +00:00
|
|
|
#include "ColorSet.h"
|
2020-10-15 06:59:01 +00:00
|
|
|
#include "Cursor.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
#include "CutAndPaste.h"
|
2009-10-09 21:33:08 +00:00
|
|
|
#include "Encoding.h"
|
2010-07-21 13:19:52 +00:00
|
|
|
#include "Exporter.h"
|
2009-11-07 12:54:08 +00:00
|
|
|
#include "FuncRequest.h"
|
2004-11-26 13:56:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2011-01-11 19:35:52 +00:00
|
|
|
#include "Language.h"
|
2004-04-18 07:34:15 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2009-11-22 20:50:35 +00:00
|
|
|
#include "MacroTable.h"
|
2017-07-05 12:31:28 +00:00
|
|
|
#include "InsetMathMacro.h"
|
|
|
|
#include "InsetMathMacroTemplate.h"
|
2016-06-04 08:41:13 +00:00
|
|
|
#include "MetricsInfo.h"
|
2011-01-11 19:35:52 +00:00
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "ParIterator.h"
|
2019-05-09 23:35:40 +00:00
|
|
|
#include "xml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "TexRow.h"
|
2011-01-11 19:35:52 +00:00
|
|
|
#include "TextClass.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "TextPainter.h"
|
2008-02-15 08:09:35 +00:00
|
|
|
#include "TocBackend.h"
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetLabel.h"
|
2009-05-15 20:54:15 +00:00
|
|
|
#include "insets/InsetRef.h"
|
2009-11-07 12:54:08 +00:00
|
|
|
#include "insets/RenderPreview.h"
|
2004-04-13 17:38:16 +00:00
|
|
|
|
2014-03-19 16:43:21 +00:00
|
|
|
#include "graphics/GraphicsImage.h"
|
2004-04-19 13:05:36 +00:00
|
|
|
#include "graphics/PreviewImage.h"
|
2009-12-17 15:21:08 +00:00
|
|
|
#include "graphics/PreviewLoader.h"
|
2004-04-13 17:38:16 +00:00
|
|
|
|
2010-11-23 15:36:58 +00:00
|
|
|
#include "frontends/alert.h"
|
2020-08-25 11:05:29 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2007-05-12 06:24:46 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2011-01-11 19:35:52 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
2016-05-23 14:44:29 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lassert.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
#include "support/lstrings.h"
|
2020-11-12 12:09:36 +00:00
|
|
|
#include "support/Changer.h"
|
2004-10-29 23:08:04 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-19 21:00:33 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using cap::grabAndEraseSelection;
|
2014-11-09 20:56:40 +00:00
|
|
|
using cap::reduceSelectionToOneCell;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
namespace {
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
int getCols(HullType type)
|
2001-10-18 13:21:21 +00:00
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
switch (type) {
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullEqnArray:
|
|
|
|
return 3;
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
return 2;
|
|
|
|
case hullUnknown:
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
case hullRegexp:
|
|
|
|
return 1;
|
2006-09-03 16:14:51 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
// avoid warning
|
|
|
|
return 0;
|
2001-10-18 13:21:21 +00:00
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
|
|
|
// returns position of first relation operator in the array
|
|
|
|
// used for "intelligent splitting"
|
2007-04-26 16:05:57 +00:00
|
|
|
size_t firstRelOp(MathData const & ar)
|
2001-10-18 13:21:21 +00:00
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
|
2016-05-30 08:33:35 +00:00
|
|
|
if ((*it)->mathClass() == MC_REL)
|
2001-10-18 13:21:21 +00:00
|
|
|
return it - ar.begin();
|
|
|
|
return ar.size();
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
char const * star(bool numbered)
|
|
|
|
{
|
|
|
|
return numbered ? "" : "*";
|
|
|
|
}
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
|
2016-10-24 22:49:26 +00:00
|
|
|
// writes a preamble for underlined or struck out math display
|
|
|
|
void writeMathdisplayPreamble(WriteStream & os)
|
|
|
|
{
|
2019-12-28 12:43:17 +00:00
|
|
|
if (os.strikeoutMath())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (os.ulemCmd() == WriteStream::UNDERLINE)
|
2016-10-24 22:49:26 +00:00
|
|
|
os << "\\raisebox{-\\belowdisplayshortskip}{"
|
2017-10-22 11:12:33 +00:00
|
|
|
"\\parbox[b]{\\linewidth}{";
|
2016-10-24 22:49:26 +00:00
|
|
|
else if (os.ulemCmd() == WriteStream::STRIKEOUT)
|
2017-10-22 11:12:33 +00:00
|
|
|
os << "\\parbox{\\linewidth}{";
|
2016-10-24 22:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// writes a postamble for underlined or struck out math display
|
|
|
|
void writeMathdisplayPostamble(WriteStream & os)
|
|
|
|
{
|
2019-12-28 12:43:17 +00:00
|
|
|
if (os.strikeoutMath())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (os.ulemCmd() == WriteStream::UNDERLINE)
|
2016-10-24 22:49:26 +00:00
|
|
|
os << "}}\\\\\n";
|
|
|
|
else if (os.ulemCmd() == WriteStream::STRIKEOUT)
|
|
|
|
os << "}\\\\\n";
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2008-03-04 12:50:06 +00:00
|
|
|
static InsetLabel * dummy_pointer = 0;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2009-11-06 15:18:48 +00:00
|
|
|
InsetMathHull::InsetMathHull(Buffer * buf)
|
2019-05-11 21:18:10 +00:00
|
|
|
: InsetMathGrid(buf, 1, 1), type_(hullNone), numbered_(1, NONUMBER),
|
2015-05-17 15:27:12 +00:00
|
|
|
numbers_(1, empty_docstring()), label_(1, dummy_pointer),
|
2016-02-03 13:50:00 +00:00
|
|
|
preview_(new RenderPreview(this))
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
//lyxerr << "sizeof InsetMath: " << sizeof(InsetMath) << endl;
|
2004-01-26 10:13:15 +00:00
|
|
|
//lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
//lyxerr << "sizeof InsetMathChar: " << sizeof(InsetMathChar) << endl;
|
2007-10-28 18:51:54 +00:00
|
|
|
//lyxerr << "sizeof FontInfo: " << sizeof(FontInfo) << endl;
|
2009-11-06 15:18:48 +00:00
|
|
|
buffer_ = buf;
|
2005-12-15 16:59:59 +00:00
|
|
|
initMath();
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathHull::InsetMathHull(Buffer * buf, HullType type)
|
2019-07-01 10:05:31 +00:00
|
|
|
: InsetMathGrid(buf, getCols(type), 1), type_(type), numbered_(1, NONUMBER),
|
2015-05-17 15:27:12 +00:00
|
|
|
numbers_(1, empty_docstring()), label_(1, dummy_pointer),
|
2016-02-03 13:50:00 +00:00
|
|
|
preview_(new RenderPreview(this))
|
2002-02-14 13:25:26 +00:00
|
|
|
{
|
2009-11-06 15:18:48 +00:00
|
|
|
buffer_ = buf;
|
2005-12-15 16:59:59 +00:00
|
|
|
initMath();
|
2002-02-14 13:25:26 +00:00
|
|
|
setDefaults();
|
|
|
|
}
|
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid(other)
|
2008-03-04 12:22:48 +00:00
|
|
|
{
|
|
|
|
operator=(other);
|
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathHull::~InsetMathHull()
|
2008-03-04 12:22:48 +00:00
|
|
|
{
|
2020-10-09 06:04:20 +00:00
|
|
|
for (auto & i : label_)
|
|
|
|
delete i;
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathHull::clone() const
|
2001-08-02 09:59:09 +00:00
|
|
|
{
|
2007-08-30 22:30:31 +00:00
|
|
|
return new InsetMathHull(*this);
|
2001-08-02 09:59:09 +00:00
|
|
|
}
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
|
|
|
if (this == &other)
|
2004-11-23 23:04:52 +00:00
|
|
|
return *this;
|
2008-03-04 12:22:48 +00:00
|
|
|
InsetMathGrid::operator=(other);
|
2004-04-13 17:38:16 +00:00
|
|
|
type_ = other.type_;
|
2010-10-24 17:27:32 +00:00
|
|
|
numbered_ = other.numbered_;
|
2011-01-11 19:35:52 +00:00
|
|
|
numbers_ = other.numbers_;
|
2009-11-06 15:18:48 +00:00
|
|
|
buffer_ = other.buffer_;
|
2020-10-09 06:04:20 +00:00
|
|
|
for (auto & i : label_)
|
|
|
|
delete i;
|
2004-04-13 17:38:16 +00:00
|
|
|
label_ = other.label_;
|
2008-03-04 12:22:48 +00:00
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (label_[i])
|
|
|
|
label_[i] = new InsetLabel(*label_[i]);
|
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
preview_.reset(new RenderPreview(*other.preview_, this));
|
2004-11-23 23:04:52 +00:00
|
|
|
|
|
|
|
return *this;
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 12:22:48 +00:00
|
|
|
void InsetMathHull::setBuffer(Buffer & buffer)
|
|
|
|
{
|
2009-08-03 10:30:34 +00:00
|
|
|
InsetMathGrid::setBuffer(buffer);
|
2008-03-04 14:18:34 +00:00
|
|
|
|
2008-03-04 12:22:48 +00:00
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (label_[i])
|
|
|
|
label_[i]->setBuffer(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-08 23:07:40 +00:00
|
|
|
// FIXME This should really be controlled by the TOC level, or
|
|
|
|
// something of the sort.
|
2011-01-12 16:04:59 +00:00
|
|
|
namespace {
|
|
|
|
const char * counters_to_save[] = {"section", "chapter"};
|
|
|
|
unsigned int const numcnts = sizeof(counters_to_save)/sizeof(char *);
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2011-01-12 16:04:59 +00:00
|
|
|
|
|
|
|
|
2020-03-06 12:23:01 +00:00
|
|
|
void InsetMathHull::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
|
2008-02-15 08:09:35 +00:00
|
|
|
{
|
2008-02-28 10:04:15 +00:00
|
|
|
if (!buffer_) {
|
|
|
|
//FIXME: buffer_ should be set at creation for this inset! Problem is
|
|
|
|
// This inset is created at too many places (see Parser::parse1() in
|
|
|
|
// MathParser.cpp).
|
|
|
|
return;
|
|
|
|
}
|
2011-01-11 19:35:52 +00:00
|
|
|
|
2011-01-12 16:04:59 +00:00
|
|
|
// if any of the equations are numbered, then we want to save the values
|
|
|
|
// of some of the counters.
|
|
|
|
if (haveNumbers()) {
|
|
|
|
BufferParams const & bp = buffer_->params();
|
|
|
|
string const & lang = it->getParLanguage(bp)->code();
|
2011-05-05 20:31:47 +00:00
|
|
|
Counters & cnts =
|
|
|
|
buffer_->masterBuffer()->params().documentClass().counters();
|
2011-01-12 16:04:59 +00:00
|
|
|
|
|
|
|
// right now, we only need to do this at export time
|
|
|
|
if (utype == OutputUpdate) {
|
|
|
|
for (size_t i = 0; i < numcnts; ++i) {
|
|
|
|
docstring const cnt = from_ascii(counters_to_save[i]);
|
|
|
|
if (cnts.hasCounter(cnt))
|
|
|
|
counter_map[cnt] = cnts.value(cnt);
|
|
|
|
}
|
|
|
|
}
|
2011-01-11 19:35:52 +00:00
|
|
|
|
2011-01-12 16:04:59 +00:00
|
|
|
// this has to be done separately
|
|
|
|
docstring const eqstr = from_ascii("equation");
|
|
|
|
if (cnts.hasCounter(eqstr)) {
|
2011-04-01 18:35:06 +00:00
|
|
|
if (utype == OutputUpdate)
|
2011-01-12 16:04:59 +00:00
|
|
|
counter_map[eqstr] = cnts.value(eqstr);
|
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (numbered(i)) {
|
2018-05-03 04:05:21 +00:00
|
|
|
Paragraph const & par = it.paragraph();
|
|
|
|
if (!par.isDeleted(it.pos())) {
|
|
|
|
cnts.step(eqstr, utype);
|
|
|
|
numbers_[i] = cnts.theCounter(eqstr, lang);
|
|
|
|
} else
|
|
|
|
numbers_[i] = from_ascii("#");
|
2011-01-12 16:04:59 +00:00
|
|
|
} else
|
|
|
|
numbers_[i] = empty_docstring();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now the labels
|
2008-03-04 12:22:48 +00:00
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
if (label_[i])
|
2020-03-06 12:23:01 +00:00
|
|
|
label_[i]->updateBuffer(it, utype, deleted);
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
2010-01-28 17:37:22 +00:00
|
|
|
// pass down
|
2020-03-06 12:23:01 +00:00
|
|
|
InsetMathGrid::updateBuffer(it, utype, deleted);
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 10:04:15 +00:00
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetMathHull::addToToc(DocIterator const & pit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const
|
2008-03-04 12:22:48 +00:00
|
|
|
{
|
|
|
|
if (!buffer_) {
|
|
|
|
//FIXME: buffer_ should be set at creation for this inset! Problem is
|
|
|
|
// This inset is created at too many places (see Parser::parse1() in
|
|
|
|
// MathParser.cpp).
|
2008-02-15 08:09:35 +00:00
|
|
|
return;
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-13 10:06:48 +00:00
|
|
|
TocBuilder & b = backend.builder("equation");
|
2017-01-09 16:37:50 +00:00
|
|
|
// compute first and last item
|
|
|
|
row_type first = nrows();
|
|
|
|
for (row_type row = 0; row != nrows(); ++row)
|
|
|
|
if (numbered(row)) {
|
|
|
|
first = row;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (first == nrows())
|
|
|
|
// no equation
|
|
|
|
return;
|
|
|
|
row_type last = nrows() - 1;
|
|
|
|
for (; last != 0; --last)
|
|
|
|
if (numbered(last))
|
|
|
|
break;
|
|
|
|
// add equation numbers
|
|
|
|
b.pushItem(pit, docstring(), output_active);
|
|
|
|
if (first != last)
|
|
|
|
b.argumentItem(bformat(from_ascii("(%1$s-%2$s)"),
|
|
|
|
numbers_[first], numbers_[last]));
|
2008-03-04 12:22:48 +00:00
|
|
|
for (row_type row = 0; row != nrows(); ++row) {
|
2014-05-27 20:17:35 +00:00
|
|
|
if (!numbered(row))
|
2008-03-04 12:22:48 +00:00
|
|
|
continue;
|
|
|
|
if (label_[row])
|
2017-01-13 10:06:48 +00:00
|
|
|
label_[row]->addToToc(pit, output_active, utype, backend);
|
2017-01-09 16:37:50 +00:00
|
|
|
docstring label = nicelabel(row);
|
|
|
|
if (first == last)
|
|
|
|
// this is the only equation
|
|
|
|
b.argumentItem(label);
|
|
|
|
else {
|
|
|
|
// insert as sub-items
|
|
|
|
b.pushItem(pit, label, output_active);
|
|
|
|
b.pop();
|
|
|
|
}
|
2008-03-04 12:22:48 +00:00
|
|
|
}
|
2017-01-09 16:37:50 +00:00
|
|
|
b.pop();
|
2008-02-15 08:09:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * InsetMathHull::editXY(Cursor & cur, int x, int y)
|
2005-07-15 00:39:44 +00:00
|
|
|
{
|
2016-02-03 13:50:00 +00:00
|
|
|
if (previewState(&cur.bv())) {
|
2005-07-15 00:39:44 +00:00
|
|
|
edit(cur, true);
|
|
|
|
return this;
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
return InsetMathNest::editXY(cur, x, y);
|
2005-07-15 00:39:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMath::mode_type InsetMathHull::currentMode() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2015-12-14 01:54:27 +00:00
|
|
|
switch (type_) {
|
|
|
|
case hullNone:
|
2002-07-18 11:02:33 +00:00
|
|
|
return UNDECIDED_MODE;
|
2015-12-14 01:54:27 +00:00
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
// definitely math mode ...
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullUnknown:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullRegexp:
|
|
|
|
return MATH_MODE;
|
|
|
|
}
|
|
|
|
// avoid warning
|
2002-07-18 11:02:33 +00:00
|
|
|
return MATH_MODE;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-13 03:32:32 +00:00
|
|
|
// FIXME: InsetMathGrid should be changed to let the real column alignment be
|
|
|
|
// given by a virtual method like displayColAlign, because the values produced
|
2015-12-20 20:56:34 +00:00
|
|
|
// by defaultColAlign can be invalidated by lfuns such as add-column. For the
|
|
|
|
// moment the values produced by defaultColAlign are not used, notably because
|
|
|
|
// alignment is not implemented in the LyXHTML output.
|
2006-09-16 18:11:38 +00:00
|
|
|
char InsetMathHull::defaultColAlign(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
2019-10-20 18:50:23 +00:00
|
|
|
return colAlign(type_, col);
|
2001-09-04 13:32:06 +00:00
|
|
|
}
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
2015-05-17 11:43:37 +00:00
|
|
|
char InsetMathHull::displayColAlign(idx_type idx) const
|
2011-10-18 18:46:57 +00:00
|
|
|
{
|
2015-12-13 03:32:32 +00:00
|
|
|
switch (type_) {
|
|
|
|
case hullMultline: {
|
2015-05-17 11:43:37 +00:00
|
|
|
row_type const r = row(idx);
|
|
|
|
if (r == 0)
|
2011-10-18 18:46:57 +00:00
|
|
|
return 'l';
|
2015-05-17 11:43:37 +00:00
|
|
|
if (r == nrows() - 1)
|
2011-10-18 18:46:57 +00:00
|
|
|
return 'r';
|
2015-12-13 03:32:32 +00:00
|
|
|
return 'c';
|
|
|
|
}
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullGather:
|
|
|
|
case hullAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullFlAlign:
|
2019-10-20 18:50:23 +00:00
|
|
|
return colAlign(type_, col(idx));
|
2015-12-13 03:32:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-10-18 18:46:57 +00:00
|
|
|
}
|
2015-05-17 11:43:37 +00:00
|
|
|
return InsetMathGrid::displayColAlign(idx);
|
2011-10-18 18:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-20 20:56:34 +00:00
|
|
|
int InsetMathHull::displayColSpace(col_type col) const
|
|
|
|
{
|
|
|
|
return colSpace(type_, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: same comment as for defaultColAlign applies.
|
2006-09-16 18:11:38 +00:00
|
|
|
int InsetMathHull::defaultColSpace(col_type col)
|
2001-09-04 13:32:06 +00:00
|
|
|
{
|
2015-12-20 20:56:34 +00:00
|
|
|
return colSpace(type_, col);
|
2001-09-04 13:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Remove a conversion to_utf8() inside FontSetChanger
This requires to change many docstrings into std::strings. The logic behind that
is that they represent a fixed set of math fonts, and therefore “string” means
here “poor man's enum” rather than text (this is consistent with MetricsBase).
Profiling of scrolling inside a document over macro-instensive areas:
Before the patch:
44,1% BufferView::updateMetrics()
-> 34,8% InsetMathHull::metrics()
-> 9,8% FontSetChanger::FontSetChanger()
28,4% BufferView::draw()
After the patch:
35,3% BufferView::updateMetrics()
-> 27,2% InsetMathHull::metrics
-> 0,4% FontSetChanger::FontSetChanger()
47,5% BufferView::draw()
FontSetChanger::FontSetChanger() is made 41x less expensive (with reference
BV::draw()) just by removing this conversion. The remaining 0,4% could be
squished by replacing the strings with a proper enum, but this is premature. Of
course, this only treats the symptoms: there is no good reason that this
function is called 45500 times over the time of 40 repaints.
2016-06-07 21:58:55 +00:00
|
|
|
string InsetMathHull::standardFont() const
|
2002-06-24 15:37:14 +00:00
|
|
|
{
|
2010-02-05 09:00:40 +00:00
|
|
|
switch (type_) {
|
|
|
|
case hullRegexp:
|
Remove a conversion to_utf8() inside FontSetChanger
This requires to change many docstrings into std::strings. The logic behind that
is that they represent a fixed set of math fonts, and therefore “string” means
here “poor man's enum” rather than text (this is consistent with MetricsBase).
Profiling of scrolling inside a document over macro-instensive areas:
Before the patch:
44,1% BufferView::updateMetrics()
-> 34,8% InsetMathHull::metrics()
-> 9,8% FontSetChanger::FontSetChanger()
28,4% BufferView::draw()
After the patch:
35,3% BufferView::updateMetrics()
-> 27,2% InsetMathHull::metrics
-> 0,4% FontSetChanger::FontSetChanger()
47,5% BufferView::draw()
FontSetChanger::FontSetChanger() is made 41x less expensive (with reference
BV::draw()) just by removing this conversion. The remaining 0,4% could be
squished by replacing the strings with a proper enum, but this is premature. Of
course, this only treats the symptoms: there is no good reason that this
function is called 45500 times over the time of 40 repaints.
2016-06-07 21:58:55 +00:00
|
|
|
return "texttt";
|
2010-02-05 09:00:40 +00:00
|
|
|
case hullNone:
|
Remove a conversion to_utf8() inside FontSetChanger
This requires to change many docstrings into std::strings. The logic behind that
is that they represent a fixed set of math fonts, and therefore “string” means
here “poor man's enum” rather than text (this is consistent with MetricsBase).
Profiling of scrolling inside a document over macro-instensive areas:
Before the patch:
44,1% BufferView::updateMetrics()
-> 34,8% InsetMathHull::metrics()
-> 9,8% FontSetChanger::FontSetChanger()
28,4% BufferView::draw()
After the patch:
35,3% BufferView::updateMetrics()
-> 27,2% InsetMathHull::metrics
-> 0,4% FontSetChanger::FontSetChanger()
47,5% BufferView::draw()
FontSetChanger::FontSetChanger() is made 41x less expensive (with reference
BV::draw()) just by removing this conversion. The remaining 0,4% could be
squished by replacing the strings with a proper enum, but this is premature. Of
course, this only treats the symptoms: there is no good reason that this
function is called 45500 times over the time of 40 repaints.
2016-06-07 21:58:55 +00:00
|
|
|
return "lyxnochange";
|
2010-02-05 09:00:40 +00:00
|
|
|
default:
|
Remove a conversion to_utf8() inside FontSetChanger
This requires to change many docstrings into std::strings. The logic behind that
is that they represent a fixed set of math fonts, and therefore “string” means
here “poor man's enum” rather than text (this is consistent with MetricsBase).
Profiling of scrolling inside a document over macro-instensive areas:
Before the patch:
44,1% BufferView::updateMetrics()
-> 34,8% InsetMathHull::metrics()
-> 9,8% FontSetChanger::FontSetChanger()
28,4% BufferView::draw()
After the patch:
35,3% BufferView::updateMetrics()
-> 27,2% InsetMathHull::metrics
-> 0,4% FontSetChanger::FontSetChanger()
47,5% BufferView::draw()
FontSetChanger::FontSetChanger() is made 41x less expensive (with reference
BV::draw()) just by removing this conversion. The remaining 0,4% could be
squished by replacing the strings with a proper enum, but this is premature. Of
course, this only treats the symptoms: there is no good reason that this
function is called 45500 times over the time of 40 repaints.
2016-06-07 21:58:55 +00:00
|
|
|
return "mathnormal";
|
2010-02-05 09:00:40 +00:00
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-09 13:02:20 +00:00
|
|
|
ColorCode InsetMathHull::standardColor() const
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
{
|
|
|
|
switch (type_) {
|
|
|
|
case hullRegexp:
|
|
|
|
case hullNone:
|
2015-12-14 01:54:27 +00:00
|
|
|
return Color_foreground;
|
|
|
|
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
default:
|
2015-12-14 01:54:27 +00:00
|
|
|
return Color_math;
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-19 16:43:21 +00:00
|
|
|
bool InsetMathHull::previewState(const BufferView *const bv) const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2014-05-20 10:19:26 +00:00
|
|
|
if (!editing(bv) && RenderPreview::previewMath()
|
|
|
|
&& type_ != hullRegexp)
|
2013-08-24 12:06:05 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::PreviewImage const * pimage =
|
2007-08-21 13:03:55 +00:00
|
|
|
preview_->getPreviewImage(bv->buffer());
|
2005-07-18 00:45:10 +00:00
|
|
|
return pimage && pimage->image();
|
2004-04-19 13:05:36 +00:00
|
|
|
}
|
2005-07-18 00:45:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
2014-03-19 16:43:21 +00:00
|
|
|
namespace {
|
2018-02-19 17:24:29 +00:00
|
|
|
const int ERROR_FRAME_WIDTH = 2;
|
|
|
|
|
2020-05-28 18:40:30 +00:00
|
|
|
bool previewTooSmall(Dimension const & dim)
|
2018-02-19 17:24:29 +00:00
|
|
|
{
|
2020-05-28 18:40:30 +00:00
|
|
|
return dim.width() <= 10 && dim.height() <= 10;
|
2018-02-19 17:24:29 +00:00
|
|
|
}
|
2014-03-19 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 17:24:29 +00:00
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
|
2005-07-18 00:45:10 +00:00
|
|
|
{
|
2020-08-25 11:05:29 +00:00
|
|
|
/* Compute \(above|below)displayskip
|
|
|
|
true value in LaTeX is 10pt plus 2pt minus 5pt (in normal size at 10pt)
|
|
|
|
FIXME: make this dependent of current size? (minor improvement)
|
|
|
|
FIXME: if would be nice if this was not part of the inset, but
|
|
|
|
just increased the row ascent/descent.
|
|
|
|
FIXME: even better would be to handle the short skip case.
|
|
|
|
*/
|
|
|
|
int const bottom_display_margin = mi.base.inPixels(Length(10, Length::PT));
|
|
|
|
int top_display_margin = bottom_display_margin;
|
|
|
|
// at start of paragraph, add an empty line
|
|
|
|
if (mi.vmode)
|
|
|
|
top_display_margin += theFontMetrics(mi.base.font).maxHeight() + 2;
|
2018-02-19 17:24:29 +00:00
|
|
|
|
2005-07-18 00:45:10 +00:00
|
|
|
if (previewState(mi.base.bv)) {
|
2004-04-13 17:38:16 +00:00
|
|
|
preview_->metrics(mi, dim);
|
2020-05-28 18:40:30 +00:00
|
|
|
if (previewTooSmall(dim)) {
|
2014-03-19 16:43:21 +00:00
|
|
|
// preview image is too small
|
|
|
|
dim.wid += 2 * ERROR_FRAME_WIDTH;
|
|
|
|
dim.asc += 2 * ERROR_FRAME_WIDTH;
|
|
|
|
} else {
|
2018-02-19 17:24:29 +00:00
|
|
|
// insert a gap in front of the formula
|
|
|
|
// value was hardcoded to 1 pixel
|
|
|
|
dim.wid += mi.base.bv->zoomedPixels(1) ;
|
2018-09-12 13:26:15 +00:00
|
|
|
if (display()) {
|
2020-08-25 11:05:29 +00:00
|
|
|
dim.asc += top_display_margin;
|
|
|
|
dim.des += bottom_display_margin;
|
2018-02-19 17:24:29 +00:00
|
|
|
}
|
2014-03-19 16:43:21 +00:00
|
|
|
}
|
2007-09-21 20:39:47 +00:00
|
|
|
return;
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 19:04:45 +00:00
|
|
|
{
|
|
|
|
Changer dummy1 = mi.base.changeFontSet(standardFont());
|
|
|
|
Changer dummy2 = mi.base.font.changeStyle(display() ? DISPLAY_STYLE
|
|
|
|
: TEXT_STYLE);
|
|
|
|
|
|
|
|
// let the cells adjust themselves
|
|
|
|
InsetMathGrid::metrics(mi, dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the numbering interferes with the equations
|
|
|
|
if (numberedType()) {
|
|
|
|
BufferParams::MathNumber const math_number = buffer().params().getMathNumber();
|
|
|
|
int extra_offset = 0;
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
rowinfo(row).offset[mi.base.bv] += extra_offset;
|
|
|
|
if (!numbered(row))
|
|
|
|
continue;
|
|
|
|
docstring const nl = nicelabel(row);
|
|
|
|
Dimension dimnl;
|
|
|
|
mathed_string_dim(mi.base.font, nl, dimnl);
|
|
|
|
int const ind = indent(*mi.base.bv);
|
|
|
|
int const x = ind ? ind : (mi.base.textwidth - dim.wid) / 2;
|
|
|
|
// for some reason metrics does not trigger at the
|
|
|
|
// same point as draw, and therefore we use >= instead of >
|
|
|
|
if ((math_number == BufferParams::LEFT && dimnl.wid >= x)
|
|
|
|
|| (math_number == BufferParams::RIGHT
|
|
|
|
&& dimnl.wid >= mi.base.textwidth - x - dim.wid)) {
|
|
|
|
extra_offset += dimnl.height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dim.des += extra_offset;
|
|
|
|
}
|
2002-06-04 09:06:04 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2018-09-12 13:26:15 +00:00
|
|
|
if (display()) {
|
2020-08-25 11:05:29 +00:00
|
|
|
dim.asc += top_display_margin;
|
|
|
|
dim.des += bottom_display_margin;
|
2002-03-21 17:42:56 +00:00
|
|
|
}
|
2001-03-06 17:44:53 +00:00
|
|
|
|
2017-01-06 08:52:10 +00:00
|
|
|
// reserve some space for marker.
|
|
|
|
dim.wid += 2;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
2009-12-17 14:09:37 +00:00
|
|
|
ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const
|
|
|
|
{
|
2014-03-19 16:43:21 +00:00
|
|
|
BufferView const * const bv = pi.base.bv;
|
|
|
|
if (previewState(bv)) {
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2020-05-28 18:40:30 +00:00
|
|
|
if (previewTooSmall(dim))
|
2014-03-19 16:43:21 +00:00
|
|
|
return Color_error;
|
2009-12-17 15:21:08 +00:00
|
|
|
return graphics::PreviewLoader::backgroundColor();
|
2014-03-19 16:43:21 +00:00
|
|
|
}
|
2009-12-17 14:09:37 +00:00
|
|
|
return Color_mathbg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-19 21:32:32 +00:00
|
|
|
void InsetMathHull::drawMarkers(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
ColorCode pen_color = mouseHovered(pi.base.bv) || editing(pi.base.bv)?
|
|
|
|
Color_mathframe : Color_mathcorners;
|
|
|
|
// If the corners have the same color as the background, do not paint them.
|
2020-08-03 12:10:46 +00:00
|
|
|
if (lcolor.getX11HexName(Color_mathbg) == lcolor.getX11HexName(pen_color))
|
2017-12-19 21:32:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Inset::drawMarkers(pi, x, y);
|
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
int const t = x + dim.width() - 1;
|
|
|
|
int const a = y - dim.ascent();
|
|
|
|
pi.pain.line(x, a + 3, x, a, pen_color);
|
|
|
|
pi.pain.line(t, a + 3, t, a, pen_color);
|
|
|
|
pi.pain.line(x, a, x + 3, a, pen_color);
|
|
|
|
pi.pain.line(t - 3, a, t, a, pen_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2020-05-28 18:40:30 +00:00
|
|
|
if (previewTooSmall(dim)) {
|
2015-05-17 15:27:12 +00:00
|
|
|
pi.pain.fillRectangle(x, y - 2 * ERROR_FRAME_WIDTH,
|
2014-03-19 16:43:21 +00:00
|
|
|
dim.wid, dim.asc + dim.des, backgroundColor(pi));
|
|
|
|
return;
|
2015-05-17 15:27:12 +00:00
|
|
|
}
|
2019-07-15 11:02:05 +00:00
|
|
|
// If there are numbers, the margins around the (displayed)
|
|
|
|
// equation have to be cleared.
|
|
|
|
if (numberedType())
|
|
|
|
pi.pain.fillRectangle(pi.leftx, y - dim.asc,
|
|
|
|
pi.rightx - pi.leftx, dim.height(), pi.background_color);
|
2008-10-25 10:47:38 +00:00
|
|
|
pi.pain.fillRectangle(x + 1, y - dim.asc + 1, dim.wid - 2,
|
2014-05-07 18:18:14 +00:00
|
|
|
dim.asc + dim.des - 1, pi.backgroundColor(this));
|
2008-10-25 10:47:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 17:38:16 +00:00
|
|
|
|
2008-10-25 10:47:38 +00:00
|
|
|
void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2014-03-19 16:43:21 +00:00
|
|
|
BufferView const * const bv = pi.base.bv;
|
2016-05-23 14:06:26 +00:00
|
|
|
Dimension const dim = dimension(*bv);
|
2007-05-12 06:24:46 +00:00
|
|
|
|
2016-10-05 23:32:21 +00:00
|
|
|
if (type_ == hullRegexp)
|
|
|
|
pi.pain.rectangle(x + 2, y - dim.ascent() + 1,
|
|
|
|
dim.width() - 3, dim.height() - 2, Color_regexpframe);
|
2014-03-19 16:43:21 +00:00
|
|
|
|
2016-02-03 13:50:00 +00:00
|
|
|
if (previewState(bv)) {
|
2016-05-23 14:44:29 +00:00
|
|
|
// Do not draw change tracking cue if taken care of by RowPainter
|
|
|
|
// already.
|
2020-11-12 12:09:36 +00:00
|
|
|
Changer dummy = !canPaintChange(*bv) ? changeVar(pi.change, Change())
|
|
|
|
: noChange();
|
2020-05-28 18:40:30 +00:00
|
|
|
if (previewTooSmall(dim)) {
|
2014-03-19 16:43:21 +00:00
|
|
|
// we have an extra frame
|
|
|
|
preview_->draw(pi, x + ERROR_FRAME_WIDTH, y);
|
|
|
|
} else {
|
|
|
|
// one pixel gap in front
|
2018-02-19 17:24:29 +00:00
|
|
|
// value was hardcoded to 1 pixel
|
|
|
|
int const gap = pi.base.bv->zoomedPixels(1) ;
|
|
|
|
preview_->draw(pi, x + gap, y);
|
2014-03-19 16:43:21 +00:00
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:05:19 +00:00
|
|
|
// First draw the numbers
|
2010-09-13 01:36:00 +00:00
|
|
|
ColorCode color = pi.selected && lyxrc.use_system_colors
|
|
|
|
? Color_selectiontext : standardColor();
|
Index: src/mathed/InsetMathHull.cpp
===================================================================
--- src/mathed/InsetMathHull.cpp (revisione 34304)
+++ src/mathed/InsetMathHull.cpp (copia locale)
@@ -328,6 +328,23 @@ docstring InsetMathHull::standardFont()
}
+docstring InsetMathHull::standardColor() const
+{
+ docstring color;
+ switch (type_) {
+ case hullRegexp:
+ color = from_ascii("foreground");
+ break;
+ case hullNone:
+ color = from_ascii("foreground");
+ break;
+ default:
+ color = from_ascii("math");
+ }
+ return color;
+}
+
+
bool InsetMathHull::previewState(BufferView * bv) const
{
if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
@@ -417,8 +434,11 @@ void InsetMathHull::draw(PainterInfo & p
return;
}
+ bool const really_change_color = pi.base.font.color() == Color_none;
+ ColorChanger dummy0(pi.base.font, standardColor(), really_change_color);
FontSetChanger dummy1(pi.base, standardFont());
StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+
InsetMathGrid::draw(pi, x + 1, y);
if (numberedType()) {
Index: src/mathed/MathSupport.cpp
===================================================================
--- src/mathed/MathSupport.cpp (revisione 34311)
+++ src/mathed/MathSupport.cpp (copia locale)
@@ -653,6 +653,13 @@ bool isMathFont(docstring const & name)
}
+bool isTextFont(docstring const & name)
+{
+ fontinfo * f = lookupFont(name);
+ return f && f->color_ == Color_foreground;
+}
+
+
FontInfo getFont(docstring const & name)
{
FontInfo font;
Index: src/mathed/MathSupport.h
===================================================================
--- src/mathed/MathSupport.h (revisione 34311)
+++ src/mathed/MathSupport.h (copia locale)
@@ -51,6 +51,8 @@ bool isFontName(docstring const & name);
bool isMathFont(docstring const & name);
+bool isTextFont(docstring const & name);
+
// converts single cell to string
docstring asString(MathData const & ar);
// converts single inset to string
Index: src/mathed/InsetMathHull.h
===================================================================
--- src/mathed/InsetMathHull.h (revisione 34304)
+++ src/mathed/InsetMathHull.h (copia locale)
@@ -197,6 +197,8 @@ private:
void changeCols(col_type);
///
docstring standardFont() const;
+ ///
+ docstring standardColor() const;
/// consistency check
void check() const;
/// can this change its number of rows?
Index: src/MetricsInfo.cpp
===================================================================
--- src/MetricsInfo.cpp (revisione 34312)
+++ src/MetricsInfo.cpp (copia locale)
@@ -235,11 +235,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = name;
mb.font = sane_font;
augmentFont(mb.font, from_ascii(name));
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (string(name) != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -252,11 +256,15 @@ FontSetChanger::FontSetChanger(MetricsBa
save_ = mb;
FontSize oldsize = save_.font.size();
ColorCode oldcolor = save_.font.color();
+ docstring const oldname = from_ascii(save_.fontname);
mb.fontname = to_utf8(name);
mb.font = sane_font;
augmentFont(mb.font, name);
mb.font.setSize(oldsize);
- mb.font.setColor(oldcolor);
+ if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ mb.font.setColor(oldcolor);
}
}
@@ -294,17 +302,21 @@ WidthChanger::~WidthChanger()
//
/////////////////////////////////////////////////////////////////////////
-ColorChanger::ColorChanger(FontInfo & font, string const & color)
- : Changer<FontInfo, string>(font)
+ColorChanger::ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color)
+ : Changer<FontInfo, ColorCode>(font), change_(really_change_color)
{
- save_ = lcolor.getFromLyXName(color);
- font.setColor(lcolor.getFromLyXName(color));
+ if (change_) {
+ save_ = font.color();
+ font.setColor(lcolor.getFromLyXName(to_utf8(color)));
+ }
}
ColorChanger::~ColorChanger()
{
- orig_.setColor(lcolor.getFromLyXName(save_));
+ if (change_)
+ orig_.setColor(save_);
}
Index: src/MetricsInfo.h
===================================================================
--- src/MetricsInfo.h (revisione 34312)
+++ src/MetricsInfo.h (copia locale)
@@ -222,12 +222,16 @@ public:
// temporarily change the used color
-class ColorChanger : public Changer<FontInfo, std::string> {
+class ColorChanger : public Changer<FontInfo, ColorCode> {
public:
///
- ColorChanger(FontInfo & font, std::string const & color);
+ ColorChanger(FontInfo & font, docstring const & color,
+ bool really_change_color = true);
///
~ColorChanger();
+private:
+ ///
+ bool change_;
};
} // namespace lyx
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34320 a592a061-630c-0410-9148-cb99ea01b6c8
2010-04-28 01:40:11 +00:00
|
|
|
bool const really_change_color = pi.base.font.color() == Color_none;
|
2016-11-20 18:53:16 +00:00
|
|
|
Changer dummy0 = really_change_color ? pi.base.font.changeColor(color)
|
2020-11-12 12:09:36 +00:00
|
|
|
: noChange();
|
2019-07-14 19:04:45 +00:00
|
|
|
if (numberedType()) {
|
2019-04-02 09:05:19 +00:00
|
|
|
BufferParams::MathNumber const math_number = buffer().params().getMathNumber();
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
2019-07-14 19:04:45 +00:00
|
|
|
int yy = y + rowinfo(row).offset[bv];
|
2006-10-17 14:46:45 +00:00
|
|
|
docstring const nl = nicelabel(row);
|
2019-07-14 19:04:45 +00:00
|
|
|
Dimension dimnl;
|
|
|
|
mathed_string_dim(pi.base.font, nl, dimnl);
|
2019-04-02 09:05:19 +00:00
|
|
|
if (math_number == BufferParams::LEFT) {
|
2019-07-14 19:04:45 +00:00
|
|
|
if (dimnl.wid > x - pi.leftx)
|
|
|
|
yy += rowinfo(row).descent + dimnl.asc;
|
2019-04-02 09:05:19 +00:00
|
|
|
pi.draw(pi.leftx, yy, nl);
|
|
|
|
} else {
|
2019-07-14 19:04:45 +00:00
|
|
|
if (dimnl.wid > pi.rightx - x - dim.wid)
|
|
|
|
yy += rowinfo(row).descent + dimnl.asc;
|
|
|
|
pi.draw(pi.rightx - dimnl.wid, yy, nl);
|
2017-05-12 13:07:02 +00:00
|
|
|
}
|
2001-07-20 14:54:13 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
2017-05-12 13:07:02 +00:00
|
|
|
|
2019-04-02 09:05:19 +00:00
|
|
|
// Then the equations
|
|
|
|
Changer dummy1 = pi.base.changeFontSet(standardFont());
|
|
|
|
Changer dummy2 = pi.base.font.changeStyle(display() ? DISPLAY_STYLE
|
|
|
|
: TEXT_STYLE);
|
|
|
|
InsetMathGrid::draw(pi, x + 1, y);
|
|
|
|
drawMarkers(pi, x, y);
|
|
|
|
|
2016-05-23 14:06:26 +00:00
|
|
|
// drawing change line
|
2020-01-11 12:39:20 +00:00
|
|
|
if (canPaintChange(*bv)) {
|
|
|
|
// like in metrics()
|
|
|
|
int const display_margin = display() ? pi.base.inPixels(Length(12, Length::PT)) : 0;
|
2020-01-14 10:50:44 +00:00
|
|
|
pi.change.paintCue(pi, x + 1, y + 1 - dim.asc + display_margin,
|
2020-01-11 12:39:20 +00:00
|
|
|
x + dim.wid, y + dim.des - display_margin);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2002-05-02 07:30:49 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
2002-03-18 11:45:53 +00:00
|
|
|
{
|
2018-09-12 13:26:15 +00:00
|
|
|
if (display()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::metricsT(mi, dim);
|
2002-07-11 15:04:43 +00:00
|
|
|
} else {
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream os;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(os);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, true, WriteStream::wsDefault);
|
2002-05-02 07:30:49 +00:00
|
|
|
write(wi);
|
2003-05-28 13:22:36 +00:00
|
|
|
dim.wid = os.str().size();
|
|
|
|
dim.asc = 1;
|
|
|
|
dim.des = 0;
|
2002-05-02 07:30:49 +00:00
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
|
2002-03-18 11:45:53 +00:00
|
|
|
{
|
2018-09-12 13:26:15 +00:00
|
|
|
if (display()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::drawT(pain, x, y);
|
2002-07-11 15:04:43 +00:00
|
|
|
} else {
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream os;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(os);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, true, WriteStream::wsDefault);
|
2002-05-02 07:30:49 +00:00
|
|
|
write(wi);
|
|
|
|
pain.draw(x, y, os.str().c_str());
|
|
|
|
}
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 02:20:12 +00:00
|
|
|
static docstring latexString(InsetMathHull const & inset)
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream ls;
|
2009-06-16 21:22:32 +00:00
|
|
|
// This has to be static, because a preview snippet or a math
|
|
|
|
// macro containing math in text mode (such as $\text{$\phi$}$ or
|
|
|
|
// \newcommand{\xxx}{\text{$\phi$}}) gets processed twice. The
|
|
|
|
// first time as a whole, and the second time only the inner math.
|
|
|
|
// In this last case inset.buffer() would be invalid.
|
|
|
|
static Encoding const * encoding = 0;
|
2010-03-08 19:07:05 +00:00
|
|
|
if (inset.isBufferValid())
|
2009-06-16 21:22:32 +00:00
|
|
|
encoding = &(inset.buffer().params().encoding());
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(ls);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, true, WriteStream::wsPreview, encoding);
|
2010-07-22 02:20:12 +00:00
|
|
|
inset.write(wi);
|
2004-04-13 17:38:16 +00:00
|
|
|
return ls.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-26 15:53:15 +00:00
|
|
|
void InsetMathHull::initUnicodeMath() const
|
|
|
|
{
|
|
|
|
// Trigger classification of the unicode symbols in this inset
|
|
|
|
docstring const dummy = latexString(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-22 21:45:51 +00:00
|
|
|
void InsetMathHull::addPreview(DocIterator const & inset_pos,
|
2009-11-22 20:50:35 +00:00
|
|
|
graphics::PreviewLoader & /*ploader*/) const
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
2014-05-20 10:19:26 +00:00
|
|
|
if (RenderPreview::previewMath()) {
|
2009-12-05 00:43:28 +00:00
|
|
|
preparePreview(inset_pos);
|
2004-04-20 08:16:22 +00:00
|
|
|
}
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-14 16:10:29 +00:00
|
|
|
void InsetMathHull::usedMacros(MathData const & md, DocIterator const & pos,
|
|
|
|
MacroNameSet & macros, MacroNameSet & defs) const
|
|
|
|
{
|
|
|
|
MacroNameSet::iterator const end = macros.end();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < md.size(); ++i) {
|
2017-07-05 12:31:28 +00:00
|
|
|
InsetMathMacro const * mi = md[i].nucleus()->asMacro();
|
|
|
|
InsetMathMacroTemplate const * mt = md[i].nucleus()->asMacroTemplate();
|
2015-06-14 16:10:29 +00:00
|
|
|
InsetMathScript const * si = md[i].nucleus()->asScriptInset();
|
|
|
|
InsetMathFracBase const * fi = md[i].nucleus()->asFracBaseInset();
|
|
|
|
InsetMathGrid const * gi = md[i].nucleus()->asGridInset();
|
|
|
|
InsetMathNest const * ni = md[i].nucleus()->asNestInset();
|
|
|
|
if (mi) {
|
2015-06-20 01:05:50 +00:00
|
|
|
// Look for macros in the arguments of this macro.
|
|
|
|
for (idx_type idx = 0; idx < mi->nargs(); ++idx)
|
|
|
|
usedMacros(mi->cell(idx), pos, macros, defs);
|
2015-06-14 16:10:29 +00:00
|
|
|
// Make sure this is a macro defined in the document
|
|
|
|
// (as we also spot the macros in the symbols file)
|
|
|
|
// or that we have not already accounted for it.
|
|
|
|
docstring const name = mi->name();
|
|
|
|
if (macros.find(name) == end)
|
|
|
|
continue;
|
|
|
|
macros.erase(name);
|
2015-06-19 23:44:22 +00:00
|
|
|
// Look for macros in the definition of this macro.
|
2015-06-14 16:10:29 +00:00
|
|
|
MathData ar(pos.buffer());
|
|
|
|
MacroData const * data =
|
|
|
|
pos.buffer()->getMacro(name, pos, true);
|
|
|
|
if (data) {
|
|
|
|
odocstringstream macro_def;
|
|
|
|
data->write(macro_def, true);
|
|
|
|
macro_def << endl;
|
|
|
|
defs.insert(macro_def.str());
|
|
|
|
asArray(data->definition(), ar);
|
|
|
|
}
|
|
|
|
usedMacros(ar, pos, macros, defs);
|
2015-06-20 14:37:12 +00:00
|
|
|
} else if (mt) {
|
|
|
|
MathData ar(pos.buffer());
|
|
|
|
asArray(mt->definition(), ar);
|
|
|
|
usedMacros(ar, pos, macros, defs);
|
2015-06-14 16:10:29 +00:00
|
|
|
} else if (si) {
|
|
|
|
if (!si->nuc().empty())
|
|
|
|
usedMacros(si->nuc(), pos, macros, defs);
|
|
|
|
if (si->hasDown())
|
|
|
|
usedMacros(si->down(), pos, macros, defs);
|
|
|
|
if (si->hasUp())
|
|
|
|
usedMacros(si->up(), pos, macros, defs);
|
|
|
|
} else if (fi || gi) {
|
|
|
|
idx_type nidx = fi ? fi->nargs() : gi->nargs();
|
|
|
|
for (idx_type idx = 0; idx < nidx; ++idx)
|
|
|
|
usedMacros(fi ? fi->cell(idx) : gi->cell(idx),
|
|
|
|
pos, macros, defs);
|
|
|
|
} else if (ni) {
|
|
|
|
usedMacros(ni->cell(0), pos, macros, defs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 15:17:58 +00:00
|
|
|
void InsetMathHull::preparePreview(DocIterator const & pos,
|
2014-02-25 20:21:47 +00:00
|
|
|
bool forexport) const
|
2009-12-05 00:43:28 +00:00
|
|
|
{
|
2010-07-29 15:17:58 +00:00
|
|
|
// there is no need to do all the macro stuff if we're not
|
|
|
|
// actually going to generate the preview.
|
2014-05-20 10:19:26 +00:00
|
|
|
if (!RenderPreview::previewMath() && !forexport)
|
2010-07-29 15:17:58 +00:00
|
|
|
return;
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2010-07-20 19:45:36 +00:00
|
|
|
Buffer const * buffer = pos.buffer();
|
|
|
|
|
|
|
|
// collect macros at this position
|
|
|
|
MacroNameSet macros;
|
|
|
|
buffer->listMacroNames(macros);
|
2015-06-14 16:10:29 +00:00
|
|
|
|
|
|
|
// collect definitions only for the macros used in this inset
|
|
|
|
MacroNameSet defs;
|
|
|
|
for (idx_type idx = 0; idx < nargs(); ++idx)
|
|
|
|
usedMacros(cell(idx), pos, macros, defs);
|
|
|
|
|
|
|
|
docstring macro_preamble;
|
2017-12-16 14:30:12 +00:00
|
|
|
for (auto const & defvar : defs)
|
|
|
|
macro_preamble.append(defvar);
|
2009-11-22 20:50:35 +00:00
|
|
|
|
2015-10-03 16:13:20 +00:00
|
|
|
// set the font series and size for this snippet
|
2016-05-03 20:09:15 +00:00
|
|
|
DocIterator dit = pos.getInnerText();
|
2015-10-03 16:13:20 +00:00
|
|
|
Paragraph const & par = dit.paragraph();
|
|
|
|
Font font = par.getFontSettings(buffer->params(), dit.pos());
|
|
|
|
font.fontInfo().realize(par.layout().font);
|
|
|
|
string const lsize = font.latexSize();
|
|
|
|
docstring setfont;
|
|
|
|
docstring endfont;
|
|
|
|
if (font.fontInfo().series() == BOLD_SERIES) {
|
|
|
|
setfont += from_ascii("\\textbf{");
|
|
|
|
endfont += '}';
|
|
|
|
}
|
|
|
|
if (lsize != "normalsize" && !prefixIs(lsize, "error"))
|
2017-07-03 17:53:14 +00:00
|
|
|
setfont += from_ascii("\\" + lsize + '\n');
|
2015-10-03 16:13:20 +00:00
|
|
|
|
2011-01-12 16:04:59 +00:00
|
|
|
docstring setcnt;
|
|
|
|
if (forexport && haveNumbers()) {
|
|
|
|
docstring eqstr = from_ascii("equation");
|
|
|
|
CounterMap::const_iterator it = counter_map.find(eqstr);
|
|
|
|
if (it != counter_map.end()) {
|
|
|
|
int num = it->second;
|
|
|
|
if (num >= 0)
|
|
|
|
setcnt += from_ascii("\\setcounter{") + eqstr + '}' +
|
|
|
|
'{' + convert<docstring>(num) + '}' + '\n';
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i != numcnts; ++i) {
|
|
|
|
docstring cnt = from_ascii(counters_to_save[i]);
|
|
|
|
it = counter_map.find(cnt);
|
|
|
|
if (it == counter_map.end())
|
|
|
|
continue;
|
|
|
|
int num = it->second;
|
|
|
|
if (num > 0)
|
|
|
|
setcnt += from_ascii("\\setcounter{") + cnt + '}' +
|
|
|
|
'{' + convert<docstring>(num) + '}';
|
|
|
|
}
|
|
|
|
}
|
2015-10-03 16:13:20 +00:00
|
|
|
docstring const snippet = macro_preamble + setfont + setcnt
|
|
|
|
+ latexString(*this) + endfont;
|
2010-07-20 19:45:36 +00:00
|
|
|
LYXERR(Debug::MACROS, "Preview snippet: " << snippet);
|
2010-07-29 15:17:58 +00:00
|
|
|
preview_->addPreview(snippet, *buffer, forexport);
|
2009-12-05 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 15:17:58 +00:00
|
|
|
void InsetMathHull::reloadPreview(DocIterator const & pos) const
|
2009-12-05 01:07:38 +00:00
|
|
|
{
|
|
|
|
preparePreview(pos);
|
2010-07-29 15:17:58 +00:00
|
|
|
preview_->startLoading(*pos.buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMathHull::loadPreview(DocIterator const & pos) const
|
|
|
|
{
|
|
|
|
bool const forexport = true;
|
|
|
|
preparePreview(pos, forexport);
|
|
|
|
preview_->startLoading(*pos.buffer(), forexport);
|
2009-12-05 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 20:50:35 +00:00
|
|
|
|
|
|
|
bool InsetMathHull::notifyCursorLeaves(Cursor const & old, Cursor & cur)
|
2004-04-13 17:38:16 +00:00
|
|
|
{
|
2014-05-20 10:19:26 +00:00
|
|
|
if (RenderPreview::previewMath()) {
|
2009-12-05 01:07:38 +00:00
|
|
|
reloadPreview(old);
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.screenUpdateFlags(Update::Force);
|
2004-08-13 19:19:24 +00:00
|
|
|
}
|
2006-08-17 21:32:04 +00:00
|
|
|
return false;
|
2004-04-13 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring InsetMathHull::label(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(row < nrows(), return docstring());
|
2008-03-04 12:22:48 +00:00
|
|
|
if (InsetLabel * il = label_[row])
|
|
|
|
return il->screenLabel();
|
|
|
|
return docstring();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 08:48:23 +00:00
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathHull::label(row_type row, docstring const & label)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2002-08-08 14:22:44 +00:00
|
|
|
//lyxerr << "setting label '" << label << "' for row " << row << endl;
|
2008-03-04 12:22:48 +00:00
|
|
|
if (label_[row]) {
|
2008-03-09 23:43:05 +00:00
|
|
|
if (label.empty()) {
|
|
|
|
delete label_[row];
|
|
|
|
label_[row] = dummy_pointer;
|
2008-11-16 16:43:49 +00:00
|
|
|
} else {
|
2009-11-05 00:38:09 +00:00
|
|
|
if (buffer_)
|
2011-07-06 17:40:51 +00:00
|
|
|
label_[row]->updateLabelAndRefs(label);
|
2009-11-05 00:38:09 +00:00
|
|
|
else
|
|
|
|
label_[row]->setParam("name", label);
|
2008-11-16 16:43:49 +00:00
|
|
|
}
|
2008-03-04 12:22:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InsetCommandParams p(LABEL_CODE);
|
|
|
|
p["name"] = label;
|
2009-11-08 16:10:34 +00:00
|
|
|
label_[row] = new InsetLabel(buffer_, p);
|
2008-03-04 12:22:48 +00:00
|
|
|
if (buffer_)
|
|
|
|
label_[row]->setBuffer(buffer());
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 20:17:35 +00:00
|
|
|
void InsetMathHull::numbered(row_type row, Numbered num)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2010-10-24 17:27:32 +00:00
|
|
|
numbered_[row] = num;
|
2014-05-27 20:17:35 +00:00
|
|
|
if (!numbered(row) && label_[row]) {
|
2008-03-04 12:22:48 +00:00
|
|
|
delete label_[row];
|
|
|
|
label_[row] = 0;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::numbered(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2014-05-27 20:17:35 +00:00
|
|
|
return numbered_[row] == NUMBER;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::ams() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2014-05-27 20:17:35 +00:00
|
|
|
switch (type_) {
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
return true;
|
|
|
|
case hullUnknown:
|
|
|
|
case hullRegexp:
|
|
|
|
return false;
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
|
|
|
break;
|
2014-05-27 20:17:35 +00:00
|
|
|
}
|
2020-10-09 06:04:20 +00:00
|
|
|
for (auto const & row : numbered_)
|
|
|
|
if (row == NOTAG)
|
2014-05-27 20:17:35 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-19 22:06:42 +00:00
|
|
|
bool InsetMathHull::outerDisplay() const
|
|
|
|
{
|
|
|
|
switch (type_) {
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
|
|
|
return true;
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullUnknown:
|
|
|
|
case hullRegexp:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-22 21:11:40 +00:00
|
|
|
Inset::RowFlags InsetMathHull::rowFlags() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2015-12-14 01:54:27 +00:00
|
|
|
switch (type_) {
|
|
|
|
case hullUnknown:
|
|
|
|
case hullSimple:
|
|
|
|
case hullNone:
|
|
|
|
case hullRegexp:
|
2008-11-16 14:57:03 +00:00
|
|
|
return Inline;
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullEquation:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
2017-04-11 11:03:34 +00:00
|
|
|
if (buffer().params().is_math_indent)
|
2020-06-22 21:11:40 +00:00
|
|
|
return Display | AlignLeft;
|
2017-04-11 11:03:34 +00:00
|
|
|
else
|
2020-06-22 21:11:40 +00:00
|
|
|
return Display;
|
2015-12-14 01:54:27 +00:00
|
|
|
}
|
|
|
|
// avoid warning
|
2020-06-22 21:11:40 +00:00
|
|
|
return Display;
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-11 11:03:34 +00:00
|
|
|
|
|
|
|
int InsetMathHull::indent(BufferView const & bv) const
|
|
|
|
{
|
|
|
|
// FIXME: set this in the textclass. This value is what the article class uses.
|
|
|
|
static Length default_indent(2.5, Length::EM);
|
2020-06-22 21:11:40 +00:00
|
|
|
if (display() && buffer().params().is_math_indent) {
|
2017-04-11 11:03:34 +00:00
|
|
|
Length const & len = buffer().params().getMathIndent();
|
|
|
|
if (len.empty())
|
|
|
|
return bv.inPixels(default_indent);
|
|
|
|
else
|
|
|
|
return bv.inPixels(len);
|
|
|
|
} else
|
|
|
|
return Inset::indent(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::numberedType() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2015-12-14 01:54:27 +00:00
|
|
|
switch (type_) {
|
|
|
|
case hullUnknown:
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullRegexp:
|
2008-11-16 00:18:52 +00:00
|
|
|
return false;
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullEquation:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
break;
|
|
|
|
}
|
2001-09-26 16:52:34 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
2014-05-27 20:17:35 +00:00
|
|
|
if (numbered(row))
|
2001-06-25 00:06:33 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::validate(LaTeXFeatures & features) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2010-03-31 19:59:09 +00:00
|
|
|
if (features.runparams().isLaTeX()) {
|
|
|
|
if (ams())
|
|
|
|
features.require("amsmath");
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2016-10-19 22:06:42 +00:00
|
|
|
if (type_ == hullRegexp) {
|
2010-03-31 19:59:09 +00:00
|
|
|
features.require("color");
|
2016-09-25 10:37:40 +00:00
|
|
|
docstring frcol = from_utf8(lcolor.getLaTeXName(Color_regexpframe));
|
|
|
|
docstring bgcol = from_ascii("white");
|
2010-03-31 19:59:09 +00:00
|
|
|
features.addPreambleSnippet(
|
2016-09-25 10:37:40 +00:00
|
|
|
"\\newcommand{\\regexp}[1]{\\fcolorbox{"
|
|
|
|
+ frcol + "}{"
|
|
|
|
+ bgcol + "}{\\ensuremath{\\mathtt{#1}}}}");
|
2011-08-25 19:16:14 +00:00
|
|
|
features.addPreambleSnippet(
|
2016-09-25 10:37:40 +00:00
|
|
|
from_ascii("\\newcommand{\\endregexp}{}"));
|
2020-01-13 07:59:26 +00:00
|
|
|
} else if (outerDisplay() && features.inDeletedInset()) {
|
2019-12-28 12:43:17 +00:00
|
|
|
features.require("tikz");
|
2019-12-26 06:15:37 +00:00
|
|
|
features.require("ct-tikz-object-sout");
|
2010-03-31 19:59:09 +00:00
|
|
|
}
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2010-03-31 19:59:09 +00:00
|
|
|
// Validation is necessary only if not using AMS math.
|
|
|
|
// To be safe, we will always run mathedvalidate.
|
|
|
|
//if (features.amsstyle)
|
|
|
|
// return;
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2010-03-31 19:59:09 +00:00
|
|
|
//features.binom = true;
|
|
|
|
} else if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
|
|
|
|
// it would be better to do this elsewhere, but we can't validate in
|
|
|
|
// InsetMathMatrix and we have no way, outside MathExtern, to know if
|
|
|
|
// we even have any matrices.
|
2011-12-06 22:17:13 +00:00
|
|
|
features.addCSSSnippet(
|
2010-03-31 19:59:09 +00:00
|
|
|
"table.matrix{display: inline-block; vertical-align: middle; text-align:center;}\n"
|
|
|
|
"table.matrix td{padding: 0.25px;}\n"
|
|
|
|
"td.ldelim{width: 0.5ex; border: thin solid black; border-right: none;}\n"
|
2011-12-06 22:17:13 +00:00
|
|
|
"td.rdelim{width: 0.5ex; border: thin solid black; border-left: none;}");
|
2010-02-05 18:34:01 +00:00
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::validate(features);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-28 12:43:17 +00:00
|
|
|
OutputParams::CtObject InsetMathHull::CtObject(OutputParams const & runparams) const
|
|
|
|
{
|
|
|
|
OutputParams::CtObject res = OutputParams::CT_NORMAL;
|
|
|
|
switch(type_) {
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullRegexp:
|
|
|
|
case hullUnknown:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline: {
|
|
|
|
if (runparams.inulemcmd
|
|
|
|
&& (!runparams.local_font || runparams.local_font->fontInfo().strikeout() != FONT_ON))
|
|
|
|
res = OutputParams::CT_UDISPLAYOBJECT;
|
|
|
|
else
|
|
|
|
res = OutputParams::CT_DISPLAYOBJECT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::header_write(WriteStream & os) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
2015-10-11 13:50:32 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
switch(type_) {
|
|
|
|
case hullNone:
|
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullSimple:
|
2016-10-20 23:35:39 +00:00
|
|
|
if (os.ulemCmd())
|
|
|
|
os << "\\mbox{";
|
2002-07-03 10:36:44 +00:00
|
|
|
os << '$';
|
2015-10-07 03:13:21 +00:00
|
|
|
os.startOuterRow();
|
2002-07-03 10:36:44 +00:00
|
|
|
if (cell(0).empty())
|
|
|
|
os << ' ';
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullEquation:
|
2016-10-24 22:49:26 +00:00
|
|
|
writeMathdisplayPreamble(os);
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
2002-07-03 10:36:44 +00:00
|
|
|
if (n)
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\\begin{equation" << star(n) << "}\n";
|
2002-07-03 10:36:44 +00:00
|
|
|
else
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\\[\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
2016-10-24 22:49:26 +00:00
|
|
|
writeMathdisplayPreamble(os);
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\begin{" << hullName(type_) << star(n) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\begin{" << hullName(type_) << star(n) << '}'
|
2002-11-27 10:30:28 +00:00
|
|
|
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2002-08-14 18:31:53 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullXXAlignAt:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\begin{" << hullName(type_) << '}'
|
2002-11-27 10:30:28 +00:00
|
|
|
<< '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2002-08-14 18:31:53 +00:00
|
|
|
|
2008-11-16 00:18:52 +00:00
|
|
|
case hullRegexp:
|
2011-08-25 19:16:14 +00:00
|
|
|
os << "\\regexp{";
|
2008-11-16 00:18:52 +00:00
|
|
|
break;
|
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullUnknown:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\begin{unknown" << star(n) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::footer_write(WriteStream & os) const
|
2002-07-03 10:36:44 +00:00
|
|
|
{
|
|
|
|
bool n = numberedType();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
switch(type_) {
|
|
|
|
case hullNone:
|
2002-07-03 10:36:44 +00:00
|
|
|
os << "\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullSimple:
|
2002-07-03 10:36:44 +00:00
|
|
|
os << '$';
|
2016-10-20 23:35:39 +00:00
|
|
|
if (os.ulemCmd())
|
|
|
|
os << "}";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-10-03 07:56:27 +00:00
|
|
|
case hullEquation:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
2002-07-03 10:36:44 +00:00
|
|
|
if (n)
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\\end{equation" << star(n) << "}\n";
|
2002-07-03 10:36:44 +00:00
|
|
|
else
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\\]\n";
|
2016-10-24 22:49:26 +00:00
|
|
|
writeMathdisplayPostamble(os);
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
2016-10-17 01:25:35 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\end{" << hullName(type_) << star(n) << "}\n";
|
2016-10-24 22:49:26 +00:00
|
|
|
writeMathdisplayPostamble(os);
|
2016-10-17 01:25:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\end{" << hullName(type_) << star(n) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case hullXXAlignAt:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\end{" << hullName(type_) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
|
2008-11-16 00:18:52 +00:00
|
|
|
case hullRegexp:
|
2011-08-25 19:16:14 +00:00
|
|
|
// Only used as a heuristic to find the regexp termination, when searching in ignore-format mode
|
|
|
|
os << "\\endregexp{}}";
|
2008-11-16 00:18:52 +00:00
|
|
|
break;
|
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullUnknown:
|
2015-10-07 03:13:21 +00:00
|
|
|
os << "\n";
|
|
|
|
os.startOuterRow();
|
|
|
|
os << "\\end{unknown" << star(n) << "}\n";
|
2006-10-03 07:56:27 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 13:50:51 +00:00
|
|
|
bool InsetMathHull::allowsTabularFeatures() const
|
2015-12-11 20:45:57 +00:00
|
|
|
{
|
|
|
|
switch (type_) {
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
return true;
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullRegexp:
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullUnknown:
|
2015-12-11 20:45:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::rowChangeOK() const
|
2004-11-23 14:43:37 +00:00
|
|
|
{
|
|
|
|
return
|
2006-09-03 16:14:51 +00:00
|
|
|
type_ == hullEqnArray || type_ == hullAlign ||
|
|
|
|
type_ == hullFlAlign || type_ == hullAlignAt ||
|
|
|
|
type_ == hullXAlignAt || type_ == hullXXAlignAt ||
|
|
|
|
type_ == hullGather || type_ == hullMultline;
|
2004-11-23 14:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::colChangeOK() const
|
2002-08-21 13:47:52 +00:00
|
|
|
{
|
2002-08-29 06:49:27 +00:00
|
|
|
return
|
2006-09-03 16:14:51 +00:00
|
|
|
type_ == hullAlign || type_ == hullFlAlign ||type_ == hullAlignAt ||
|
|
|
|
type_ == hullXAlignAt || type_ == hullXXAlignAt;
|
2002-08-21 13:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::addRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (!rowChangeOK())
|
|
|
|
return;
|
2008-03-11 17:54:05 +00:00
|
|
|
|
|
|
|
bool numbered = numberedType();
|
2011-05-08 11:19:55 +00:00
|
|
|
// Move the number and raw pointer, do not call label() (bug 7511)
|
|
|
|
InsetLabel * label = dummy_pointer;
|
|
|
|
docstring number = empty_docstring();
|
2008-03-11 17:54:05 +00:00
|
|
|
if (type_ == hullMultline) {
|
2008-05-06 06:41:08 +00:00
|
|
|
if (row + 1 == nrows()) {
|
2014-05-27 20:17:35 +00:00
|
|
|
numbered_[row] = NONUMBER;
|
2018-09-18 21:06:36 +00:00
|
|
|
swap(label, label_[row]);
|
|
|
|
swap(number, numbers_[row]);
|
2008-05-06 06:41:08 +00:00
|
|
|
} else
|
2008-03-11 17:54:05 +00:00
|
|
|
numbered = false;
|
|
|
|
}
|
|
|
|
|
2014-05-27 20:17:35 +00:00
|
|
|
numbered_.insert(numbered_.begin() + row + 1, numbered ? NUMBER : NONUMBER);
|
2011-05-08 11:19:55 +00:00
|
|
|
numbers_.insert(numbers_.begin() + row + 1, number);
|
|
|
|
label_.insert(label_.begin() + row + 1, label);
|
2007-11-05 20:54:28 +00:00
|
|
|
InsetMathGrid::addRow(row);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::swapRow(row_type row)
|
2003-10-06 09:57:03 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (nrows() <= 1)
|
2003-10-06 09:57:03 +00:00
|
|
|
return;
|
|
|
|
if (row + 1 == nrows())
|
|
|
|
--row;
|
2018-09-18 21:06:36 +00:00
|
|
|
swap(numbered_[row], numbered_[row + 1]);
|
|
|
|
swap(numbers_[row], numbers_[row + 1]);
|
|
|
|
swap(label_[row], label_[row + 1]);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::swapRow(row);
|
2003-10-06 09:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::delRow(row_type row)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (nrows() <= 1 || !rowChangeOK())
|
2002-08-19 10:11:13 +00:00
|
|
|
return;
|
2008-05-06 06:41:08 +00:00
|
|
|
if (row + 1 == nrows() && type_ == hullMultline) {
|
2018-09-18 21:06:36 +00:00
|
|
|
swap(numbered_[row - 1], numbered_[row]);
|
|
|
|
swap(numbers_[row - 1], numbers_[row]);
|
|
|
|
swap(label_[row - 1], label_[row]);
|
2008-05-06 06:41:08 +00:00
|
|
|
InsetMathGrid::delRow(row);
|
|
|
|
return;
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::delRow(row);
|
2005-10-14 10:50:23 +00:00
|
|
|
// The last dummy row has no number info nor a label.
|
|
|
|
// Test nrows() + 1 because we have already erased the row.
|
|
|
|
if (row == nrows() + 1)
|
|
|
|
row--;
|
2010-10-24 17:27:32 +00:00
|
|
|
numbered_.erase(numbered_.begin() + row);
|
2011-01-11 19:35:52 +00:00
|
|
|
numbers_.erase(numbers_.begin() + row);
|
2008-03-06 19:31:14 +00:00
|
|
|
delete label_[row];
|
2001-06-25 00:06:33 +00:00
|
|
|
label_.erase(label_.begin() + row);
|
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::addCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (!colChangeOK())
|
|
|
|
return;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::addCol(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 13:32:06 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::delCol(col_type col)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2004-11-23 14:43:37 +00:00
|
|
|
if (ncols() <= 1 || !colChangeOK())
|
|
|
|
return;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::delCol(col);
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 14:46:45 +00:00
|
|
|
docstring InsetMathHull::nicelabel(row_type row) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2014-05-27 20:17:35 +00:00
|
|
|
if (!numbered(row))
|
2006-10-17 14:46:45 +00:00
|
|
|
return docstring();
|
2011-01-11 19:35:52 +00:00
|
|
|
docstring const & val = numbers_[row];
|
2008-03-04 12:22:48 +00:00
|
|
|
if (!label_[row])
|
2011-01-11 19:35:52 +00:00
|
|
|
return '(' + val + ')';
|
|
|
|
return '(' + val + ',' + label_[row]->screenLabel() + ')';
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-19 13:58:36 +00:00
|
|
|
void InsetMathHull::glueall(HullType type)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar;
|
2001-09-26 16:52:34 +00:00
|
|
|
for (idx_type i = 0; i < nargs(); ++i)
|
2002-07-30 13:56:02 +00:00
|
|
|
ar.append(cell(i));
|
2010-08-19 13:58:36 +00:00
|
|
|
InsetLabel * label = 0;
|
|
|
|
if (type == hullEquation) {
|
2010-08-19 22:50:06 +00:00
|
|
|
// preserve first non-empty label
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (label_[row]) {
|
|
|
|
label = label_[row];
|
|
|
|
label_[row] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-19 13:58:36 +00:00
|
|
|
}
|
2009-11-08 11:45:46 +00:00
|
|
|
*this = InsetMathHull(buffer_, hullSimple);
|
2010-10-25 21:36:25 +00:00
|
|
|
label_[0] = label;
|
2001-06-25 00:06:33 +00:00
|
|
|
cell(0) = ar;
|
2002-07-03 10:36:44 +00:00
|
|
|
setDefaults();
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 13:28:45 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::splitTo2Cols()
|
2004-09-13 18:14:37 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(ncols() == 1, return);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::addCol(1);
|
2004-09-13 18:14:37 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type const i = 2 * row;
|
|
|
|
pos_type pos = firstRelOp(cell(i));
|
2009-11-08 11:45:46 +00:00
|
|
|
cell(i + 1) = MathData(buffer_, cell(i).begin() + pos, cell(i).end());
|
2004-09-13 18:14:37 +00:00
|
|
|
cell(i).erase(pos, cell(i).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::splitTo3Cols()
|
2004-09-13 18:14:37 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(ncols() < 3, return);
|
2004-09-13 18:14:37 +00:00
|
|
|
if (ncols() < 2)
|
|
|
|
splitTo2Cols();
|
2007-10-13 15:48:22 +00:00
|
|
|
InsetMathGrid::addCol(2);
|
2004-09-13 18:14:37 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type const i = 3 * row + 1;
|
2012-10-21 19:14:16 +00:00
|
|
|
if (!cell(i).empty()) {
|
2009-11-08 11:45:46 +00:00
|
|
|
cell(i + 1) = MathData(buffer_, cell(i).begin() + 1, cell(i).end());
|
2004-09-13 18:14:37 +00:00
|
|
|
cell(i).erase(1, cell(i).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::changeCols(col_type cols)
|
2004-09-13 18:14:37 +00:00
|
|
|
{
|
|
|
|
if (ncols() == cols)
|
|
|
|
return;
|
|
|
|
else if (ncols() < cols) {
|
|
|
|
// split columns
|
|
|
|
if (cols < 3)
|
|
|
|
splitTo2Cols();
|
|
|
|
else {
|
|
|
|
splitTo3Cols();
|
|
|
|
while (ncols() < cols)
|
2007-10-13 15:48:22 +00:00
|
|
|
InsetMathGrid::addCol(ncols());
|
2004-09-13 18:14:37 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// combine columns
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
idx_type const i = row * ncols();
|
|
|
|
for (col_type col = cols; col < ncols(); ++col) {
|
|
|
|
cell(i + cols - 1).append(cell(i + col));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// delete columns
|
|
|
|
while (ncols() > cols) {
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::delCol(ncols() - 1);
|
2004-09-13 18:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
HullType InsetMathHull::getType() const
|
2001-08-01 13:28:45 +00:00
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
return type_;
|
2001-08-01 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::setType(HullType type)
|
2001-08-01 13:28:45 +00:00
|
|
|
{
|
2002-07-03 10:36:44 +00:00
|
|
|
type_ = type;
|
2001-09-04 13:32:06 +00:00
|
|
|
setDefaults();
|
2001-08-01 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
bool InsetMathHull::isMutable(HullType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullXXAlignAt:
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
return true;
|
|
|
|
case hullUnknown:
|
|
|
|
case hullRegexp:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// avoid warning
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::mutate(HullType newtype)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2005-07-15 08:51:34 +00:00
|
|
|
//lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
if (newtype == type_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// This guards the algorithm below it, which is designed with certain types
|
|
|
|
// in mind.
|
|
|
|
if (!isMutable(newtype) || !isMutable(type_)) {
|
|
|
|
lyxerr << "mutation from '" << to_utf8(hullName(type_))
|
|
|
|
<< "' to '" << to_utf8(hullName(newtype))
|
|
|
|
<< "' not implemented" << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-03 10:36:44 +00:00
|
|
|
// we try to move along the chain
|
2004-09-13 18:14:37 +00:00
|
|
|
// none <-> simple <-> equation <-> eqnarray -> *align* -> multline, gather -+
|
|
|
|
// ^ |
|
|
|
|
// +-------------------------------------+
|
|
|
|
// we use eqnarray as intermediate type for mutations that are not
|
|
|
|
// directly supported because it handles labels and numbering for
|
|
|
|
// "down mutation".
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
switch (type_) {
|
|
|
|
case hullNone:
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullSimple);
|
2002-07-03 10:36:44 +00:00
|
|
|
numbered(0, false);
|
2003-05-02 07:52:15 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2001-08-07 12:02:21 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullSimple:
|
2006-09-03 16:14:51 +00:00
|
|
|
if (newtype == hullNone) {
|
|
|
|
setType(hullNone);
|
2004-09-13 18:14:37 +00:00
|
|
|
numbered(0, false);
|
2003-05-02 07:52:15 +00:00
|
|
|
} else {
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullEquation);
|
2020-10-05 10:38:09 +00:00
|
|
|
numbered(0, label_[0] != nullptr);
|
2003-05-02 07:52:15 +00:00
|
|
|
mutate(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2001-07-09 16:59:57 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullEquation:
|
|
|
|
switch (newtype) {
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullSimple);
|
2004-09-13 18:14:37 +00:00
|
|
|
numbered(0, false);
|
2002-07-03 10:36:44 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullEqnArray:
|
2004-09-13 18:14:37 +00:00
|
|
|
// split it "nicely" on the first relop
|
|
|
|
splitTo3Cols();
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullEqnArray);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
2002-08-08 16:08:11 +00:00
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// *align*
|
2002-07-03 10:36:44 +00:00
|
|
|
// split it "nicely"
|
2004-09-13 18:14:37 +00:00
|
|
|
splitTo2Cols();
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullAlign);
|
2002-07-03 10:36:44 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullEqnArray:
|
|
|
|
switch (newtype) {
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
2010-08-19 13:58:36 +00:00
|
|
|
glueall(newtype);
|
2002-07-03 10:36:44 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// align & Co.
|
2004-09-13 18:14:37 +00:00
|
|
|
changeCols(2);
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullAlign);
|
2002-07-03 10:36:44 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
|
|
|
case hullFlAlign:
|
|
|
|
switch (newtype) {
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
2004-09-13 18:14:37 +00:00
|
|
|
changeCols(3);
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullEqnArray);
|
2002-07-03 10:36:44 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
2004-09-13 18:14:37 +00:00
|
|
|
changeCols(1);
|
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullXXAlignAt:
|
2004-09-13 18:14:37 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
numbered(row, false);
|
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-07-03 10:36:44 +00:00
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2001-09-04 14:56:30 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullXXAlignAt:
|
2004-09-13 18:14:37 +00:00
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
numbered(row, false);
|
2015-12-14 01:54:27 +00:00
|
|
|
switch (newtype) {
|
|
|
|
case hullNone:
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
2004-09-13 18:14:37 +00:00
|
|
|
changeCols(3);
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullEqnArray);
|
2004-09-13 18:14:37 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
2004-09-13 18:14:37 +00:00
|
|
|
changeCols(1);
|
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-09-13 18:14:37 +00:00
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
case hullMultline:
|
|
|
|
case hullGather:
|
|
|
|
switch (newtype) {
|
|
|
|
case hullGather:
|
|
|
|
case hullMultline:
|
2004-09-13 18:14:37 +00:00
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullAlign:
|
|
|
|
case hullFlAlign:
|
|
|
|
case hullAlignAt:
|
|
|
|
case hullXAlignAt:
|
2004-09-13 18:14:37 +00:00
|
|
|
splitTo2Cols();
|
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
case hullXXAlignAt:
|
2004-09-13 18:14:37 +00:00
|
|
|
splitTo2Cols();
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
numbered(row, false);
|
2004-08-13 21:21:10 +00:00
|
|
|
setType(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// first we mutate to EqnArray
|
2004-09-13 18:14:37 +00:00
|
|
|
splitTo3Cols();
|
2006-09-03 16:14:51 +00:00
|
|
|
setType(hullEqnArray);
|
2004-09-13 18:14:37 +00:00
|
|
|
mutate(newtype);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2002-07-03 10:36:44 +00:00
|
|
|
}
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
2001-09-04 14:56:30 +00:00
|
|
|
|
2015-12-14 01:54:27 +00:00
|
|
|
default:
|
|
|
|
// we passed the guard so we should not be here
|
2017-12-16 04:41:32 +00:00
|
|
|
LYXERR0("Mutation not implemented, but should have been.");
|
|
|
|
LASSERT(false, return);
|
2015-12-14 01:54:27 +00:00
|
|
|
break;
|
|
|
|
}// switch
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
|
2010-11-06 02:53:29 +00:00
|
|
|
docstring InsetMathHull::eolString(row_type row, bool fragile, bool latex,
|
|
|
|
bool last_eoln) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring res;
|
2002-08-15 17:41:24 +00:00
|
|
|
if (numberedType()) {
|
2014-05-27 20:17:35 +00:00
|
|
|
if (label_[row] && numbered(row)) {
|
2010-11-06 02:53:29 +00:00
|
|
|
docstring const name =
|
|
|
|
latex ? escape(label_[row]->getParam("name"))
|
|
|
|
: label_[row]->getParam("name");
|
|
|
|
res += "\\label{" + name + '}';
|
|
|
|
}
|
2014-05-27 20:17:35 +00:00
|
|
|
if (type_ != hullMultline) {
|
|
|
|
if (numbered_[row] == NONUMBER)
|
|
|
|
res += "\\nonumber ";
|
|
|
|
else if (numbered_[row] == NOTAG)
|
|
|
|
res += "\\notag ";
|
|
|
|
}
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
2010-07-04 16:31:53 +00:00
|
|
|
// Never add \\ on the last empty line of eqnarray and friends
|
|
|
|
last_eoln = false;
|
2010-11-06 02:53:29 +00:00
|
|
|
return res + InsetMathGrid::eolString(row, fragile, latex, last_eoln);
|
2002-08-15 17:41:24 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 02:20:12 +00:00
|
|
|
void InsetMathHull::write(WriteStream & os) const
|
2002-08-15 17:41:24 +00:00
|
|
|
{
|
2013-08-24 16:42:14 +00:00
|
|
|
ModeSpecifier specifier(os, MATH_MODE);
|
2010-07-22 02:20:12 +00:00
|
|
|
header_write(os);
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::write(os);
|
2010-07-22 02:20:12 +00:00
|
|
|
footer_write(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::normalize(NormalStream & os) const
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2006-10-03 07:56:27 +00:00
|
|
|
os << "[formula " << hullName(type_) << ' ';
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::normalize(os);
|
2001-11-08 12:06:56 +00:00
|
|
|
os << "] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathHull::infoize(odocstream & os) const
|
2002-05-30 07:09:54 +00:00
|
|
|
{
|
2014-11-14 17:18:30 +00:00
|
|
|
os << bformat(_("Type: %1$s"), hullName(type_));
|
2002-05-30 07:09:54 +00:00
|
|
|
}
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::check() const
|
2001-12-11 15:04:02 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(numbered_.size() == nrows());
|
|
|
|
LATTEST(numbers_.size() == nrows());
|
|
|
|
LATTEST(label_.size() == nrows());
|
2001-12-11 15:04:02 +00:00
|
|
|
}
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
|
2002-08-14 16:43:16 +00:00
|
|
|
{
|
2018-06-05 09:24:05 +00:00
|
|
|
//FIXME: sort out whether we want std::string or docstring for those
|
|
|
|
string const lang = func.getArg(0);
|
|
|
|
docstring extra = from_utf8(func.getArg(1));
|
2002-08-14 16:43:16 +00:00
|
|
|
if (extra.empty())
|
2006-10-21 00:16:43 +00:00
|
|
|
extra = from_ascii("noextra");
|
2002-08-14 16:43:16 +00:00
|
|
|
|
2014-11-09 20:56:40 +00:00
|
|
|
// replace selection with result of computation
|
|
|
|
if (reduceSelectionToOneCell(cur)) {
|
|
|
|
MathData ar;
|
|
|
|
asArray(grabAndEraseSelection(cur), ar);
|
|
|
|
lyxerr << "use selection: " << ar << endl;
|
|
|
|
cur.insert(pipeThroughExtern(lang, extra, ar));
|
|
|
|
return;
|
|
|
|
}
|
2002-08-14 16:43:16 +00:00
|
|
|
|
2010-11-23 15:36:58 +00:00
|
|
|
// only inline, display or eqnarray math is allowed
|
2015-12-14 01:54:27 +00:00
|
|
|
switch (getType()) {
|
|
|
|
case hullSimple:
|
|
|
|
case hullEquation:
|
|
|
|
case hullEqnArray:
|
|
|
|
break;
|
|
|
|
default:
|
2010-11-23 15:36:58 +00:00
|
|
|
frontend::Alert::warning(_("Bad math environment"),
|
|
|
|
_("Computation cannot be performed for AMS "
|
|
|
|
"math environments.\nChange the math "
|
|
|
|
"formula type and try again."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData eq;
|
2006-09-16 18:11:38 +00:00
|
|
|
eq.push_back(MathAtom(new InsetMathChar('=')));
|
2002-08-14 16:43:16 +00:00
|
|
|
|
|
|
|
// go to first item in line
|
2004-01-15 17:34:44 +00:00
|
|
|
cur.idx() -= cur.idx() % ncols();
|
|
|
|
cur.pos() = 0;
|
2002-08-14 16:43:16 +00:00
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
if (getType() == hullSimple) {
|
2004-01-15 17:34:44 +00:00
|
|
|
size_type pos = cur.cell().find_last(eq);
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar;
|
2014-11-09 20:56:40 +00:00
|
|
|
if (pos == cur.cell().size()) {
|
2004-01-15 17:34:44 +00:00
|
|
|
ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use whole cell: " << ar << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
} else {
|
2009-11-08 11:45:46 +00:00
|
|
|
ar = MathData(buffer_, cur.cell().begin() + pos + 1, cur.cell().end());
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use partial cell form pos: " << pos << endl;
|
2002-08-14 16:43:16 +00:00
|
|
|
}
|
2004-01-15 17:34:44 +00:00
|
|
|
cur.cell().append(eq);
|
|
|
|
cur.cell().append(pipeThroughExtern(lang, extra, ar));
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-14 16:43:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
if (getType() == hullEquation) {
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use equation inset" << endl;
|
2006-09-03 16:14:51 +00:00
|
|
|
mutate(hullEqnArray);
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use cell: " << ar << endl;
|
2004-01-15 17:34:44 +00:00
|
|
|
++cur.idx();
|
|
|
|
cur.cell() = eq;
|
|
|
|
++cur.idx();
|
|
|
|
cur.cell() = pipeThroughExtern(lang, extra, ar);
|
2002-08-14 16:43:16 +00:00
|
|
|
// move to end of line
|
2004-01-15 17:34:44 +00:00
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-14 16:43:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use eqnarray" << endl;
|
2004-01-15 17:34:44 +00:00
|
|
|
cur.idx() += 2 - cur.idx() % ncols();
|
|
|
|
cur.pos() = 0;
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData ar = cur.cell();
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "use cell: " << ar << endl;
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: temporarily disabled
|
2007-11-05 20:54:28 +00:00
|
|
|
addRow(cur.row());
|
2004-01-15 17:34:44 +00:00
|
|
|
++cur.idx();
|
|
|
|
++cur.idx();
|
|
|
|
cur.cell() = eq;
|
|
|
|
++cur.idx();
|
|
|
|
cur.cell() = pipeThroughExtern(lang, extra, ar);
|
|
|
|
cur.pos() = cur.lastpos();
|
2002-08-14 16:43:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-08-13 17:43:40 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
//lyxerr << "action: " << cmd.action() << endl;
|
|
|
|
switch (cmd.action()) {
|
2002-08-13 17:43:40 +00:00
|
|
|
|
2007-10-22 22:18:52 +00:00
|
|
|
case LFUN_FINISHED_BACKWARD:
|
|
|
|
case LFUN_FINISHED_FORWARD:
|
2008-02-10 19:57:00 +00:00
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
case LFUN_FINISHED_LEFT:
|
2010-04-09 19:00:42 +00:00
|
|
|
//lyxerr << "action: " << cmd.action() << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
2004-04-13 17:38:16 +00:00
|
|
|
break;
|
|
|
|
|
2012-09-29 16:06:42 +00:00
|
|
|
case LFUN_PARAGRAPH_BREAK:
|
2004-04-08 15:41:48 +00:00
|
|
|
// just swallow this
|
|
|
|
break;
|
|
|
|
|
2008-03-26 08:10:01 +00:00
|
|
|
case LFUN_NEWLINE_INSERT:
|
2004-08-12 20:52:43 +00:00
|
|
|
// some magic for the common case
|
2006-09-03 16:14:51 +00:00
|
|
|
if (type_ == hullSimple || type_ == hullEquation) {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2005-07-14 23:36:49 +00:00
|
|
|
bool const align =
|
2015-12-10 21:14:05 +00:00
|
|
|
cur.bv().buffer().params().use_package("amsmath") != BufferParams::package_off;
|
2006-09-03 16:14:51 +00:00
|
|
|
mutate(align ? hullAlign : hullEqnArray);
|
2010-07-09 14:37:00 +00:00
|
|
|
// mutate() may change labels and such.
|
|
|
|
cur.forceBufferUpdate();
|
2007-10-11 17:12:34 +00:00
|
|
|
cur.idx() = nrows() * ncols() - 1;
|
2004-04-18 19:41:40 +00:00
|
|
|
cur.pos() = cur.lastpos();
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_TOGGLE: {
|
2004-02-16 11:58:51 +00:00
|
|
|
//lyxerr << "toggling all numbers" << endl;
|
2008-01-03 17:31:12 +00:00
|
|
|
cur.recordUndoInset();
|
|
|
|
bool old = numberedType();
|
|
|
|
if (type_ == hullMultline)
|
|
|
|
numbered(nrows() - 1, !old);
|
|
|
|
else
|
|
|
|
for (row_type row = 0; row < nrows(); ++row)
|
|
|
|
numbered(row, !old);
|
2008-10-13 11:25:37 +00:00
|
|
|
|
2008-01-03 17:31:12 +00:00
|
|
|
cur.message(old ? _("No number") : _("Number"));
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2008-01-03 17:31:12 +00:00
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_LINE_TOGGLE: {
|
2008-01-03 17:31:12 +00:00
|
|
|
cur.recordUndoInset();
|
|
|
|
row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
|
|
|
bool old = numbered(r);
|
|
|
|
cur.message(old ? _("No number") : _("Number"));
|
|
|
|
numbered(r, !old);
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2008-01-03 17:31:12 +00:00
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_LABEL_INSERT: {
|
2006-09-03 16:14:51 +00:00
|
|
|
row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring old_label = label(r);
|
2010-03-17 12:50:58 +00:00
|
|
|
docstring const default_label = from_ascii("eq:");
|
2006-01-10 12:49:34 +00:00
|
|
|
if (old_label.empty())
|
|
|
|
old_label = default_label;
|
2005-07-17 16:36:21 +00:00
|
|
|
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(LABEL_CODE);
|
Rework InsetCommandParams interface and file storage
* src/insets/insetcommandparams.[Ch]:
(operator[]): New, access a parameter
(clear): New, clear all parameters
(info_): New, stire info about this command
(cmdname): Rename to name_
(contents, options, sec_options): Replace with params_. Parameters
are now stored as docstring.
(findInfo): New factor for command info for all commands
(read, write): Use new syntax
(parameter set and get methods): reimplemenmt for new parameter storage
* src/insets/insetcommand.h
(getParam): New, get a parameter
(setParam): New, set a parameter
(parameter set and get methods): Adjust to InsetCommandParams changes
* src/insets/insetbibitem.[Ch]
(write): Remove, not needed anymore
(directWrite): ditto
* src/insets/insetbibitem.C
(InsetBibitem::read): Use InsetCommand::read
* src/insets/insetref.C
(InsetRef::latex): Use new InsetCommandParams interface
* src/mathed/InsetMathHull.C
(InsetMathHull::doDispatch): ditto
* src/text3.C
(LyXText::dispatch): ditto
* src/factory.C
(createInset): Create InsetCommandParams with command name
(readInset): ditto
(readInset): Remove error message for bibitem, since bibitem is
now a normal command inset
* src/buffer.C: Bump file format number
* src/frontends/controllers/ControlCommand.[Ch]
(ControlCommand): take an additional command name parameter
* src/text.C
(readParToken): Remove code for \bibitem
* lib/lyx2lyx/LyX.py: Bump latest file format number
* lib/lyx2lyx/lyx_1_5.py
(convert_bibitem, convert_commandparams): new, convert to new format
(revert_commandparams): new, convert to old format
* development/FORMAT: document new format
* many other files: Adjust to the changes above
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15357 a592a061-630c-0410-9148-cb99ea01b6c8
2006-10-17 21:07:16 +00:00
|
|
|
p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
|
2010-10-29 00:25:28 +00:00
|
|
|
string const data = InsetCommand::params2string(p);
|
2005-07-17 16:36:21 +00:00
|
|
|
|
2006-09-01 15:41:38 +00:00
|
|
|
if (cmd.argument().empty())
|
2007-11-18 00:39:15 +00:00
|
|
|
cur.bv().showDialog("label", data);
|
2006-09-01 15:41:38 +00:00
|
|
|
else {
|
2005-07-17 16:36:21 +00:00
|
|
|
FuncRequest fr(LFUN_INSET_INSERT, data);
|
|
|
|
dispatch(cur, fr);
|
2002-08-15 14:33:14 +00:00
|
|
|
}
|
2005-07-17 16:36:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-08-15 14:33:14 +00:00
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_COPY_AS_REFERENCE: {
|
2009-05-20 23:58:29 +00:00
|
|
|
row_type row;
|
|
|
|
if (cmd.argument().empty() && &cur.inset() == this)
|
|
|
|
// if there is no argument and we're inside math, we retrieve
|
|
|
|
// the row number from the cursor position.
|
|
|
|
row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
|
|
|
else {
|
|
|
|
// if there is an argument, find the corresponding label, else
|
|
|
|
// check whether there is at least one label.
|
|
|
|
for (row = 0; row != nrows(); ++row)
|
2014-05-27 20:17:35 +00:00
|
|
|
if (numbered(row) && label_[row]
|
2009-05-20 23:58:29 +00:00
|
|
|
&& (cmd.argument().empty() || label(row) == cmd.argument()))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (row == nrows())
|
|
|
|
break;
|
|
|
|
|
2009-05-15 20:54:15 +00:00
|
|
|
InsetCommandParams p(REF_CODE, "ref");
|
|
|
|
p["reference"] = label(row);
|
|
|
|
cap::clearSelection();
|
2009-11-08 15:53:21 +00:00
|
|
|
cap::copyInset(cur, new InsetRef(buffer_, p), label(row));
|
2009-05-15 20:54:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-09 23:43:05 +00:00
|
|
|
case LFUN_WORD_DELETE_FORWARD:
|
|
|
|
case LFUN_CHAR_DELETE_FORWARD:
|
|
|
|
if (col(cur.idx()) + 1 == ncols()
|
2009-10-12 15:20:23 +00:00
|
|
|
&& cur.pos() == cur.lastpos()
|
|
|
|
&& !cur.selection()) {
|
2008-03-10 17:09:02 +00:00
|
|
|
if (!label(row(cur.idx())).empty()) {
|
|
|
|
cur.recordUndoInset();
|
|
|
|
label(row(cur.idx()), docstring());
|
|
|
|
} else if (numbered(row(cur.idx()))) {
|
|
|
|
cur.recordUndoInset();
|
|
|
|
numbered(row(cur.idx()), false);
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2008-03-10 17:09:02 +00:00
|
|
|
} else {
|
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
return;
|
|
|
|
}
|
2008-03-09 23:43:05 +00:00
|
|
|
} else {
|
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-17 16:36:21 +00:00
|
|
|
case LFUN_INSET_INSERT: {
|
2006-10-21 00:16:43 +00:00
|
|
|
//lyxerr << "arg: " << to_utf8(cmd.argument()) << endl;
|
2008-03-04 12:43:20 +00:00
|
|
|
// FIXME: this should be cleaned up to use InsetLabel methods directly.
|
2007-12-12 19:28:07 +00:00
|
|
|
string const name = cmd.getArg(0);
|
2005-07-17 16:36:21 +00:00
|
|
|
if (name == "label") {
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(LABEL_CODE);
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring str = p["name"];
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2006-09-03 16:14:51 +00:00
|
|
|
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2007-12-12 19:57:42 +00:00
|
|
|
str = trim(str);
|
2005-07-17 16:36:21 +00:00
|
|
|
if (!str.empty())
|
|
|
|
numbered(r, true);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring old = label(r);
|
2005-07-17 23:03:01 +00:00
|
|
|
if (str != old) {
|
2008-03-04 12:43:20 +00:00
|
|
|
if (label_[r])
|
|
|
|
// The label will take care of the reference update.
|
|
|
|
label(r, str);
|
|
|
|
else {
|
|
|
|
label(r, str);
|
|
|
|
// Newly created inset so initialize it.
|
|
|
|
label_[r]->initView();
|
|
|
|
}
|
2005-07-17 23:03:01 +00:00
|
|
|
}
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2005-11-22 13:52:25 +00:00
|
|
|
break;
|
2005-07-17 16:36:21 +00:00
|
|
|
}
|
2006-09-30 17:17:31 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
return;
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_EXTERN:
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2004-02-16 11:58:51 +00:00
|
|
|
doExtern(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
|
|
|
|
case LFUN_MATH_MUTATE: {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2004-02-25 14:39:14 +00:00
|
|
|
row_type row = cur.row();
|
|
|
|
col_type col = cur.col();
|
2006-10-22 10:15:23 +00:00
|
|
|
mutate(hullType(cmd.argument()));
|
2004-02-25 14:39:14 +00:00
|
|
|
cur.idx() = row * ncols() + col;
|
|
|
|
if (cur.idx() > cur.lastidx()) {
|
|
|
|
cur.idx() = cur.lastidx();
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
}
|
2004-02-16 11:58:51 +00:00
|
|
|
if (cur.pos() > cur.lastpos())
|
2004-01-15 17:34:44 +00:00
|
|
|
cur.pos() = cur.lastpos();
|
2008-10-13 11:25:37 +00:00
|
|
|
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2008-02-08 16:19:58 +00:00
|
|
|
// FIXME: find some more clever handling of the selection,
|
|
|
|
// i.e. preserve it.
|
|
|
|
cur.clearSelection();
|
2004-02-16 11:58:51 +00:00
|
|
|
//cur.dispatched(FINISHED);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case LFUN_MATH_DISPLAY: {
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndoInset();
|
2006-09-03 16:14:51 +00:00
|
|
|
mutate(type_ == hullSimple ? hullEquation : hullSimple);
|
2015-07-08 09:01:42 +00:00
|
|
|
// if the cursor is in a cell that got merged, move it to
|
|
|
|
// start of the hull inset.
|
|
|
|
if (cur.idx() > 0) {
|
|
|
|
cur.idx() = 0;
|
|
|
|
cur.pos() = 0;
|
|
|
|
}
|
|
|
|
if (cur.pos() > cur.lastpos())
|
|
|
|
cur.pos() = cur.lastpos();
|
|
|
|
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
2004-02-16 11:58:51 +00:00
|
|
|
}
|
2002-08-15 14:33:14 +00:00
|
|
|
|
2015-12-11 20:45:57 +00:00
|
|
|
case LFUN_TABULAR_FEATURE:
|
2016-04-22 13:50:51 +00:00
|
|
|
if (!allowsTabularFeatures())
|
2015-12-11 20:45:57 +00:00
|
|
|
cur.undispatched();
|
|
|
|
else
|
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
|
2004-02-16 11:58:51 +00:00
|
|
|
default:
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
2004-04-06 19:25:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-12 07:24:55 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-06-09 14:02:39 +00:00
|
|
|
bool allowDisplayMath(Cursor const & cur)
|
2016-05-12 07:24:55 +00:00
|
|
|
{
|
|
|
|
LATTEST(cur.depth() > 1);
|
2016-06-09 14:02:39 +00:00
|
|
|
Cursor tmpcur = cur;
|
|
|
|
tmpcur.pop();
|
2016-05-12 07:24:55 +00:00
|
|
|
FuncStatus status;
|
|
|
|
FuncRequest cmd(LFUN_MATH_DISPLAY);
|
2016-06-09 14:02:39 +00:00
|
|
|
return tmpcur.getStatus(cmd, status) && status.enabled();
|
2016-05-12 07:24:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2016-05-12 07:24:55 +00:00
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-07-18 00:09:20 +00:00
|
|
|
FuncStatus & status) const
|
2004-04-06 19:25:39 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2007-10-22 22:18:52 +00:00
|
|
|
case LFUN_FINISHED_BACKWARD:
|
|
|
|
case LFUN_FINISHED_FORWARD:
|
2008-02-10 19:57:00 +00:00
|
|
|
case LFUN_FINISHED_RIGHT:
|
|
|
|
case LFUN_FINISHED_LEFT:
|
2007-05-29 20:53:32 +00:00
|
|
|
case LFUN_UP:
|
|
|
|
case LFUN_DOWN:
|
2008-03-26 08:10:01 +00:00
|
|
|
case LFUN_NEWLINE_INSERT:
|
2004-04-06 19:25:39 +00:00
|
|
|
case LFUN_MATH_EXTERN:
|
|
|
|
// we handle these
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2004-04-06 19:25:39 +00:00
|
|
|
return true;
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2010-12-14 17:33:38 +00:00
|
|
|
// we never allow this in math, and we want to bind enter
|
|
|
|
// to another actions in command-alternatives
|
2012-09-29 16:06:42 +00:00
|
|
|
case LFUN_PARAGRAPH_BREAK:
|
2010-12-14 17:33:38 +00:00
|
|
|
status.setEnabled(false);
|
|
|
|
return true;
|
2009-05-21 12:45:31 +00:00
|
|
|
case LFUN_MATH_MUTATE: {
|
2010-12-03 02:44:16 +00:00
|
|
|
HullType const ht = hullType(cmd.argument());
|
2009-05-21 12:45:31 +00:00
|
|
|
status.setOnOff(type_ == ht);
|
2015-12-14 01:54:27 +00:00
|
|
|
status.setEnabled(isMutable(ht) && isMutable(type_));
|
2010-12-03 02:44:16 +00:00
|
|
|
|
2016-05-12 07:24:55 +00:00
|
|
|
if (ht != hullSimple && status.enabled())
|
|
|
|
status.setEnabled(allowDisplayMath(cur));
|
2010-12-03 02:44:16 +00:00
|
|
|
return true;
|
2010-11-21 17:00:12 +00:00
|
|
|
}
|
|
|
|
case LFUN_MATH_DISPLAY: {
|
2020-06-22 21:11:40 +00:00
|
|
|
status.setEnabled(display() || allowDisplayMath(cur));
|
|
|
|
status.setOnOff(display());
|
2009-05-21 12:45:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_TOGGLE:
|
2008-01-03 17:31:12 +00:00
|
|
|
// FIXME: what is the right test, this or the one of
|
|
|
|
// LABEL_INSERT?
|
2020-06-22 21:11:40 +00:00
|
|
|
status.setEnabled(display());
|
2008-01-03 17:31:12 +00:00
|
|
|
status.setOnOff(numberedType());
|
|
|
|
return true;
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2008-01-11 22:45:19 +00:00
|
|
|
case LFUN_MATH_NUMBER_LINE_TOGGLE: {
|
2008-01-03 17:31:12 +00:00
|
|
|
// FIXME: what is the right test, this or the one of
|
|
|
|
// LABEL_INSERT?
|
2008-11-16 14:55:30 +00:00
|
|
|
bool const enable = (type_ == hullMultline)
|
|
|
|
? (nrows() - 1 == cur.row())
|
2020-06-22 21:11:40 +00:00
|
|
|
: display();
|
2008-01-03 17:31:12 +00:00
|
|
|
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(enable);
|
2009-05-21 10:14:07 +00:00
|
|
|
status.setOnOff(enable && numbered(r));
|
2008-01-03 17:31:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2006-05-05 20:23:12 +00:00
|
|
|
case LFUN_LABEL_INSERT:
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(type_ != hullSimple);
|
2005-07-15 15:19:07 +00:00
|
|
|
return true;
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2014-02-11 10:00:20 +00:00
|
|
|
case LFUN_LABEL_COPY_AS_REFERENCE: {
|
2009-05-20 23:58:29 +00:00
|
|
|
bool enabled = false;
|
|
|
|
if (cmd.argument().empty() && &cur.inset() == this) {
|
|
|
|
// if there is no argument and we're inside math, we retrieve
|
|
|
|
// the row number from the cursor position.
|
2017-12-16 04:41:32 +00:00
|
|
|
row_type row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
|
2014-05-27 20:17:35 +00:00
|
|
|
enabled = numberedType() && label_[row] && numbered(row);
|
2009-05-20 23:58:29 +00:00
|
|
|
} else {
|
|
|
|
// if there is an argument, find the corresponding label, else
|
|
|
|
// check whether there is at least one label.
|
|
|
|
for (row_type row = 0; row != nrows(); ++row) {
|
2014-05-27 20:17:35 +00:00
|
|
|
if (numbered(row) && label_[row] &&
|
2009-05-20 23:58:29 +00:00
|
|
|
(cmd.argument().empty() || label(row) == cmd.argument())) {
|
|
|
|
enabled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status.setEnabled(enabled);
|
2009-05-15 20:54:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-09-30 17:17:31 +00:00
|
|
|
case LFUN_INSET_INSERT:
|
|
|
|
if (cmd.getArg(0) == "label") {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(type_ != hullSimple);
|
2006-09-30 17:17:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return InsetMathGrid::getStatus(cur, cmd, status);
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2015-12-11 02:15:52 +00:00
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2016-04-22 13:50:51 +00:00
|
|
|
if (!allowsTabularFeatures())
|
2015-12-11 20:45:57 +00:00
|
|
|
return false;
|
2015-12-11 02:15:52 +00:00
|
|
|
string s = cmd.getArg(0);
|
2004-11-23 14:43:37 +00:00
|
|
|
if (!rowChangeOK()
|
|
|
|
&& (s == "append-row"
|
2004-10-05 10:11:42 +00:00
|
|
|
|| s == "delete-row"
|
2004-11-26 13:56:22 +00:00
|
|
|
|| s == "copy-row")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
status.message(bformat(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't change number of rows in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2004-11-26 13:56:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-11-23 14:43:37 +00:00
|
|
|
if (!colChangeOK()
|
2004-11-15 15:41:42 +00:00
|
|
|
&& (s == "append-column"
|
2004-11-23 14:43:37 +00:00
|
|
|
|| s == "delete-column"
|
2004-11-26 13:56:22 +00:00
|
|
|
|| s == "copy-column")) {
|
2005-07-18 00:09:20 +00:00
|
|
|
status.message(bformat(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't change number of columns in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2004-11-26 13:56:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
2005-07-18 00:09:20 +00:00
|
|
|
status.message(bformat(
|
2006-10-21 00:16:43 +00:00
|
|
|
from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
|
2006-10-22 10:15:23 +00:00
|
|
|
hullName(type_)));
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2005-03-22 12:34:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-04-26 11:12:20 +00:00
|
|
|
if (s == "valign-top" || s == "valign-middle"
|
2005-04-25 14:10:10 +00:00
|
|
|
|| s == "valign-bottom" || s == "align-left"
|
|
|
|
|| s == "align-center" || s == "align-right") {
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(false);
|
2005-04-25 14:10:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
return InsetMathGrid::getStatus(cur, cmd, status);
|
2004-08-12 20:43:24 +00:00
|
|
|
}
|
2009-05-15 20:54:15 +00:00
|
|
|
|
2004-04-06 19:25:39 +00:00
|
|
|
default:
|
2006-09-16 18:11:38 +00:00
|
|
|
return InsetMathGrid::getStatus(cur, cmd, status);
|
2002-08-13 17:43:40 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-28 08:44:56 +00:00
|
|
|
|
|
|
|
|
2016-11-17 15:17:49 +00:00
|
|
|
int InsetMathHull::leftMargin() const
|
|
|
|
{
|
|
|
|
return (getType() == hullSimple) ? 0 : InsetMathGrid::leftMargin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMathHull::rightMargin() const
|
|
|
|
{
|
|
|
|
return (getType() == hullSimple) ? 0 : InsetMathGrid::rightMargin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetMathHull::border() const
|
|
|
|
{
|
|
|
|
return (getType() == hullSimple) ? 0 : InsetMathGrid::border();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// simply scrap this function if you want
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathHull::mutateToText()
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
// translate to latex
|
|
|
|
ostringstream os;
|
2008-04-07 20:43:02 +00:00
|
|
|
latex(os, false, false);
|
2004-01-26 10:13:15 +00:00
|
|
|
string str = os.str();
|
|
|
|
|
|
|
|
// insert this text
|
2007-04-29 23:33:02 +00:00
|
|
|
Text * lt = view_->cursor().innerText();
|
2004-01-26 10:13:15 +00:00
|
|
|
string::const_iterator cit = str.begin();
|
|
|
|
string::const_iterator end = str.end();
|
|
|
|
for (; cit != end; ++cit)
|
2006-09-17 10:03:00 +00:00
|
|
|
view_->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
// remove ourselves
|
2006-10-21 00:16:43 +00:00
|
|
|
//dispatch(LFUN_ESCAPE);
|
2004-01-26 10:13:15 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::handleFont(Cursor & cur, docstring const & arg,
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const & font)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
|
|
|
// this whole function is a hack and won't work for incremental font
|
|
|
|
// changes...
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndo();
|
2006-09-16 18:11:38 +00:00
|
|
|
if (cur.inset().asInsetMath()->name() == font)
|
2006-10-22 10:15:23 +00:00
|
|
|
cur.handleFont(to_utf8(font));
|
2004-01-26 10:13:15 +00:00
|
|
|
else {
|
2009-11-08 11:45:46 +00:00
|
|
|
cur.handleNest(createInsetMath(font, cur.buffer()));
|
2004-01-26 10:13:15 +00:00
|
|
|
cur.insert(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg)
|
2004-01-26 10:13:15 +00:00
|
|
|
{
|
2007-10-18 11:51:17 +00:00
|
|
|
cur.recordUndo();
|
2007-04-29 18:17:15 +00:00
|
|
|
Font font;
|
2004-01-26 10:13:15 +00:00
|
|
|
bool b;
|
2007-09-29 11:00:18 +00:00
|
|
|
font.fromString(to_utf8(arg), b);
|
2007-10-28 18:51:54 +00:00
|
|
|
if (font.fontInfo().color() != Color_inherit) {
|
2009-11-08 11:45:46 +00:00
|
|
|
MathAtom at = MathAtom(new InsetMathColor(buffer_, true, font.fontInfo().color()));
|
2018-04-04 16:24:14 +00:00
|
|
|
cur.handleNest(at);
|
2004-01-26 10:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-11 08:20:13 +00:00
|
|
|
void InsetMathHull::edit(Cursor & cur, bool front, EntryDirection entry_from)
|
2004-04-06 19:25:39 +00:00
|
|
|
{
|
2018-04-04 16:24:14 +00:00
|
|
|
InsetMathNest::edit(cur, front, entry_from);
|
2007-04-13 11:35:11 +00:00
|
|
|
// The inset formula dimension is not necessarily the same as the
|
2007-04-13 11:49:58 +00:00
|
|
|
// one of the instant preview image, so we have to indicate to the
|
2007-05-28 22:27:45 +00:00
|
|
|
// BufferView that a metrics update is needed.
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.screenUpdateFlags(Update::Force);
|
2004-04-06 19:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
#if 0
|
2006-09-16 18:11:38 +00:00
|
|
|
bool InsetMathHull::searchForward(BufferView * bv, string const & str,
|
2004-01-26 10:13:15 +00:00
|
|
|
bool, bool)
|
|
|
|
{
|
2007-08-10 11:47:12 +00:00
|
|
|
// FIXME: completely broken
|
2006-09-16 18:11:38 +00:00
|
|
|
static InsetMathHull * lastformula = 0;
|
2004-03-31 19:11:56 +00:00
|
|
|
static CursorBase current = DocIterator(ibegin(nucleus()));
|
2007-04-26 16:05:57 +00:00
|
|
|
static MathData ar;
|
2004-01-26 10:13:15 +00:00
|
|
|
static string laststr;
|
|
|
|
|
|
|
|
if (lastformula != this || laststr != str) {
|
|
|
|
//lyxerr << "reset lastformula to " << this << endl;
|
|
|
|
lastformula = this;
|
|
|
|
laststr = str;
|
2004-01-30 11:41:12 +00:00
|
|
|
current = ibegin(nucleus());
|
2004-01-26 10:13:15 +00:00
|
|
|
ar.clear();
|
2009-11-06 15:18:48 +00:00
|
|
|
mathed_parse_cell(ar, str, Parse::NORMAL, &buffer());
|
2004-01-26 10:13:15 +00:00
|
|
|
} else {
|
|
|
|
increment(current);
|
|
|
|
}
|
|
|
|
//lyxerr << "searching '" << str << "' in " << this << ar << endl;
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
for (DocIterator it = current; it != iend(nucleus()); increment(it)) {
|
2004-01-26 10:13:15 +00:00
|
|
|
CursorSlice & top = it.back();
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData const & a = top.asInsetMath()->cell(top.idx_);
|
2004-01-26 10:13:15 +00:00
|
|
|
if (a.matchpart(ar, top.pos_)) {
|
|
|
|
bv->cursor().setSelection(it, ar.size());
|
|
|
|
current = it;
|
|
|
|
top.pos_ += ar.size();
|
|
|
|
bv->update();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//lyxerr << "not found!" << endl;
|
|
|
|
lastformula = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetMathHull::write(ostream & os) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream oss;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(oss);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, false, WriteStream::wsDefault);
|
2006-10-19 16:51:30 +00:00
|
|
|
oss << "Formula ";
|
2004-01-30 11:41:12 +00:00
|
|
|
write(wi);
|
2006-10-21 00:16:43 +00:00
|
|
|
os << to_utf8(oss.str());
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetMathHull::read(Lexer & lex)
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
|
|
|
MathAtom at;
|
2009-11-08 18:47:33 +00:00
|
|
|
mathed_parse_normal(buffer_, at, lex, Parse::TRACKMACRO);
|
2004-01-30 11:41:12 +00:00
|
|
|
operator=(*at->asHullInset());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-31 15:19:39 +00:00
|
|
|
bool InsetMathHull::readQuiet(Lexer & lex)
|
2008-10-17 21:40:11 +00:00
|
|
|
{
|
|
|
|
MathAtom at;
|
2009-11-08 11:45:46 +00:00
|
|
|
bool success = mathed_parse_normal(buffer_, at, lex, Parse::QUIET);
|
2009-11-06 15:18:48 +00:00
|
|
|
if (success)
|
|
|
|
operator=(*at->asHullInset());
|
|
|
|
return success;
|
2008-10-17 21:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetMathHull::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const & op, size_t max_length) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2017-12-16 04:41:32 +00:00
|
|
|
// Try enabling this now that there is a flag as requested at #2275.
|
2018-09-12 13:26:15 +00:00
|
|
|
if (buffer().isExporting() && display()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
Dimension dim;
|
|
|
|
TextMetricsInfo mi;
|
|
|
|
metricsT(mi, dim);
|
|
|
|
TextPainter tpain(dim.width(), dim.height());
|
|
|
|
drawT(tpain, 0, dim.ascent());
|
|
|
|
tpain.show(os, 3);
|
|
|
|
// reset metrics cache to "real" values
|
|
|
|
//metrics();
|
|
|
|
return tpain.textheight();
|
2011-10-25 18:43:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
odocstringstream oss;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(oss);
|
2011-10-25 18:43:47 +00:00
|
|
|
Encoding const * const enc = encodings.fromLyXName("utf8");
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, true, WriteStream::wsDefault, enc);
|
2011-10-25 18:43:47 +00:00
|
|
|
|
|
|
|
// Fix Bug #6139
|
|
|
|
if (type_ == hullRegexp)
|
|
|
|
write(wi);
|
|
|
|
else {
|
|
|
|
for (row_type r = 0; r < nrows(); ++r) {
|
|
|
|
for (col_type c = 0; c < ncols(); ++c)
|
|
|
|
wi << (c == 0 ? "" : "\t") << cell(index(r, c));
|
2011-10-25 18:43:51 +00:00
|
|
|
// if it's for the TOC, we write just the first line
|
|
|
|
// and do not include the newline.
|
2013-03-08 19:52:18 +00:00
|
|
|
if (op.for_toc || op.for_tooltip || oss.str().size() >= max_length)
|
2011-10-25 18:43:51 +00:00
|
|
|
break;
|
2015-05-17 15:27:12 +00:00
|
|
|
if (r < nrows() - 1)
|
2014-10-02 05:29:00 +00:00
|
|
|
wi << "\n";
|
2011-05-11 19:44:27 +00:00
|
|
|
}
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
2011-10-25 18:43:47 +00:00
|
|
|
docstring const str = oss.str();
|
|
|
|
os << str;
|
|
|
|
return str.size();
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2020-06-08 02:07:47 +00:00
|
|
|
// Choose the tag around the MathML equation.
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring name;
|
2020-08-30 22:21:12 +00:00
|
|
|
bool doCR = false;
|
2006-09-03 16:14:51 +00:00
|
|
|
if (getType() == hullSimple)
|
2006-10-22 10:15:23 +00:00
|
|
|
name = from_ascii("inlineequation");
|
2020-08-29 17:05:59 +00:00
|
|
|
else {
|
2020-08-30 22:21:12 +00:00
|
|
|
doCR = true; // This is a block equation, always have <informalequation> on its own line.
|
2006-10-22 10:15:23 +00:00
|
|
|
name = from_ascii("informalequation");
|
2020-08-29 17:05:59 +00:00
|
|
|
}
|
2004-08-13 11:00:34 +00:00
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
// DocBook also has <equation>, but it comes with a title.
|
2020-08-29 20:58:23 +00:00
|
|
|
// TODO: recognise \tag from amsmath? This would allow having <equation> with a proper title.
|
2020-06-08 21:27:49 +00:00
|
|
|
|
2020-07-26 21:23:02 +00:00
|
|
|
docstring attr;
|
2020-06-08 02:07:47 +00:00
|
|
|
for (row_type i = 0; i < nrows(); ++i) {
|
|
|
|
if (!label(i).empty()) {
|
2020-07-26 21:23:02 +00:00
|
|
|
attr = "xml:id=\"" + xml::cleanID(label(i)) + "\"";
|
2020-06-08 02:07:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-11-05 23:46:17 +00:00
|
|
|
|
2020-08-30 22:21:12 +00:00
|
|
|
if (doCR)
|
|
|
|
if (!xs.isLastTagCR())
|
|
|
|
xs << xml::CR();
|
|
|
|
|
2020-07-26 21:23:02 +00:00
|
|
|
xs << xml::StartTag(name, attr);
|
2020-08-01 19:43:44 +00:00
|
|
|
xs << xml::CR();
|
2020-07-26 21:23:02 +00:00
|
|
|
|
|
|
|
// With DocBook 5, MathML must be within its own namespace; defined in Buffer.cpp::writeDocBookSource as "m".
|
|
|
|
// Output everything in a separate stream so that this does not interfere with the standard flow of DocBook tags.
|
|
|
|
odocstringstream osmath;
|
|
|
|
MathStream ms(osmath, "m", true);
|
2004-08-13 11:00:34 +00:00
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
// Output the MathML subtree.
|
2006-10-19 16:51:30 +00:00
|
|
|
odocstringstream ls;
|
2016-06-19 02:39:38 +00:00
|
|
|
otexstream ols(ls);
|
2004-11-23 23:04:52 +00:00
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
// TeX transcription. Avoid MTag/ETag so that there are no extraneous spaces.
|
|
|
|
ms << "<" << from_ascii("alt") << " role='tex'" << ">";
|
|
|
|
// Workaround for db2latex: db2latex always includes equations with
|
|
|
|
// \ensuremath{} or \begin{display}\end{display}
|
|
|
|
// so we strip LyX' math environment
|
|
|
|
WriteStream wi(ols, false, false, WriteStream::wsDefault, runparams.encoding);
|
|
|
|
InsetMathGrid::write(wi);
|
|
|
|
ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
|
|
|
|
ms << "</" << from_ascii("alt") << ">";
|
|
|
|
|
2020-07-08 16:15:34 +00:00
|
|
|
// Actual transformation of the formula into MathML. This translation may fail (for example, due to custom macros).
|
|
|
|
// The new output stream is required to deal with the errors: first write completely the formula into this
|
|
|
|
// temporary stream; then, if it is possible without error, then copy it back to the "real" stream. Otherwise,
|
2020-06-08 21:27:49 +00:00
|
|
|
// some incomplete tags might be put into the real stream.
|
2020-07-08 16:15:34 +00:00
|
|
|
try {
|
|
|
|
// First, generate the MathML expression.
|
|
|
|
odocstringstream ostmp;
|
|
|
|
MathStream mstmp(ostmp, ms.xmlns(), ms.xmlMode());
|
|
|
|
InsetMathGrid::mathmlize(mstmp);
|
|
|
|
|
|
|
|
// Then, output it (but only if the generation can be done without errors!).
|
|
|
|
ms << MTag("math");
|
|
|
|
ms.cr();
|
2020-06-08 21:27:49 +00:00
|
|
|
osmath << ostmp.str(); // osmath is not a XMLStream, so no need for XMLStream::ESCAPE_NONE.
|
2020-07-08 16:15:34 +00:00
|
|
|
ms << ETag("math");
|
|
|
|
} catch (MathExportException const &) {
|
2020-08-15 22:59:43 +00:00
|
|
|
ms.cr();
|
|
|
|
osmath << "<mathphrase>MathML export failed. Please report this as a bug.</mathphrase>";
|
2020-06-08 21:27:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 21:23:02 +00:00
|
|
|
// Output the complete formula to the DocBook stream.
|
2020-06-08 21:27:49 +00:00
|
|
|
xs << XMLStream::ESCAPE_NONE << osmath.str();
|
2020-08-01 19:43:44 +00:00
|
|
|
xs << xml::CR();
|
2020-07-26 21:23:02 +00:00
|
|
|
xs << xml::EndTag(name);
|
2020-08-30 22:21:12 +00:00
|
|
|
if (doCR)
|
|
|
|
xs << xml::CR();
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
2005-11-25 14:40:34 +00:00
|
|
|
|
|
|
|
|
2011-01-12 16:04:59 +00:00
|
|
|
bool InsetMathHull::haveNumbers() const
|
2011-01-11 23:34:59 +00:00
|
|
|
{
|
|
|
|
bool havenumbers = false;
|
2011-03-20 12:12:08 +00:00
|
|
|
// inline formulas are never numbered (bug 7351 part 3)
|
|
|
|
if (getType() == hullSimple)
|
|
|
|
return havenumbers;
|
2011-01-11 23:34:59 +00:00
|
|
|
for (size_t i = 0; i != numbered_.size(); ++i) {
|
2014-05-27 20:17:35 +00:00
|
|
|
if (numbered(i)) {
|
2011-01-11 23:34:59 +00:00
|
|
|
havenumbers = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-12 16:04:59 +00:00
|
|
|
return havenumbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME XHTML
|
|
|
|
// We need to do something about alignment here.
|
|
|
|
//
|
|
|
|
// This duplicates code from InsetMathGrid, but
|
|
|
|
// we need access here to number information,
|
|
|
|
// and we simply do not have that in InsetMathGrid.
|
|
|
|
void InsetMathHull::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
bool const havenumbers = haveNumbers();
|
2011-01-11 23:34:59 +00:00
|
|
|
bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
|
|
|
|
|
|
|
|
if (!havetable) {
|
|
|
|
os << cell(index(0, 0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
os << MTag("table", "class='mathtable'");
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
os << MTag("tr");
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
os << MTag("td");
|
|
|
|
os << cell(index(row, col));
|
|
|
|
os << ETag("td");
|
|
|
|
}
|
|
|
|
if (havenumbers) {
|
|
|
|
os << MTag("td");
|
|
|
|
docstring const & num = numbers_[row];
|
|
|
|
if (!num.empty())
|
|
|
|
os << '(' << num << ')';
|
|
|
|
os << ETag("td");
|
|
|
|
}
|
|
|
|
os << ETag("tr");
|
|
|
|
}
|
|
|
|
os << ETag("table");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 23:18:56 +00:00
|
|
|
// this duplicates code from InsetMathGrid, but
|
2011-01-11 23:34:59 +00:00
|
|
|
// we need access here to number information,
|
2011-01-11 23:18:56 +00:00
|
|
|
// and we simply do not have that in InsetMathGrid.
|
2019-05-09 23:52:07 +00:00
|
|
|
void InsetMathHull::mathmlize(MathStream & ms) const
|
2011-01-11 23:18:56 +00:00
|
|
|
{
|
2011-01-13 18:30:24 +00:00
|
|
|
bool const havenumbers = haveNumbers();
|
2011-01-11 23:18:56 +00:00
|
|
|
bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
|
|
|
|
|
|
|
|
if (havetable)
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << MTag("mtable");
|
2011-01-11 23:18:56 +00:00
|
|
|
char const * const celltag = havetable ? "mtd" : "mrow";
|
|
|
|
// FIXME There does not seem to be wide support at the moment
|
|
|
|
// for mlabeledtr, so we have to use just mtr for now.
|
|
|
|
// char const * const rowtag = havenumbers ? "mlabeledtr" : "mtr";
|
|
|
|
char const * const rowtag = "mtr";
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
if (havetable)
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << MTag(rowtag);
|
2011-01-11 23:18:56 +00:00
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << MTag(celltag)
|
2011-01-11 23:18:56 +00:00
|
|
|
<< cell(index(row, col))
|
|
|
|
<< ETag(celltag);
|
|
|
|
}
|
|
|
|
// fleqn?
|
|
|
|
if (havenumbers) {
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << MTag("mtd");
|
2011-01-11 23:18:56 +00:00
|
|
|
docstring const & num = numbers_[row];
|
|
|
|
if (!num.empty())
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << '(' << num << ')';
|
|
|
|
ms << ETag("mtd");
|
2011-01-11 23:18:56 +00:00
|
|
|
}
|
|
|
|
if (havetable)
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << ETag(rowtag);
|
2011-01-11 23:18:56 +00:00
|
|
|
}
|
|
|
|
if (havetable)
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << ETag("mtable");
|
2011-01-11 23:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 23:55:20 +00:00
|
|
|
void InsetMathHull::mathAsLatex(WriteStream & os) const
|
|
|
|
{
|
|
|
|
MathEnsurer ensurer(os, false);
|
2011-01-12 16:04:59 +00:00
|
|
|
bool havenumbers = haveNumbers();
|
2011-01-11 23:55:20 +00:00
|
|
|
bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
|
|
|
|
|
|
|
|
if (!havetable) {
|
|
|
|
os << cell(index(0, 0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
os << "<table class='mathtable'>";
|
|
|
|
for (row_type row = 0; row < nrows(); ++row) {
|
|
|
|
os << "<tr>";
|
|
|
|
for (col_type col = 0; col < ncols(); ++col) {
|
|
|
|
os << "<td class='math'>";
|
|
|
|
os << cell(index(row, col));
|
|
|
|
os << "</td>";
|
|
|
|
}
|
|
|
|
if (havenumbers) {
|
|
|
|
os << "<td>";
|
|
|
|
docstring const & num = numbers_[row];
|
|
|
|
if (!num.empty())
|
|
|
|
os << '(' << num << ')';
|
|
|
|
os << "</td>";
|
|
|
|
}
|
|
|
|
os << "</tr>";
|
|
|
|
}
|
|
|
|
os << "</table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetMathHull::xhtml(XMLStream & xs, OutputParams const & op) const
|
2009-11-14 15:25:32 +00:00
|
|
|
{
|
2014-02-25 20:21:47 +00:00
|
|
|
BufferParams::MathOutput const mathtype =
|
2013-03-27 18:51:27 +00:00
|
|
|
buffer().masterBuffer()->params().html_math_output;
|
2011-01-12 13:50:46 +00:00
|
|
|
|
2010-07-29 15:37:42 +00:00
|
|
|
bool success = false;
|
2011-01-12 13:50:46 +00:00
|
|
|
|
|
|
|
// we output all the labels just at the beginning of the equation.
|
|
|
|
// this should be fine.
|
|
|
|
for (size_t i = 0; i != label_.size(); ++i) {
|
|
|
|
InsetLabel const * const il = label_[i];
|
|
|
|
if (!il)
|
|
|
|
continue;
|
|
|
|
il->xhtml(xs, op);
|
|
|
|
}
|
|
|
|
|
2010-03-29 22:52:13 +00:00
|
|
|
// FIXME Eventually we would like to do this inset by inset.
|
2010-07-29 15:37:42 +00:00
|
|
|
if (mathtype == BufferParams::MathML) {
|
2010-07-21 14:02:46 +00:00
|
|
|
odocstringstream os;
|
|
|
|
MathStream ms(os);
|
2010-07-29 15:37:42 +00:00
|
|
|
try {
|
2011-01-11 23:18:56 +00:00
|
|
|
mathmlize(ms);
|
2010-07-29 15:37:42 +00:00
|
|
|
success = true;
|
|
|
|
} catch (MathExportException const &) {}
|
|
|
|
if (success) {
|
|
|
|
if (getType() == hullSimple)
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::StartTag("math",
|
2010-07-29 15:37:42 +00:00
|
|
|
"xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
|
2014-02-25 20:21:47 +00:00
|
|
|
else
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::StartTag("math",
|
2010-11-24 15:27:36 +00:00
|
|
|
"display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << XMLStream::ESCAPE_NONE
|
2010-07-29 15:37:42 +00:00
|
|
|
<< os.str()
|
2019-05-09 23:35:40 +00:00
|
|
|
<< xml::EndTag("math");
|
2010-07-29 15:37:42 +00:00
|
|
|
}
|
|
|
|
} else if (mathtype == BufferParams::HTML) {
|
2010-07-21 14:02:46 +00:00
|
|
|
odocstringstream os;
|
|
|
|
HtmlStream ms(os);
|
2010-07-29 15:37:42 +00:00
|
|
|
try {
|
2011-01-11 23:34:59 +00:00
|
|
|
htmlize(ms);
|
2010-07-29 15:37:42 +00:00
|
|
|
success = true;
|
|
|
|
} catch (MathExportException const &) {}
|
|
|
|
if (success) {
|
|
|
|
string const tag = (getType() == hullSimple) ? "span" : "div";
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::StartTag(tag, "class='formula'", true)
|
|
|
|
<< XMLStream::ESCAPE_NONE
|
2010-11-24 15:27:36 +00:00
|
|
|
<< os.str()
|
2019-05-09 23:35:40 +00:00
|
|
|
<< xml::EndTag(tag);
|
2010-07-29 15:37:42 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2010-07-29 16:55:02 +00:00
|
|
|
// what we actually want is this:
|
|
|
|
// if (
|
2014-02-25 20:21:47 +00:00
|
|
|
// ((mathtype == BufferParams::MathML || mathtype == BufferParams::HTML)
|
2010-07-29 16:55:02 +00:00
|
|
|
// && !success)
|
|
|
|
// || mathtype == BufferParams::Images
|
|
|
|
// )
|
2014-02-25 20:21:47 +00:00
|
|
|
// but what follows is equivalent, since we'll enter only if either (a) we
|
2010-07-29 16:55:02 +00:00
|
|
|
// tried and failed with MathML or HTML or (b) didn't try yet at all but
|
2016-06-30 03:18:57 +00:00
|
|
|
// aren't doing LaTeX.
|
|
|
|
//
|
|
|
|
// so this is for Images.
|
2011-04-01 20:44:23 +00:00
|
|
|
if (!success && mathtype != BufferParams::LaTeX) {
|
|
|
|
graphics::PreviewImage const * pimage = 0;
|
|
|
|
if (!op.dryrun) {
|
|
|
|
loadPreview(docit_);
|
|
|
|
pimage = preview_->getPreviewImage(buffer());
|
2010-07-21 13:26:48 +00:00
|
|
|
// FIXME Do we always have png?
|
2011-04-01 20:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pimage || op.dryrun) {
|
|
|
|
string const filename = pimage ? pimage->filename().onlyFileName()
|
|
|
|
: "previewimage.png";
|
2011-04-02 13:04:11 +00:00
|
|
|
if (pimage) {
|
|
|
|
// if we are not in the master buffer, then we need to see that the
|
|
|
|
// generated image is copied there; otherwise, preview fails.
|
|
|
|
Buffer const * mbuf = buffer().masterBuffer();
|
|
|
|
if (mbuf != &buffer()) {
|
|
|
|
string mbtmp = mbuf->temppath();
|
|
|
|
FileName const mbufimg(support::addName(mbtmp, filename));
|
|
|
|
pimage->filename().copyTo(mbufimg);
|
|
|
|
}
|
|
|
|
// add the file to the list of files to be exported
|
|
|
|
op.exportdata->addExternalFile("xhtml", pimage->filename());
|
|
|
|
}
|
|
|
|
|
2010-07-21 13:26:48 +00:00
|
|
|
string const tag = (getType() == hullSimple) ? "span" : "div";
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::CR()
|
|
|
|
<< xml::StartTag(tag, "style = \"text-align: center;\"")
|
2020-11-18 04:29:26 +00:00
|
|
|
<< xml::CompTag("img", "src=\"" + filename + "\" alt=\"Mathematical Equation\"")
|
|
|
|
<< xml::EndTag(tag)
|
|
|
|
<< xml::CR();
|
2010-07-29 15:37:42 +00:00
|
|
|
success = true;
|
2010-07-21 13:19:52 +00:00
|
|
|
}
|
2010-07-29 15:37:42 +00:00
|
|
|
}
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2010-07-29 15:37:42 +00:00
|
|
|
// so we'll pass this test if we've failed everything else, or
|
|
|
|
// if mathtype was LaTeX, since we won't have entered any of the
|
|
|
|
// earlier branches
|
2010-07-29 16:55:02 +00:00
|
|
|
if (!success /* || mathtype != BufferParams::LaTeX */) {
|
2010-07-22 02:47:12 +00:00
|
|
|
// Unfortunately, we cannot use latexString() because we do not want
|
|
|
|
// $...$ or whatever.
|
|
|
|
odocstringstream ls;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(ls);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, true, WriteStream::wsPreview);
|
2010-07-22 02:47:12 +00:00
|
|
|
ModeSpecifier specifier(wi, MATH_MODE);
|
2011-01-11 23:55:20 +00:00
|
|
|
mathAsLatex(wi);
|
2010-07-22 02:47:12 +00:00
|
|
|
docstring const latex = ls.str();
|
2014-02-25 20:21:47 +00:00
|
|
|
|
2010-07-21 13:43:35 +00:00
|
|
|
// class='math' allows for use of jsMath
|
|
|
|
// http://www.math.union.edu/~dpvc/jsMath/
|
|
|
|
// FIXME XHTML
|
|
|
|
// probably should allow for some kind of customization here
|
2011-01-12 16:04:59 +00:00
|
|
|
string const tag = (getType() == hullSimple) ? "span" : "div";
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::StartTag(tag, "class='math'")
|
2014-02-25 20:21:47 +00:00
|
|
|
<< latex
|
2019-05-09 23:35:40 +00:00
|
|
|
<< xml::EndTag(tag)
|
|
|
|
<< xml::CR();
|
2010-03-29 22:52:13 +00:00
|
|
|
}
|
2009-12-31 15:46:39 +00:00
|
|
|
return docstring();
|
2009-11-14 15:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-15 01:34:04 +00:00
|
|
|
void InsetMathHull::toString(odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
{
|
2013-03-08 19:52:18 +00:00
|
|
|
odocstringstream ods;
|
|
|
|
plaintext(ods, OutputParams(0));
|
|
|
|
os << ods.str();
|
2005-11-25 14:40:34 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2015-10-04 18:38:47 +00:00
|
|
|
void InsetMathHull::forOutliner(docstring & os, size_t const, bool const) const
|
2010-12-20 21:55:09 +00:00
|
|
|
{
|
|
|
|
odocstringstream ods;
|
2011-10-25 18:43:51 +00:00
|
|
|
OutputParams op(0);
|
|
|
|
op.for_toc = true;
|
2015-10-04 18:38:47 +00:00
|
|
|
// FIXME: this results in spilling TeX into the LyXHTML output since the
|
|
|
|
// outliner is used to generate the LyXHTML list of figures/etc.
|
2011-10-25 18:43:51 +00:00
|
|
|
plaintext(ods, op);
|
2010-12-20 21:55:09 +00:00
|
|
|
os += ods.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetMathHull::contextMenuName() const
|
2008-03-09 15:07:27 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-math";
|
2008-03-09 15:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-21 13:19:52 +00:00
|
|
|
void InsetMathHull::recordLocation(DocIterator const & di)
|
|
|
|
{
|
|
|
|
docit_ = di;
|
|
|
|
}
|
|
|
|
|
2016-05-23 14:06:26 +00:00
|
|
|
|
|
|
|
bool InsetMathHull::canPaintChange(BufferView const &) const
|
|
|
|
{
|
|
|
|
// We let RowPainter do it seamlessly for inline insets
|
2020-06-22 21:11:40 +00:00
|
|
|
return display();
|
2016-05-23 14:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|