mathed/InsetMathXArrow.cpp \
mathed/InsetMathXYMatrix.cpp \
mathed/InsetMathDiagram.cpp \
+ mathed/MacroTable.cpp \
mathed/MathAtom.cpp \
mathed/MathAutoCorrect.cpp \
+ mathed/MathClass.cpp \
mathed/MathData.cpp \
mathed/MathExtern.cpp \
mathed/MathFactory.cpp \
mathed/MathMacro.cpp \
mathed/MathMacroArgument.cpp \
- mathed/MacroTable.cpp \
mathed/MathMacroTemplate.cpp \
mathed/MathParser.cpp \
mathed/MathStream.cpp \
mathed/InsetMathDiagram.h \
mathed/MathAtom.h \
mathed/MathAutoCorrect.h \
+ mathed/MathClass.h \
mathed/MathData.h \
mathed/MathCompletionList.h \
mathed/MathExtern.h \
}
+MathClass InsetMath::mathClass() const
+{
+ return MC_ORD;
+}
+
+
void InsetMath::dump() const
{
lyxerr << "---------------------------------------------" << endl;
#ifndef MATH_INSET_H
#define MATH_INSET_H
+#include "MathClass.h"
+
#include "insets/Inset.h"
virtual InsetMathRef * asRefInset() { return 0; }
virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
+ /// The class of the math object (used primarily for spacing)
+ virtual MathClass mathClass() const;
+
/// identifies things that can get scripts
virtual bool isScriptable() const { return false; }
- /// identifies a binary operators (used for spacing)
- virtual bool isMathBin() const { return false; }
- /// identifies relational operators (used for spacing and splitting equations)
- virtual bool isMathRel() const { return false; }
- /// identifies punctuation (used for spacing)
- virtual bool isMathPunct() const { return false; }
/// will this get written as a single block in {..}
virtual bool extraBraces() const { return false; }
dim = fm.dimension(char_);
kerning_ = fm.rbearing(char_) - dim.wid;
}
- if (mathfont && isMathPunct())
- dim.wid += mathed_thinmuskip(mi.base.font);
}
}
-bool InsetMathChar::isMathBin() const
+MathClass InsetMathChar::mathClass() const
{
- return subst_ && subst_->extra == "mathbin";
-}
-
-
-bool InsetMathChar::isMathRel() const
-{
- return subst_ && subst_->extra == "mathrel";
-}
-
-
-bool InsetMathChar::isMathPunct() const
-{
- return support::contains(",;", static_cast<char>(char_))
- || (subst_ && subst_->extra == "mathpunct");
+ // this information comes from fontmath.ltx in LaTeX source.
+ char const ch = static_cast<char>(char_);
+ if (subst_)
+ return string_to_class(subst_->extra);
+ else if (support::contains(",;", ch))
+ return MC_PUNCT;
+ else if (support::contains("([", ch))
+ return MC_OPEN;
+ else if (support::contains(")]!?", ch))
+ return MC_CLOSE;
+ else return MC_ORD;
}
///
char_type getChar() const { return char_; }
///
- bool isMathBin() const;
- ///
- bool isMathRel() const;
- ///
- bool isMathPunct() const;
+ MathClass mathClass() const;
///
InsetCode lyxCode() const { return MATH_CHAR_CODE; }
dw_ = 8;
if (dw_ < 4)
dw_ = 4;
- dim.wid = dim0.width() + 2 * dw_ + 2 * mathed_thinmuskip(mi.base.font);
+ dim.wid = dim0.width() + 2 * dw_;
dim.asc = max(a0, d0) + h0;
dim.des = max(a0, d0) - h0;
}
{
Dimension const dim = dimension(*pi.base.bv);
int const b = y - dim.asc;
- int const skip = mathed_thinmuskip(pi.base.font);
- cell(0).draw(pi, x + dw_ + skip, y);
- mathed_draw_deco(pi, x + skip, b, dw_, dim.height(), left_);
- mathed_draw_deco(pi, x + dim.width() - dw_ - skip,
+ cell(0).draw(pi, x + dw_, y);
+ mathed_draw_deco(pi, x, b, dw_, dim.height(), left_);
+ mathed_draw_deco(pi, x + dim.width() - dw_,
b, dw_, dim.height(), right_);
setPosCache(pi, x, y);
}
InsetMathDelim * asDelimInset() { return this; }
///
InsetMathDelim const * asDelimInset() const { return this; }
+ ///
+ MathClass mathClass() const { return MC_INNER; }
/// is it (...)?
bool isParenthesis() const;
/// is it [...]?
}
+MathClass InsetMathFrac::mathClass() const
+{
+ // Generalized fractions are of inner class (see The TeXbook, p. 292)
+ // But stuff from the unit/nicefrac packages are not real fractions.
+ MathClass mc = MC_ORD;
+ switch (kind_) {
+ case ATOP:
+ case OVER:
+ case FRAC:
+ case DFRAC:
+ case TFRAC:
+ case CFRAC:
+ case CFRACLEFT:
+ case CFRACRIGHT:
+ mc = MC_INNER;
+ break;
+ case NICEFRAC:
+ case UNITFRAC:
+ case UNIT:
+ break;
+ }
+ return mc;
+}
+
+
void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const
{
Dimension dim0, dim1, dim2;
///
bool idxBackward(Cursor &) const;
///
+ MathClass mathClass() const;
+ ///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo &, int x, int y) const;
void write(WriteStream & os) const;
///
void normalize(NormalStream &) const;
+ /// Generalized fractions are of inner class (see The TeXbook, p.292)
+ MathClass mathClass() const { return MC_INNER; }
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
size_t firstRelOp(MathData const & ar)
{
for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
- if ((*it)->isMathRel())
+ if ((*it)->mathClass() == MC_REL)
return it - ar.begin();
return ar.size();
}
}
+MathClass InsetMathScript::mathClass() const
+{
+ // FIXME: this is a hack, since the class will not be correct if
+ // the nucleus has several elements.
+ // The correct implementation would require to linearize the nucleus.
+ if (nuc().empty())
+ return MC_ORD;
+ else
+ // return the class of last element since this is the one that counts.
+ return nuc().back()->mathClass();
+}
+
+
void InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
{
Dimension dim0;
///
mode_type currentMode() const { return MATH_MODE; }
///
+ MathClass mathClass() const;
+ ///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
}
+MathClass InsetMathStackrel::mathClass() const
+{
+ // FIXME: update this when/if \stackbin is supported
+ return MC_REL;
+}
+
+
void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
{
Dimension dim1;
///
bool idxUpDown(Cursor &, bool up) const;
///
+ MathClass mathClass() const;
+ ///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo & pi, int x, int y) const;
void mathmlize(MathStream &) const;
///
void htmlize(HtmlStream &) const;
- ///
+ ///
void validate(LaTeXFeatures &) const;
///
InsetCode lyxCode() const { return MATH_STACKREL_CODE; }
dim.asc += h_;
dim.des -= h_;
}
- // set striptable_
+ // set scriptable_
scriptable_ = false;
if (mi.base.style == LM_ST_DISPLAY)
if (sym_->inset == "cmex" || sym_->inset == "esint" ||
}
-bool InsetMathSymbol::isMathBin() const
-{
- return sym_->extra == "mathbin";
-}
-
-
-bool InsetMathSymbol::isMathRel() const
-{
- return sym_->extra == "mathrel";
-}
-
-
-bool InsetMathSymbol::isMathPunct() const
+bool InsetMathSymbol::isOrdAlpha() const
{
- return sym_->extra == "mathpunct";
+ return sym_->extra == "mathord" || sym_->extra == "mathalpha";
}
-bool InsetMathSymbol::isOrdAlpha() const
+MathClass InsetMathSymbol::mathClass() const
{
- return sym_->extra == "mathord" || sym_->extra == "mathalpha";
+ if (sym_->extra == "func" || sym_->extra == "funclim")
+ return MC_OP;
+ MathClass const mc = string_to_class(sym_->extra);
+ return (mc == MC_UNKNOWN) ? MC_ORD : mc;
}
///
mode_type currentMode() const;
///
- bool isMathRel() const;
- ///
- bool isMathBin() const;
- ///
- bool isMathPunct() const;
+ MathClass mathClass() const;
///
bool isOrdAlpha() const;
/// do we take scripts?
--- /dev/null
+/**
+ * \file MathClass.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "MathClass.h"
+
+#include "support/docstring.h"
+#include "support/lassert.h"
+
+using namespace std;
+
+namespace lyx {
+
+
+docstring const class_to_string(MathClass const mc)
+{
+ string s;
+ switch (mc) {
+ case MC_ORD:
+ s = "mathord";
+ break;
+ case MC_OP:
+ s = "mathop";
+ break;
+ case MC_BIN:
+ s = "mathbin";
+ break;
+ case MC_REL:
+ s = "mathrel";
+ break;
+ case MC_OPEN:
+ s = "mathopen";
+ break;
+ case MC_CLOSE:
+ s = "mathclose";
+ break;
+ case MC_PUNCT:
+ s = "mathpunct";
+ break;
+ case MC_INNER:
+ s = "mathinner";
+ break;
+ case MC_UNKNOWN:
+ LATTEST(false);
+ s = "mathord";
+ }
+ return from_ascii(s);
+}
+
+
+MathClass string_to_class(docstring const &s)
+{
+ if (s == "mathop")
+ return MC_OP;
+ else if (s == "mathbin")
+ return MC_BIN;
+ else if (s == "mathrel")
+ return MC_REL;
+ else if (s == "mathopen")
+ return MC_OPEN;
+ else if (s == "mathclose")
+ return MC_CLOSE;
+ else if (s == "mathpunct")
+ return MC_PUNCT;
+ else if (s == "mathinner")
+ return MC_INNER;
+ else if (s == "mathord")
+ return MC_ORD;
+ else
+ return MC_UNKNOWN;
+}
+
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file MathClass.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef MATH_CLASS_H
+#define MATH_CLASS_H
+
+#include "support/strfwd.h"
+
+namespace lyx {
+
+
+/* The TeXbook, p. 158:
+ *
+ * There are thirteen kinds of atoms, each of which might act
+ * differently in a formula; for example, ‘(’ is an Open atom because
+ * it comes from an opening. Here is a complete list of the different
+ * kinds:
+
+ * + Ord: an ordinary atom like ‘x’
+ * + Op: a large operator atom like ‘\sum’
+ * + Bin: a binary operation atom like ‘+’
+ * + Rel: a relation atom like ‘=’
+ * + Open: an opening atom like ‘(’
+ * + Close: a closing atom like ‘)’
+ * + Punct: a punctuation atom like ‘,’
+ * + Inner: an inner atom like ‘\frac{1}{2}’
+ * + Over: an overline atom like ‘\overline{x}’
+ * + Under: an underline atom like ‘\underline{x}’
+ * + Acc: an accented atom like ‘\hat{x}’
+ * + Rad: a radical atom like ‘\sqrt{2}’
+ * + Vcent: a vbox to be centered, produced by \vcenter.
+ *
+ * Over, Under, Acc, Rad and Vcent are not considered in the enum
+ * below. The relvant elements will be considered as Ord.
+ */
+enum MathClass {
+ MC_ORD,
+ MC_OP,
+ MC_BIN,
+ MC_REL,
+ MC_OPEN,
+ MC_CLOSE,
+ MC_PUNCT,
+ MC_INNER,
+ MC_UNKNOWN
+};
+
+
+MathClass string_to_class(docstring const &);
+
+docstring const class_to_string(MathClass);
+
+
+} // namespace lyx
+
+#endif
std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
Changer dummy = mi.base.changeFontSet(font);
mathed_string_dim(mi.base.font, sym->draw, dim);
- // seperate things a bit
- if (sym->extra == "mathbin")
- dim.wid += 2 * mathed_medmuskip(mi.base.font);
- else if (sym->extra == "mathrel")
- dim.wid += 2 * mathed_thickmuskip(mi.base.font);
- else if (sym->extra == "mathpunct")
- dim.wid += mathed_thinmuskip(mi.base.font);
}
sym->extra == "mathalpha" &&
pi.base.fontname == "mathit";
std::string const font = italic_upcase_greek ? "cmm" : sym->inset;
- if (sym->extra == "mathbin")
- x += mathed_medmuskip(pi.base.font);
- else if (sym->extra == "mathrel")
- x += mathed_thickmuskip(pi.base.font);
Changer dummy = pi.base.changeFontSet(font);
pi.draw(x, y, sym->draw);