2 #include "math_spaceinset.h"
4 #include "math_support.h"
6 #include "frontends/Painter.h"
7 #include "math_mathmlstream.h"
8 #include "LaTeXFeatures.h"
12 char const * latex_mathspace[] = {
13 "!", "negmedspace", "negthickspace", // negative space
14 ",", ":", ";", "quad", "qquad", // positive space
15 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
18 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
21 MathSpaceInset::MathSpaceInset(int sp)
26 MathSpaceInset::MathSpaceInset(string const & name)
29 for (int i = 0; i < nSpace; ++i)
30 if (latex_mathspace[i] == name)
35 MathInset * MathSpaceInset::clone() const
37 return new MathSpaceInset(*this);
41 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
44 case 0: dim.wid = 6; break;
45 case 1: dim.wid = 8; break;
46 case 2: dim.wid = 10; break;
47 case 3: dim.wid = 6; break;
48 case 4: dim.wid = 8; break;
49 case 5: dim.wid = 10; break;
50 case 6: dim.wid = 20; break;
51 case 7: dim.wid = 40; break;
52 case 8: dim.wid = -2; break;
53 case 9: dim.wid = 2; break;
61 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
64 // Sadly, HP-UX CC can't handle that kind of initialization.
65 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
66 if (space_ >= nSpace - 2)
72 xp[0] = ++x; yp[0] = y - 3;
74 xp[2] = x + pi.width - 2; yp[2] = y;
75 xp[3] = x + pi.width - 2; yp[3] = y - 3;
77 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
81 void MathSpaceInset::incSpace()
83 space_ = (space_ + 1) % (nSpace - 2);
87 void MathSpaceInset::validate(LaTeXFeatures & features) const
89 if (space_ >= 0 && space_< nSpace) {
90 if ((latex_mathspace[space_] == "negmedspace")
91 || (latex_mathspace[space_] == "negthickspace"))
92 features.require("amsmath");
97 void MathSpaceInset::maple(MapleStream & os) const
102 void MathSpaceInset::mathematica(MathematicaStream & os) const
108 void MathSpaceInset::octave(OctaveStream & os) const
114 void MathSpaceInset::normalize(NormalStream & os) const
116 os << "[space " << int(space_) << "] ";
120 void MathSpaceInset::write(WriteStream & os) const
122 if (space_ >= 0 && space_ < nSpace) {
123 os << '\\' << latex_mathspace[space_];
124 os.pendingSpace(true);