1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-11 08:26:02 +00:00
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
* \file InsetMath.h
|
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.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifndef MATH_INSET_H
|
|
|
|
#define MATH_INSET_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2016-05-30 08:33:35 +00:00
|
|
|
#include "MathClass.h"
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
#include "insets/Inset.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-09-03 16:14:51 +00:00
|
|
|
enum HullType {
|
|
|
|
hullNone,
|
|
|
|
hullSimple,
|
|
|
|
hullEquation,
|
|
|
|
hullEqnArray,
|
|
|
|
hullAlign,
|
|
|
|
hullAlignAt,
|
|
|
|
hullXAlignAt,
|
|
|
|
hullXXAlignAt,
|
|
|
|
hullFlAlign,
|
|
|
|
hullMultline,
|
2008-11-16 00:18:52 +00:00
|
|
|
hullGather,
|
2015-12-14 01:54:27 +00:00
|
|
|
hullRegexp,
|
|
|
|
hullUnknown
|
2006-09-03 16:14:51 +00:00
|
|
|
};
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
HullType hullType(docstring const & name);
|
|
|
|
docstring hullName(HullType type);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
/**
|
|
|
|
|
|
|
|
Abstract base class for all math objects. A math insets is for use of the
|
|
|
|
math editor only, it isn't a general LyX inset. It's used to represent all
|
2002-03-21 17:42:56 +00:00
|
|
|
the math objects.
|
2001-12-03 16:24:50 +00:00
|
|
|
|
2015-10-13 23:23:12 +00:00
|
|
|
Math insets do not know their parents, a cursor position or things
|
2012-09-12 23:38:26 +00:00
|
|
|
like that. They are dumb objects that are contained in other math insets
|
2006-09-16 18:11:38 +00:00
|
|
|
(InsetMathNests, in fact) thus forming a tree. The root of this tree is
|
|
|
|
always a InsetMathHull, which provides an interface to the Outer World by
|
2001-12-03 16:24:50 +00:00
|
|
|
inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
*/
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2016-11-16 14:07:00 +00:00
|
|
|
class Cursor;
|
2003-11-05 12:06:20 +00:00
|
|
|
class OutputParams;
|
2016-11-16 14:07:00 +00:00
|
|
|
class MetricsInfo;
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
class InsetMathArray;
|
|
|
|
class InsetMathAMSArray;
|
|
|
|
class InsetMathBrace;
|
|
|
|
class InsetMathChar;
|
|
|
|
class InsetMathDelim;
|
2015-06-14 16:10:29 +00:00
|
|
|
class InsetMathFracBase;
|
2006-09-16 18:11:38 +00:00
|
|
|
class InsetMathFrac;
|
|
|
|
class InsetMathFont;
|
|
|
|
class InsetMathGrid;
|
|
|
|
class InsetMathHull;
|
|
|
|
class InsetMathMatrix;
|
|
|
|
class InsetMathNest;
|
|
|
|
class InsetMathScript;
|
|
|
|
class InsetMathString;
|
|
|
|
class InsetMathSpace;
|
2008-10-23 00:48:06 +00:00
|
|
|
class InsetMathSpecialChar;
|
2006-09-16 18:11:38 +00:00
|
|
|
class InsetMathSymbol;
|
|
|
|
class InsetMathUnknown;
|
2007-04-28 20:49:56 +00:00
|
|
|
class InsetMathRef;
|
2001-07-13 14:54:56 +00:00
|
|
|
|
2010-03-29 22:52:13 +00:00
|
|
|
class HtmlStream;
|
2001-11-09 08:35:57 +00:00
|
|
|
class NormalStream;
|
|
|
|
class OctaveStream;
|
|
|
|
class MapleStream;
|
2002-10-28 17:15:19 +00:00
|
|
|
class MaximaStream;
|
2002-07-01 11:17:14 +00:00
|
|
|
class MathematicaStream;
|
2006-10-22 10:15:23 +00:00
|
|
|
class MathStream;
|
2001-11-09 08:35:57 +00:00
|
|
|
class WriteStream;
|
|
|
|
|
2016-09-30 14:50:09 +00:00
|
|
|
class MathData;
|
2001-11-09 14:23:44 +00:00
|
|
|
class MathMacroTemplate;
|
2003-06-02 10:03:27 +00:00
|
|
|
class MathMacro;
|
2016-11-16 14:07:00 +00:00
|
|
|
class MathRow;
|
2003-06-02 10:03:27 +00:00
|
|
|
class TextPainter;
|
|
|
|
class TextMetricsInfo;
|
|
|
|
class ReplaceData;
|
2001-10-19 11:25:48 +00:00
|
|
|
|
2016-06-19 02:39:38 +00:00
|
|
|
/// Type of unique identifiers for math insets (used in TexRow)
|
|
|
|
typedef void const * uid_type;
|
|
|
|
|
2001-10-19 11:25:48 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
class InsetMath : public Inset {
|
2002-03-21 17:42:56 +00:00
|
|
|
public:
|
2009-11-08 11:45:46 +00:00
|
|
|
///
|
|
|
|
InsetMath(Buffer * buf = 0) : Inset(buf) {}
|
2004-01-15 11:58:35 +00:00
|
|
|
/// identification as math inset
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMath * asInsetMath() { return this; }
|
2009-08-01 21:39:14 +00:00
|
|
|
/// identification as math inset
|
|
|
|
InsetMath const * asInsetMath() const { return this; }
|
2004-02-25 14:39:14 +00:00
|
|
|
/// this is overridden in math text insets (i.e. mbox)
|
|
|
|
bool inMathed() const { return true; }
|
2011-03-28 22:33:04 +00:00
|
|
|
///
|
|
|
|
virtual docstring name() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2009-07-06 00:48:07 +00:00
|
|
|
/// this is overridden by specific insets
|
|
|
|
virtual mode_type currentMode() const { return MATH_MODE; }
|
|
|
|
|
2017-02-08 15:42:14 +00:00
|
|
|
// The possible marker types for math insets
|
|
|
|
enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
|
2017-01-06 08:52:10 +00:00
|
|
|
/// this is overridden by insets with specific edit marker type
|
2017-02-08 15:42:14 +00:00
|
|
|
virtual marker_type marker(BufferView const *) const;
|
2017-01-06 08:52:10 +00:00
|
|
|
|
2002-03-18 11:45:53 +00:00
|
|
|
/// the ascent of the inset above the baseline
|
|
|
|
/// compute the size of the object for text based drawing
|
2003-05-28 13:22:36 +00:00
|
|
|
virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
|
2002-03-18 11:45:53 +00:00
|
|
|
/// draw the object as text
|
2002-03-21 06:57:13 +00:00
|
|
|
virtual void drawT(TextPainter &, int x, int y) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
/// return cell given its number
|
2007-04-26 16:05:57 +00:00
|
|
|
virtual MathData & cell(idx_type);
|
2001-11-22 09:48:57 +00:00
|
|
|
/// return cell given its number
|
2007-04-26 16:05:57 +00:00
|
|
|
virtual MathData const & cell(idx_type) const;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-11-09 12:01:10 +00:00
|
|
|
/// identifies certain types of insets
|
2006-09-16 18:11:38 +00:00
|
|
|
virtual InsetMathAMSArray * asAMSArrayInset() { return 0; }
|
|
|
|
virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
|
|
|
|
virtual InsetMathArray * asArrayInset() { return 0; }
|
|
|
|
virtual InsetMathArray const * asArrayInset() const { return 0; }
|
2007-11-01 10:58:59 +00:00
|
|
|
virtual InsetMathBrace * asBraceInset() { return 0; }
|
2006-09-16 18:11:38 +00:00
|
|
|
virtual InsetMathBrace const * asBraceInset() const { return 0; }
|
|
|
|
virtual InsetMathChar const * asCharInset() const { return 0; }
|
|
|
|
virtual InsetMathDelim * asDelimInset() { return 0; }
|
|
|
|
virtual InsetMathDelim const * asDelimInset() const { return 0; }
|
2015-06-14 16:10:29 +00:00
|
|
|
virtual InsetMathFracBase * asFracBaseInset() { return 0; }
|
|
|
|
virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
|
2006-09-16 18:11:38 +00:00
|
|
|
virtual InsetMathFrac * asFracInset() { return 0; }
|
|
|
|
virtual InsetMathFrac const * asFracInset() const { return 0; }
|
|
|
|
virtual InsetMathFont * asFontInset() { return 0; }
|
|
|
|
virtual InsetMathFont const * asFontInset() const { return 0; }
|
|
|
|
virtual InsetMathGrid * asGridInset() { return 0; }
|
|
|
|
virtual InsetMathGrid const * asGridInset() const { return 0; }
|
|
|
|
virtual InsetMathHull * asHullInset() { return 0; }
|
|
|
|
virtual InsetMathHull const * asHullInset() const { return 0; }
|
2004-04-13 06:27:29 +00:00
|
|
|
virtual MathMacro * asMacro() { return 0; }
|
|
|
|
virtual MathMacro const * asMacro() const { return 0; }
|
2002-08-09 10:22:35 +00:00
|
|
|
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
|
|
|
|
virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
|
2006-09-16 18:11:38 +00:00
|
|
|
virtual InsetMathMatrix const * asMatrixInset() const { return 0; }
|
|
|
|
virtual InsetMathNest * asNestInset() { return 0; }
|
|
|
|
virtual InsetMathNest const * asNestInset() const { return 0; }
|
|
|
|
virtual InsetMathScript * asScriptInset() { return 0; }
|
|
|
|
virtual InsetMathScript const * asScriptInset() const { return 0; }
|
|
|
|
virtual InsetMathSpace * asSpaceInset() { return 0; }
|
|
|
|
virtual InsetMathSpace const * asSpaceInset() const { return 0; }
|
|
|
|
virtual InsetMathString * asStringInset() { return 0; }
|
|
|
|
virtual InsetMathString const * asStringInset() const { return 0; }
|
|
|
|
virtual InsetMathSymbol const * asSymbolInset() const { return 0; }
|
|
|
|
virtual InsetMathUnknown * asUnknownInset() { return 0; }
|
|
|
|
virtual InsetMathUnknown const * asUnknownInset() const { return 0; }
|
2007-04-28 20:49:56 +00:00
|
|
|
virtual InsetMathRef * asRefInset() { return 0; }
|
2008-10-23 00:48:06 +00:00
|
|
|
virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
|
2001-10-12 12:02:49 +00:00
|
|
|
|
2016-05-30 08:33:35 +00:00
|
|
|
/// The class of the math object (used primarily for spacing)
|
|
|
|
virtual MathClass mathClass() const;
|
2016-11-16 14:07:00 +00:00
|
|
|
/// Add this inset to a math row. Return true if contents got added
|
2016-10-04 22:25:38 +00:00
|
|
|
virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
|
2017-02-01 14:20:06 +00:00
|
|
|
/// Hook that is run before metrics computation starts
|
|
|
|
virtual void beforeMetrics() const {}
|
|
|
|
/// Hook that is run after metrics computation
|
|
|
|
virtual void afterMetrics() const {}
|
|
|
|
/// Hook that is run before actual drawing
|
|
|
|
virtual void beforeDraw(PainterInfo const &) const {}
|
|
|
|
/// Hook that is run after drawing
|
|
|
|
virtual void afterDraw(PainterInfo const &) const {}
|
2016-05-30 08:33:35 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
/// identifies things that can get scripts
|
|
|
|
virtual bool isScriptable() const { return false; }
|
2002-07-10 07:15:36 +00:00
|
|
|
/// will this get written as a single block in {..}
|
|
|
|
virtual bool extraBraces() const { return false; }
|
2001-10-12 12:02:49 +00:00
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
/// return the content as char if the inset is able to do so
|
2006-10-22 10:15:23 +00:00
|
|
|
virtual char_type getChar() const { return 0; }
|
2001-09-11 10:58:17 +00:00
|
|
|
/// identifies things that can get \limits or \nolimits
|
|
|
|
virtual bool takesLimits() const { return false; }
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
/// replace things by other things
|
2001-11-16 09:55:37 +00:00
|
|
|
virtual void replace(ReplaceData &) {}
|
2002-02-01 17:01:30 +00:00
|
|
|
/// do we contain a given subsequence?
|
2007-04-26 16:05:57 +00:00
|
|
|
virtual bool contains(MathData const &) const { return false; }
|
2002-05-30 07:09:54 +00:00
|
|
|
/// access to the lock (only nest array have one)
|
|
|
|
virtual bool lock() const { return false; }
|
|
|
|
/// access to the lock (only nest array have one)
|
|
|
|
virtual void lock(bool) {}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
2014-12-19 10:35:37 +00:00
|
|
|
// Indicate that we do not want to hide the normal version of
|
|
|
|
// write(). This is to shut off a clang warning.
|
|
|
|
using Inset::write;
|
|
|
|
/// write LaTeX and LyX code
|
2002-01-11 15:23:10 +00:00
|
|
|
virtual void write(WriteStream & os) const;
|
2001-11-08 12:06:56 +00:00
|
|
|
/// write normalized content
|
2001-11-09 08:35:57 +00:00
|
|
|
virtual void normalize(NormalStream &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
/// write content as something readable by Maple
|
2003-02-14 14:30:09 +00:00
|
|
|
virtual void maple(MapleStream &) const;
|
2002-10-28 17:15:19 +00:00
|
|
|
/// write content as something readable by Maxima
|
2003-02-14 14:30:09 +00:00
|
|
|
virtual void maxima(MaximaStream &) const;
|
2002-07-01 11:17:14 +00:00
|
|
|
/// write content as something readable by Mathematica
|
2003-02-14 14:30:09 +00:00
|
|
|
virtual void mathematica(MathematicaStream &) const;
|
2010-03-29 22:52:13 +00:00
|
|
|
/// write content as MathML
|
2009-12-31 15:46:39 +00:00
|
|
|
virtual void mathmlize(MathStream &) const;
|
2010-03-29 22:52:13 +00:00
|
|
|
/// write content as HTML, best we can.
|
|
|
|
/// the idea for this, and some of the details, come from
|
|
|
|
/// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
|
|
|
|
/// we try to mimic how eLyXer outputs some math.
|
|
|
|
virtual void htmlize(HtmlStream &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
/// write content as something readable by Octave
|
2003-02-14 14:30:09 +00:00
|
|
|
virtual void octave(OctaveStream &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
|
2007-02-16 09:08:38 +00:00
|
|
|
/// plain text output in ucs4 encoding
|
2013-03-08 19:52:18 +00:00
|
|
|
int plaintext(odocstringstream &, OutputParams const &, size_t) const;
|
2007-02-16 09:08:38 +00:00
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
/// dump content to stderr for debugging
|
|
|
|
virtual void dump() const;
|
2002-07-08 06:39:40 +00:00
|
|
|
|
|
|
|
/// LyXInset stuff
|
|
|
|
virtual bool numberedType() const { return false; }
|
|
|
|
/// hull type
|
2006-09-03 16:14:51 +00:00
|
|
|
virtual HullType getType() const;
|
2002-07-08 06:39:40 +00:00
|
|
|
/// change type
|
2006-09-03 16:14:51 +00:00
|
|
|
virtual void mutate(HullType /*newtype*/) {}
|
2004-10-05 10:11:42 +00:00
|
|
|
|
2004-08-14 19:55:00 +00:00
|
|
|
/// math stuff usually isn't allowed in text mode
|
|
|
|
virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
|
2007-03-21 17:21:59 +00:00
|
|
|
|
2016-11-27 21:45:51 +00:00
|
|
|
/// Italic correction as described in InsetMathScript.h
|
2008-01-03 15:44:05 +00:00
|
|
|
virtual int kerning(BufferView const *) const { return 0; }
|
2009-07-16 19:00:24 +00:00
|
|
|
///
|
2010-10-26 01:10:19 +00:00
|
|
|
bool isInToc() const { return true; }
|
|
|
|
///
|
2009-07-16 19:00:24 +00:00
|
|
|
InsetCode lyxCode() const { return MATH_CODE; }
|
2015-10-13 23:23:12 +00:00
|
|
|
///
|
|
|
|
uid_type id() const { return this; }
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
///
|
2002-05-24 08:29:16 +00:00
|
|
|
std::ostream & operator<<(std::ostream &, MathAtom const &);
|
2006-10-19 16:51:30 +00:00
|
|
|
///
|
2006-10-21 00:16:43 +00:00
|
|
|
odocstream & operator<<(odocstream &, MathAtom const &);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2002-10-22 13:56:40 +00:00
|
|
|
// initialize math
|
2002-07-12 14:24:47 +00:00
|
|
|
void initMath();
|
2002-06-24 15:37:14 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|