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"
19 #include "frontends/Painter.h"
25 char const * latex_mathspace[] = {
26 "!", "negmedspace", "negthickspace", // negative space
27 ",", ":", ";", "quad", "qquad", // positive space
28 "lyxnegspace", "lyxposspace" // LyX special ("unvisible space")
31 int const nSpace = sizeof(latex_mathspace)/sizeof(char *);
35 int spaceToWidth(int space)
54 InsetMathSpace::InsetMathSpace(int sp)
59 dim_.wid = spaceToWidth(space_);
63 InsetMathSpace::InsetMathSpace(docstring const & name)
68 for (int i = 0; i < nSpace; ++i)
69 if (latex_mathspace[i] == name)
71 dim_.wid = spaceToWidth(space_);
75 Inset * InsetMathSpace::clone() const
77 return new InsetMathSpace(*this);
81 void InsetMathSpace::metrics(MetricsInfo &, Dimension & dim) const
87 void InsetMathSpace::draw(PainterInfo & pi, int x, int y) const
89 // Sadly, HP-UX CC can't handle that kind of initialization.
90 // XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
91 if (space_ >= nSpace - 2)
98 xp[0] = ++x; yp[0] = y - 3;
100 xp[2] = x + w - 2; yp[2] = y;
101 xp[3] = x + w - 2; yp[3] = y - 3;
103 pi.pain.lines(xp, yp, 4, (space_ < 3) ? Color_latex : Color_math);
107 void InsetMathSpace::incSpace()
109 space_ = (space_ + 1) % (nSpace - 2);
110 dim_.wid = spaceToWidth(space_);
114 void InsetMathSpace::validate(LaTeXFeatures & features) const
116 if (space_ >= 0 && space_< nSpace) {
117 if ((latex_mathspace[space_] == string("negmedspace"))
118 || (latex_mathspace[space_] == string("negthickspace")))
119 features.require("amsmath");
124 void InsetMathSpace::maple(MapleStream & os) const
129 void InsetMathSpace::mathematica(MathematicaStream & os) const
135 void InsetMathSpace::octave(OctaveStream & os) const
141 void InsetMathSpace::normalize(NormalStream & os) const
143 os << "[space " << int(space_) << "] ";
147 void InsetMathSpace::write(WriteStream & os) const
149 if (space_ >= 0 && space_ < nSpace) {
150 bool brace = os.pendingBrace();
151 os.pendingBrace(false);
152 if (os.latex() && os.textMode()) {
153 os << "\\ensuremath{";
157 os << '\\' << latex_mathspace[space_];
158 os.pendingSpace(true);
159 os.pendingBrace(brace);