Fix some bugs related to spaces in math:

- Interpret argument of LFUN_SPACE_INSERT correctly
- Use InsetMathSpace instead of InsetMathSpecialChar for "\ " (bug # 7728)
- Use InsetMathSpace instead of InsetMathChar for ~ (bug # 7728).
  This fixes also the display in LyX (previously a literal ~ was displayed).
Using InsetMathSpace enables also the "Insert Formatting" menu entries.
No file format change is needed, since the LaTeX export is unchanged.
Note that there are still some bugs related to spaces in math:
#7746, #7747, #7749, #7842


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39947 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2011-10-23 20:19:49 +00:00
parent 6781444835
commit 8e8c214bef
14 changed files with 67 additions and 52 deletions

View File

@ -51,7 +51,6 @@
#include "TextMetrics.h"
#include "TexRow.h"
#include "TocBackend.h"
#include "VSpace.h"
#include "WordLangTuple.h"
#include "insets/InsetBibtex.h"

View File

@ -478,6 +478,7 @@ void LyXAction::init()
* \li Params: <NAME>: normal, protected, visible, thin, quad, qquad, enspace,
enskip, negthinspace, negmedspace, negthickspace, hfill,
hfill*, dotfill, hrulefill, hspace, hspace* \n
Only in math mode: med and thick.\n
<LEN>: length for custom spaces (hspace, hspace* for protected)
* \li Origin: JSpitzm, 20 May 2003, Mar 17 2008
* \endvar

View File

@ -43,7 +43,6 @@
#include "TextClass.h"
#include "TexRow.h"
#include "Text.h"
#include "VSpace.h"
#include "WordLangTuple.h"
#include "WordList.h"

View File

@ -34,7 +34,6 @@
#include "sgml.h"
#include "TextClass.h"
#include "TexRow.h"
#include "VSpace.h"
#include "frontends/FontMetrics.h"

View File

@ -46,7 +46,6 @@
#include "ParIterator.h"
#include "TextClass.h"
#include "TextMetrics.h"
#include "VSpace.h"
#include "WordLangTuple.h"
#include "WordList.h"

View File

@ -42,7 +42,6 @@
#include "ParagraphParameters.h"
#include "TextClass.h"
#include "TextMetrics.h"
#include "VSpace.h"
#include "insets/InsetCollapsable.h"

View File

@ -45,7 +45,6 @@
#include "SpellChecker.h"
#include "TextClass.h"
#include "TextMetrics.h"
#include "VSpace.h"
#include "WordLangTuple.h"
#include "frontends/Application.h"

View File

@ -42,6 +42,7 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
spacingCO->clear();
if (math_mode_) {
spacingCO->addItem(qt_("Interword Space"), toqstr("normal"));
spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
spacingCO->addItem(qt_("Medium Space"), toqstr("medspace"));
spacingCO->addItem(qt_("Thick Space"), toqstr("thickspace"));

View File

@ -1134,10 +1134,34 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
}
case LFUN_SPACE_INSERT:
case LFUN_SPACE_INSERT: {
cur.recordUndoSelection();
cur.insert(MathAtom(new InsetMathSpace));
string const name = cmd.getArg(0);
if (name == "normal")
cur.insert(MathAtom(new InsetMathSpace(" ", "")));
else if (name == "protected")
cur.insert(MathAtom(new InsetMathSpace("~", "")));
else if (name == "thin" || name == "med" || name == "thick")
cur.insert(MathAtom(new InsetMathSpace(name + "space", "")));
else if (name == "hfill*")
cur.insert(MathAtom(new InsetMathSpace("hspace*{\\fill}", "")));
else if (name == "quad" || name == "qquad" ||
name == "enspace" || name == "enskip" ||
name == "negthinspace" || name == "negmedspace" ||
name == "negthickspace" || name == "hfill")
cur.insert(MathAtom(new InsetMathSpace(name, "")));
else if (name == "hspace" || name == "hspace*") {
string const len = cmd.getArg(1);
if (len.empty() || !isValidLength(len)) {
lyxerr << "LyX function 'space-insert " << name << "' "
"needs a valid length argument." << endl;
break;
}
cur.insert(MathAtom(new InsetMathSpace(name, len)));
} else
cur.insert(MathAtom(new InsetMathSpace));
break;
}
case LFUN_MATH_SPACE:
cur.recordUndoSelection();
@ -1420,7 +1444,7 @@ bool InsetMathNest::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_SPACE_INSERT: {
docstring const & name = cmd.argument();
if (name == "protected" || name == "normal" || name == "visible")
if (name == "visible")
flag.setEnabled(false);
break;
}

View File

@ -42,30 +42,33 @@ struct SpaceInfo {
bool negative;
bool visible;
bool custom;
bool escape; ///< whether a backslash needs to be added for writing
};
SpaceInfo space_info[] = {
// name width kind negative visible custom
{"!", 6, InsetSpaceParams::NEGTHIN, true, true, false},
{"negthinspace", 6, InsetSpaceParams::NEGTHIN, true, true, false},
{"negmedspace", 8, InsetSpaceParams::NEGMEDIUM, true, true, false},
{"negthickspace", 10, InsetSpaceParams::NEGTHICK, true, true, false},
{",", 6, InsetSpaceParams::THIN, false, true, false},
{"thinspace", 6, InsetSpaceParams::THIN, false, true, false},
{":", 8, InsetSpaceParams::MEDIUM, false, true, false},
{"medspace", 8, InsetSpaceParams::MEDIUM, false, true, false},
{";", 10, InsetSpaceParams::THICK, false, true, false},
{"thickspace", 10, InsetSpaceParams::THICK, false, true, false},
{"enskip", 10, InsetSpaceParams::ENSKIP, false, true, false},
{"enspace", 10, InsetSpaceParams::ENSPACE, false, true, false},
{"quad", 20, InsetSpaceParams::QUAD, false, true, false},
{"qquad", 40, InsetSpaceParams::QQUAD, false, true, false},
{"lyxnegspace", -2, InsetSpaceParams::NEGTHIN, true, false, false},
{"lyxposspace", 2, InsetSpaceParams::THIN, false, false, false},
{"hfill", 80, InsetSpaceParams::HFILL, false, true, false},
{"hspace*{\\fill}", 80, InsetSpaceParams::HFILL_PROTECTED, false, true, false},
{"hspace*", 0, InsetSpaceParams::CUSTOM_PROTECTED, false, true, true},
{"hspace", 0, InsetSpaceParams::CUSTOM, false, true, true},
// name width kind negative visible custom escape
{"!", 6, InsetSpaceParams::NEGTHIN, true, true, false, true},
{"negthinspace", 6, InsetSpaceParams::NEGTHIN, true, true, false, true},
{"negmedspace", 8, InsetSpaceParams::NEGMEDIUM, true, true, false, true},
{"negthickspace", 10, InsetSpaceParams::NEGTHICK, true, true, false, true},
{",", 6, InsetSpaceParams::THIN, false, true, false, true},
{"thinspace", 6, InsetSpaceParams::THIN, false, true, false, true},
{":", 8, InsetSpaceParams::MEDIUM, false, true, false, true},
{"medspace", 8, InsetSpaceParams::MEDIUM, false, true, false, true},
{";", 10, InsetSpaceParams::THICK, false, true, false, true},
{"thickspace", 10, InsetSpaceParams::THICK, false, true, false, true},
{"enskip", 10, InsetSpaceParams::ENSKIP, false, true, false, true},
{"enspace", 10, InsetSpaceParams::ENSPACE, false, true, false, true},
{"quad", 20, InsetSpaceParams::QUAD, false, true, false, true},
{"qquad", 40, InsetSpaceParams::QQUAD, false, true, false, true},
{"lyxnegspace", -2, InsetSpaceParams::NEGTHIN, true, false, false, true},
{"lyxposspace", 2, InsetSpaceParams::THIN, false, false, false, true},
{"hfill", 80, InsetSpaceParams::HFILL, false, true, false, true},
{"hspace*{\\fill}", 80, InsetSpaceParams::HFILL_PROTECTED, false, true, false, true},
{"hspace*", 0, InsetSpaceParams::CUSTOM_PROTECTED,false, true, true, true},
{"hspace", 0, InsetSpaceParams::CUSTOM, false, true, true, true},
{" ", 10, InsetSpaceParams::NORMAL, false, true, false, true},
{"~", 10, InsetSpaceParams::PROTECTED, false, true, false, false},
};
int const nSpace = sizeof(space_info)/sizeof(SpaceInfo);
@ -246,6 +249,10 @@ void InsetMathSpace::htmlize(HtmlStream & ms) const
<< from_ascii("&nbsp;") << ETag("span");
break;
}
case InsetSpaceParams::NORMAL:
case InsetSpaceParams::PROTECTED:
ms << from_ascii("&nbsp;");
break;
default:
break;
}
@ -261,10 +268,12 @@ void InsetMathSpace::normalize(NormalStream & os) const
void InsetMathSpace::write(WriteStream & os) const
{
// no MathEnsurer - all kinds work in text and math mode
os << '\\' << space_info[space_].name.c_str();
if (space_info[space_].escape)
os << '\\';
os << space_info[space_].name.c_str();
if (space_info[space_].custom)
os << '{' << length_.asLatexString().c_str() << '}';
else
else if (space_info[space_].escape && space_info[space_].name != " ")
os.pendingSpace(true);
}

