1 #include "math_spaceinset.h"
3 #include "math_support.h"
5 #include "frontends/Painter.h"
6 #include "math_mathmlstream.h"
7 #include "LaTeXFeatures.h"
13 char const * latex_mathspace[] = {
14 "!", "negmedspace", "negthickspace", // negative space
15 ",", ":", ";", "quad", "qquad", // positive space
16 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
19 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
22 MathSpaceInset::MathSpaceInset(int sp)
27 MathSpaceInset::MathSpaceInset(string const & name)
30 for (int i = 0; i < nSpace; ++i)
31 if (latex_mathspace[i] == name)
36 auto_ptr<InsetBase> MathSpaceInset::clone() const
38 return auto_ptr<InsetBase>(new MathSpaceInset(*this));
42 void MathSpaceInset::metrics(MetricsInfo &, Dimension & dim) const
45 case 0: dim.wid = 6; break;
46 case 1: dim.wid = 8; break;
47 case 2: dim.wid = 10; break;
48 case 3: dim.wid = 6; break;
49 case 4: dim.wid = 8; break;
50 case 5: dim.wid = 10; break;
51 case 6: dim.wid = 20; break;
52 case 7: dim.wid = 40; break;
53 case 8: dim.wid = -2; break;
54 case 9: dim.wid = 2; break;
62 void MathSpaceInset::draw(PainterInfo & pi, int x, int y) const
65 // Sadly, HP-UX CC can't handle that kind of initialization.
66 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
67 if (space_ >= nSpace - 2)
73 xp[0] = ++x; yp[0] = y - 3;
75 xp[2] = x + pi.width - 2; yp[2] = y;
76 xp[3] = x + pi.width - 2; yp[3] = y - 3;
78 pi.pain.lines(xp, yp, 4, (space_ < 3) ? LColor::latex : LColor::math);
82 void MathSpaceInset::incSpace()
84 space_ = (space_ + 1) % (nSpace - 2);
88 void MathSpaceInset::validate(LaTeXFeatures & features) const
90 if (space_ >= 0 && space_< nSpace) {
91 if ((latex_mathspace[space_] == "negmedspace")
92 || (latex_mathspace[space_] == "negthickspace"))
93 features.require("amsmath");
98 void MathSpaceInset::maple(MapleStream & os) const
103 void MathSpaceInset::mathematica(MathematicaStream & os) const
109 void MathSpaceInset::octave(OctaveStream & os) const
115 void MathSpaceInset::normalize(NormalStream & os) const
117 os << "[space " << int(space_) << "] ";
121 void MathSpaceInset::write(WriteStream & os) const
123 if (space_ >= 0 && space_ < nSpace) {
124 os << '\\' << latex_mathspace[space_];
125 os.pendingSpace(true);