2 * \file InsetMathSpace.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathSpace.h"
14 #include "MathArray.h"
15 #include "MathStream.h"
17 #include "LaTeXFeatures.h"
20 #include "frontends/Painter.h"
28 char const * latex_mathspace[] = {
29 "!", "negmedspace", "negthickspace", // negative space
30 ",", ":", ";", "quad", "qquad", // positive space
31 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
34 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
38 int spaceToWidth(int space)
57 InsetMathSpace::InsetMathSpace(int sp)
62 dim_.wid = spaceToWidth(space_);
66 InsetMathSpace::InsetMathSpace(docstring const & name)
71 for (int i = 0; i < nSpace; ++i)
72 if (latex_mathspace[i] == name)
74 dim_.wid = spaceToWidth(space_);
78 auto_ptr<InsetBase> InsetMathSpace::doClone() const
80 return auto_ptr<InsetBase>(new InsetMathSpace(*this));
84 bool InsetMathSpace::metrics(MetricsInfo &, Dimension & dim) const
96 void InsetMathSpace::draw(PainterInfo & pi, int x, int y) const
98 // Sadly, HP-UX CC can't handle that kind of initialization.
99 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
100 if (space_ >= nSpace - 2)
107 xp[0] = ++x; yp[0] = y - 3;
108 xp[1] = x; yp[1] = y;
109 xp[2] = x + w - 2; yp[2] = y;
110 xp[3] = x + w - 2; yp[3] = y - 3;
112 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
116 void InsetMathSpace::incSpace()
118 space_ = (space_ + 1) % (nSpace - 2);
119 dim_.wid = spaceToWidth(space_);
123 void InsetMathSpace::validate(LaTeXFeatures & features) const
125 if (space_ >= 0 && space_< nSpace) {
126 if ((latex_mathspace[space_] == string("negmedspace"))
127 || (latex_mathspace[space_] == string("negthickspace")))
128 features.require("amsmath");
133 void InsetMathSpace::maple(MapleStream & os) const
138 void InsetMathSpace::mathematica(MathematicaStream & os) const
144 void InsetMathSpace::octave(OctaveStream & os) const
150 void InsetMathSpace::normalize(NormalStream & os) const
152 os << "[space " << int(space_) << "] ";
156 void InsetMathSpace::write(WriteStream & os) const
158 if (space_ >= 0 && space_ < nSpace) {
159 os << '\\' << latex_mathspace[space_];
160 os.pendingSpace(true);