View File

@ -55,11 +55,7 @@ Inset * InsetMathSpecialChar::clone() const
void InsetMathSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (char_ == ' ') {
dim.asc = 4;
dim.des = 0;
dim.wid = 10;
} else if (mi.base.fontname == "mathnormal") {
if (mi.base.fontname == "mathnormal") {
ShapeChanger dummy(mi.base.font, UP_SHAPE);
dim = theFontMetrics(mi.base.font).dimension(char_);
} else {
@ -72,18 +68,7 @@ void InsetMathSpecialChar::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetMathSpecialChar::draw(PainterInfo & pi, int x, int y) const
{
if (char_ == ' ') {
int xp[4];
int yp[4];
int w = 10;
xp[0] = ++x; yp[0] = y - 3;
xp[1] = x; yp[1] = y;
xp[2] = x + w - 2; yp[2] = y;
xp[3] = x + w - 2; yp[3] = y - 3;
pi.pain.lines(xp, yp, 4, Color_special);
} else if (pi.base.fontname == "mathnormal") {
if (pi.base.fontname == "mathnormal") {
ShapeChanger dummy(pi.base.font, UP_SHAPE);
pi.draw(x, y, char_);
} else {

View File

@ -240,7 +240,7 @@ bool isSpecialChar(docstring const & name)
char_type const c = name.at(0);
return c == '{' || c == '}' || c == '&' || c == '$' ||
c == '#' || c == '%' || c == '_' || c == ' ';
c == '#' || c == '%' || c == '_';
}
@ -505,6 +505,8 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
return MathAtom(new InsetMathEnsureMath(buf));
if (isSpecialChar(s))
return MathAtom(new InsetMathSpecialChar(s));
if (s == " ")
return MathAtom(new InsetMathSpace(" ", ""));
if (s == "regexp")
return MathAtom(new InsetMathHull(buf, hullRegexp));

View File

@ -914,7 +914,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
}
else if (t.cat() == catActive)
cell->push_back(MathAtom(new InsetMathChar(t.character())));
cell->push_back(MathAtom(new InsetMathSpace(string(1, t.character()), "")));
else if (t.cat() == catBegin) {
MathData ar;

View File

@ -25,7 +25,6 @@
#include "ParagraphParameters.h"
#include "TextClass.h"
#include "TexRow.h"
#include "VSpace.h"
#include "insets/InsetBibitem.h"
#include "insets/InsetArgument.h"