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"
15 #include "MathStream.h"
17 #include "LaTeXFeatures.h"
20 #include "frontends/Painter.h"
26 char const * latex_mathspace[] = {
27 "!", "negmedspace", "negthickspace", // negative space
28 ",", ":", ";", "quad", "qquad", // positive space
29 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
32 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
36 int spaceToWidth(int space)
55 InsetMathSpace::InsetMathSpace(int sp)
60 dim_.wid = spaceToWidth(space_);
64 InsetMathSpace::InsetMathSpace(docstring const & name)
69 for (int i = 0; i < nSpace; ++i)
70 if (latex_mathspace[i] == name)
72 dim_.wid = spaceToWidth(space_);
76 Inset * InsetMathSpace::clone() const
78 return new InsetMathSpace(*this);
82 void InsetMathSpace::metrics(MetricsInfo &, Dimension & dim) const
88 void InsetMathSpace::draw(PainterInfo & pi, int x, int y) const
90 // Sadly, HP-UX CC can't handle that kind of initialization.
91 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
92 if (space_ >= nSpace - 2)
99 xp[0] = ++x; yp[0] = y - 3;
100 xp[1] = x; yp[1] = y;
101 xp[2] = x + w - 2; yp[2] = y;
102 xp[3] = x + w - 2; yp[3] = y - 3;
104 pi.pain.lines(xp, yp, 4, (space_ < 3) ? Color::latex : Color::math);
108 void InsetMathSpace::incSpace()
110 space_ = (space_ + 1) % (nSpace - 2);
111 dim_.wid = spaceToWidth(space_);
115 void InsetMathSpace::validate(LaTeXFeatures & features) const
117 if (space_ >= 0 && space_< nSpace) {
118 if ((latex_mathspace[space_] == string("negmedspace"))
119 || (latex_mathspace[space_] == string("negthickspace")))
120 features.require("amsmath");
125 void InsetMathSpace::maple(MapleStream & os) const
130 void InsetMathSpace::mathematica(MathematicaStream & os) const
136 void InsetMathSpace::octave(OctaveStream & os) const
142 void InsetMathSpace::normalize(NormalStream & os) const
144 os << "[space " << int(space_) << "] ";
148 void InsetMathSpace::write(WriteStream & os) const
150 if (space_ >= 0 && space_ < nSpace) {
151 os << '\\' << latex_mathspace[space_];
152 os.pendingSpace(true);