InsetSpace support for

- \negmedspace and \negthickspace outside of math
- \enspace, \hspace*, \hspace*{\fill} and \hfill inside math
(fileformat change)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39557 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2011-08-29 14:07:30 +00:00
parent 6a0ab44ca7
commit f5a03ab601
12 changed files with 216 additions and 182 deletions

View File

@ -11,6 +11,12 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
----------------------- -----------------------
2011-08-30 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 416 (r3xxxx)
support for \negmedspace and \negthinspace outside of math
support for \hfill, \enspace and \hspace* in math
No new InsetSpace parameters
2011-07-30 Uwe Stöhr <uwestoehr@web.de> 2011-07-30 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 415 (r39464) * Format incremented to 415 (r39464)
support for the LaTeX-package undertilde (fix bug 6622) support for the LaTeX-package undertilde (fix bug 6622)

View File

@ -61,12 +61,12 @@ def revert_visible_space(document):
"Revert InsetSpace visible into its ERT counterpart" "Revert InsetSpace visible into its ERT counterpart"
i = 0 i = 0
while True: while True:
i = find_token(document.body, "\\begin_inset space \\textvisiblespace{}", i) i = find_token(document.body, "\\begin_inset space \\textvisiblespace{}", i)
if i == -1: if i == -1:
return return
end = find_end_of_inset(document.body, i) end = find_end_of_inset(document.body, i)
subst = put_cmd_in_ert("\\textvisiblespace{}") subst = put_cmd_in_ert("\\textvisiblespace{}")
document.body[i:end + 1] = subst document.body[i:end + 1] = subst
def convert_undertilde(document): def convert_undertilde(document):
@ -78,7 +78,6 @@ def convert_undertilde(document):
def revert_undertilde(document): def revert_undertilde(document):
" Load undertilde if used in the document " " Load undertilde if used in the document "
undertilde = find_token(document.header, "\\use_undertilde" , 0) undertilde = find_token(document.header, "\\use_undertilde" , 0)
if undertilde == -1: if undertilde == -1:
document.warning("No \\use_undertilde line. Assuming auto.") document.warning("No \\use_undertilde line. Assuming auto.")
@ -118,16 +117,63 @@ def revert_undertilde(document):
i = j i = j
def revert_negative_space(document):
"Revert InsetSpace negmedspace and negthickspace into its TeX-code counterpart"
i = 0
j = 0
reverted = False
while True:
i = find_token(document.body, "\\begin_inset space \\negmedspace{}", i)
if i == -1:
j = find_token(document.body, "\\begin_inset space \\negthickspace{}", j)
if j == -1:
# load amsmath in the preamble if not already loaded if we are at the end of checking
if reverted == True:
i = find_token(document.header, "\\use_amsmath 2", 0)
if i == -1:
add_to_preamble(document, ["\\@ifundefined{negthickspace}{\\usepackage{amsmath}}"])
return
if i == -1:
return
end = find_end_of_inset(document.body, i)
subst = put_cmd_in_ert("\\negmedspace{}")
document.body[i:end + 1] = subst
j = find_token(document.body, "\\begin_inset space \\negthickspace{}", j)
if j == -1:
return
end = find_end_of_inset(document.body, j)
subst = put_cmd_in_ert("\\negthickspace{}")
document.body[j:end + 1] = subst
reverted = True
def revert_math_spaces(document):
"Revert formulas with protected custom space and protected hfills to TeX-code"
i = 0
while True:
i = find_token(document.body, "\\begin_inset Formula", i)
if i == -1:
return
j = document.body[i].find("\\hspace*")
if j != -1:
end = find_end_of_inset(document.body, i)
subst = put_cmd_in_ert(document.body[i][21:])
document.body[i:end + 1] = subst
i = i + 1
## ##
# Conversion hub # Conversion hub
# #
supported_versions = ["2.1.0","2.1"] supported_versions = ["2.1.0","2.1"]
convert = [[414, []], convert = [[414, []],
[415, [convert_undertilde]] [415, [convert_undertilde]],
[416, []]
] ]
revert = [[414, [revert_undertilde]], revert = [[415, [revert_negative_space,revert_math_spaces]],
[414, [revert_undertilde]],
[413, [revert_visible_space]] [413, [revert_visible_space]]
] ]

View File

@ -160,8 +160,11 @@ medspace space none
; space none ; space none
thickspace space none thickspace space none
enskip space none enskip space none
enspace space none
quad space none quad space none
qquad space none qquad space none
hfill space none
hspace* space none
hspace space none hspace space none
# styles # styles

View File

@ -128,7 +128,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // independent branches. Instead add your own.
int const LYX_FORMAT = 415; //uwestoehr : support for package undertilde (bug 6622) int const LYX_FORMAT = 416; //uwestoehr : support for horizontal spaces (bug 7728)
typedef map<string, bool> DepClean; typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache; typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -476,8 +476,8 @@ void LyXAction::init()
* \li Action: Inserts one of horizontal space insets. * \li Action: Inserts one of horizontal space insets.
* \li Syntax: space-insert <NAME> [<LEN>] * \li Syntax: space-insert <NAME> [<LEN>]
* \li Params: <NAME>: normal, protected, visible, thin, quad, qquad, enspace, * \li Params: <NAME>: normal, protected, visible, thin, quad, qquad, enspace,
enskip, negthinspace, hfill, hfill*, dotfill, hrulefill, hspace, enskip, negthinspace, negmedspace, negthickspace, hfill,
hspace* \n hfill*, dotfill, hrulefill, hspace, hspace* \n
<LEN>: length for custom spaces (hspace, hspace* for protected) <LEN>: length for custom spaces (hspace, hspace* for protected)
* \li Origin: JSpitzm, 20 May 2003, Mar 17 2008 * \li Origin: JSpitzm, 20 May 2003, Mar 17 2008
* \endvar * \endvar

View File

@ -400,9 +400,9 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
isp.kind = InsetSpaceParams::ENSKIP; isp.kind = InsetSpaceParams::ENSKIP;
else if (name == "negthinspace") else if (name == "negthinspace")
isp.kind = InsetSpaceParams::NEGTHIN; isp.kind = InsetSpaceParams::NEGTHIN;
else if (isp.math && name == "negmedspace") else if (name == "negmedspace")
isp.kind = InsetSpaceParams::NEGMEDIUM; isp.kind = InsetSpaceParams::NEGMEDIUM;
else if (isp.math && name == "negthickspace") else if (name == "negthickspace")
isp.kind = InsetSpaceParams::NEGTHICK; isp.kind = InsetSpaceParams::NEGTHICK;
else if (name == "hfill") else if (name == "hfill")
isp.kind = InsetSpaceParams::HFILL; isp.kind = InsetSpaceParams::HFILL;

View File

@ -42,26 +42,29 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
spacingCO->clear(); spacingCO->clear();
if (math_mode_) { if (math_mode_) {
spacingCO->addItem(qt_("Thin Space")); spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
spacingCO->addItem(qt_("Medium Space")); spacingCO->addItem(qt_("Medium Space"), toqstr("medspace"));
spacingCO->addItem(qt_("Thick Space")); spacingCO->addItem(qt_("Thick Space"), toqstr("thickspace"));
spacingCO->addItem(qt_("Negative Thin Space")); spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
spacingCO->addItem(qt_("Negative Medium Space")); spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
spacingCO->addItem(qt_("Negative Thick Space")); spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
spacingCO->addItem(qt_("Half Quad (0.5 em)")); spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
spacingCO->addItem(qt_("Quad (1 em)")); spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
spacingCO->addItem(qt_("Double Quad (2 em)")); spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
spacingCO->addItem(qt_("Custom")); spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
spacingCO->addItem(qt_("Custom"), toqstr("custom"));
} else { } else {
spacingCO->addItem(qt_("Interword Space")); spacingCO->addItem(qt_("Interword Space"), toqstr("normal"));
spacingCO->addItem(qt_("Thin Space")); spacingCO->addItem(qt_("Thin Space"), toqstr("thinspace"));
spacingCO->addItem(qt_("Negative Thin Space")); spacingCO->addItem(qt_("Negative Thin Space"), toqstr("negthinspace"));
spacingCO->addItem(qt_("Half Quad (0.5 em)")); spacingCO->addItem(qt_("Negative Medium Space"), toqstr("negmedspace"));
spacingCO->addItem(qt_("Quad (1 em)")); spacingCO->addItem(qt_("Negative Thick Space"), toqstr("negthickspace"));
spacingCO->addItem(qt_("Double Quad (2 em)")); spacingCO->addItem(qt_("Half Quad (0.5 em)"), toqstr("halfquad"));
spacingCO->addItem(qt_("Horizontal Fill")); spacingCO->addItem(qt_("Quad (1 em)"), toqstr("quad"));
spacingCO->addItem(qt_("Custom")); spacingCO->addItem(qt_("Double Quad (2 em)"), toqstr("qquad"));
spacingCO->addItem(qt_("Visible Space")); spacingCO->addItem(qt_("Horizontal Fill"), toqstr("hfill"));
spacingCO->addItem(qt_("Custom"), toqstr("custom"));
spacingCO->addItem(qt_("Visible Space"), toqstr("visible"));
} }
connect(spacingCO, SIGNAL(highlighted(QString)), connect(spacingCO, SIGNAL(highlighted(QString)),
@ -96,21 +99,14 @@ void GuiHSpace::changedSlot()
void GuiHSpace::enableWidgets() void GuiHSpace::enableWidgets()
{ {
int const selection = spacingCO->currentIndex(); QString const selection = spacingCO->itemData(spacingCO->currentIndex()).toString();
bool const custom = (math_mode_ && selection == 9) || bool const custom = selection == "custom";
(!math_mode_ && selection == 7);
valueLE->setEnabled(custom); valueLE->setEnabled(custom);
unitCO->setEnabled(custom); unitCO->setEnabled(custom);
if (math_mode_) { fillPatternCO->setEnabled(!math_mode_ && selection == "hfill");
fillPatternCO->setEnabled(false); bool const no_pattern = fillPatternCO->currentIndex() == 0 || math_mode_;
keepCB->setEnabled(false);
return;
}
fillPatternCO->setEnabled(selection == 6);
bool const no_pattern = fillPatternCO->currentIndex() == 0;
bool const enable_keep = bool const enable_keep =
selection == 0 || selection == 3 || selection == "normal" || selection == "halfquad" || (selection == "hfill" && no_pattern) || custom;
(selection == 6 && no_pattern) || custom;
keepCB->setEnabled(enable_keep); keepCB->setEnabled(enable_keep);
} }
@ -121,97 +117,95 @@ void GuiHSpace::paramsToDialog(Inset const * inset)
? static_cast<InsetMathSpace const *>(inset)->params() ? static_cast<InsetMathSpace const *>(inset)->params()
: static_cast<InsetSpace const *>(inset)->params(); : static_cast<InsetSpace const *>(inset)->params();
int item = 0; QString item;
int pattern = 0; int pattern = 0;
bool protect = false; bool protect = false;
switch (params.kind) { switch (params.kind) {
case InsetSpaceParams::NORMAL: case InsetSpaceParams::NORMAL:
item = 0; item = "normal";
break; break;
case InsetSpaceParams::PROTECTED: case InsetSpaceParams::PROTECTED:
item = 0; item = "normal";
protect = !params.math; protect = true;
break; break;
case InsetSpaceParams::VISIBLE: case InsetSpaceParams::VISIBLE:
item = 8; item = "visible";
protect = true; protect = true;
break; break;
case InsetSpaceParams::THIN: case InsetSpaceParams::THIN:
item = params.math ? 0 : 1; item = "thinspace";
break; break;
case InsetSpaceParams::MEDIUM: case InsetSpaceParams::MEDIUM:
item = 1; item = "medspace";
break; break;
case InsetSpaceParams::THICK: case InsetSpaceParams::THICK:
item = params.math ? 2 : 1; item = "thickspace";
break; break;
case InsetSpaceParams::NEGTHIN: case InsetSpaceParams::NEGTHIN:
item = params.math ? 3 : 2; item = "negthinspace";
break; break;
case InsetSpaceParams::NEGMEDIUM: case InsetSpaceParams::NEGMEDIUM:
item = params.math ? 4 : 2; item = "negmedspace";
break; break;
case InsetSpaceParams::NEGTHICK: case InsetSpaceParams::NEGTHICK:
item = params.math ? 5 : 2; item = "negthickspace";
break; break;
case InsetSpaceParams::ENSKIP: case InsetSpaceParams::ENSKIP:
item = params.math ? 6 : 3; item = "halfquad";
break; break;
case InsetSpaceParams::ENSPACE: case InsetSpaceParams::ENSPACE:
item = params.math ? 6 : 3; item = "halfquad";
protect = !params.math; protect = true;
break; break;
case InsetSpaceParams::QUAD: case InsetSpaceParams::QUAD:
item = params.math ? 7 : 4; item = "quad";
break; break;
case InsetSpaceParams::QQUAD: case InsetSpaceParams::QQUAD:
item = params.math ? 8 : 5; item = "qquad";
break; break;
case InsetSpaceParams::HFILL: case InsetSpaceParams::HFILL:
item = params.math ? 3 : 6; item = "hfill";
break; break;
case InsetSpaceParams::HFILL_PROTECTED: case InsetSpaceParams::HFILL_PROTECTED:
item = params.math ? 3 : 6; item = "hfill";
protect = !params.math; protect = true;
break; break;
case InsetSpaceParams::DOTFILL: case InsetSpaceParams::DOTFILL:
item = params.math ? 3 : 6; item = "hfill";
pattern = 1; pattern = 1;
break; break;
case InsetSpaceParams::HRULEFILL: case InsetSpaceParams::HRULEFILL:
item = params.math ? 3 : 6; item = "hfill";
pattern = 2; pattern = 2;
break; break;
case InsetSpaceParams::LEFTARROWFILL: case InsetSpaceParams::LEFTARROWFILL:
item = params.math ? 3 : 6; item = "hfill";
pattern = 3; pattern = 3;
break; break;
case InsetSpaceParams::RIGHTARROWFILL: case InsetSpaceParams::RIGHTARROWFILL:
item = params.math ? 3 : 6; item = "hfill";
pattern = 4; pattern = 4;
break; break;
case InsetSpaceParams::UPBRACEFILL: case InsetSpaceParams::UPBRACEFILL:
item = params.math ? 3 : 6; item = "hfill";
pattern = 5; pattern = 5;
break; break;
case InsetSpaceParams::DOWNBRACEFILL: case InsetSpaceParams::DOWNBRACEFILL:
item = params.math ? 3 : 6; item = "hfill";
pattern = 6; pattern = 6;
break; break;
case InsetSpaceParams::CUSTOM: case InsetSpaceParams::CUSTOM:
item = params.math ? 9 : 7; item = "custom";
break; break;
case InsetSpaceParams::CUSTOM_PROTECTED: case InsetSpaceParams::CUSTOM_PROTECTED:
item = params.math ? 9 : 7; item = "custom";
protect = !params.math; protect = true;
break; break;
} }
spacingCO->setCurrentIndex(item); spacingCO->setCurrentIndex(spacingCO->findData(item));
fillPatternCO->setCurrentIndex(pattern); fillPatternCO->setCurrentIndex(pattern);
keepCB->setChecked(protect); keepCB->setChecked(protect);
if (math_mode_) { if (item == "halfquad") {
keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
} else if (item == 3) {
keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n" keepCB->setToolTip(qt_("Insert the spacing even after a line break.\n"
"Note that a protected Half Quad will be turned into\n" "Note that a protected Half Quad will be turned into\n"
"a vertical space if used at the beginning of a paragraph!")); "a vertical space if used at the beginning of a paragraph!"));
@ -219,7 +213,7 @@ void GuiHSpace::paramsToDialog(Inset const * inset)
keepCB->setToolTip(qt_("Insert the spacing even after a line break")); keepCB->setToolTip(qt_("Insert the spacing even after a line break"));
} }
Length::UNIT const default_unit = Length::defaultUnit(); Length::UNIT const default_unit = Length::defaultUnit();
if (item == (params.math ? 9 : 7)) { if (item == "custom") {
string length = params.length.asString(); string length = params.length.asString();
lengthToWidgets(valueLE, unitCO, length, default_unit); lengthToWidgets(valueLE, unitCO, length, default_unit);
} else } else
@ -229,99 +223,70 @@ void GuiHSpace::paramsToDialog(Inset const * inset)
} }
docstring GuiHSpace::dialogToMathParams() const
{
InsetSpaceParams params(true);
switch (spacingCO->currentIndex()) {
case 0: params.kind = InsetSpaceParams::THIN; break;
case 1: params.kind = InsetSpaceParams::MEDIUM; break;
case 2: params.kind = InsetSpaceParams::THICK; break;
case 3: params.kind = InsetSpaceParams::NEGTHIN; break;
case 4: params.kind = InsetSpaceParams::NEGMEDIUM; break;
case 5: params.kind = InsetSpaceParams::NEGTHICK; break;
case 6: params.kind = InsetSpaceParams::ENSKIP; break;
case 7: params.kind = InsetSpaceParams::QUAD; break;
case 8: params.kind = InsetSpaceParams::QQUAD; break;
case 9:
params.kind = InsetSpaceParams::CUSTOM;
params.length = GlueLength(widgetsToLength(valueLE, unitCO));
break;
}
return from_ascii(InsetSpace::params2string(params));
}
docstring GuiHSpace::dialogToParams() const docstring GuiHSpace::dialogToParams() const
{ {
if (math_mode_) InsetSpaceParams params = math_mode_ ?
return dialogToMathParams(); InsetSpaceParams(true) : InsetSpaceParams(false);
InsetSpaceParams params(false); QString const item =
spacingCO->itemData(spacingCO->currentIndex()).toString();
switch (spacingCO->currentIndex()) { if (item == "normal")
case 0: params.kind = keepCB->isChecked() ?
if (keepCB->isChecked()) InsetSpaceParams::PROTECTED : InsetSpaceParams::NORMAL;
params.kind = InsetSpaceParams::PROTECTED; else if (item == "thinspace")
else params.kind = InsetSpaceParams::THIN;
params.kind = InsetSpaceParams::NORMAL; else if (item == "medspace")
break; params.kind = InsetSpaceParams::MEDIUM;
else if (item == "thickspace")
params.kind = InsetSpaceParams::THICK;
else if (item == "negthinspace")
params.kind = InsetSpaceParams::NEGTHIN;
else if (item == "negmedspace")
params.kind = InsetSpaceParams::NEGMEDIUM;
else if (item == "negthickspace")
params.kind = InsetSpaceParams::NEGTHICK;
else if (item == "halfquad")
params.kind = keepCB->isChecked() ?
InsetSpaceParams::ENSPACE : InsetSpaceParams::ENSKIP;
else if (item == "quad")
params.kind = InsetSpaceParams::QUAD;
else if (item == "qquad")
params.kind = InsetSpaceParams::QQUAD;
else if (item == "hfill") {
switch (fillPatternCO->currentIndex()) {
case 1: case 1:
params.kind = InsetSpaceParams::THIN; params.kind = InsetSpaceParams::DOTFILL;
break; break;
case 2: case 2:
params.kind = InsetSpaceParams::NEGTHIN; params.kind = InsetSpaceParams::HRULEFILL;
break; break;
case 3: case 3:
if (keepCB->isChecked()) params.kind = InsetSpaceParams::LEFTARROWFILL;
params.kind = InsetSpaceParams::ENSPACE;
else
params.kind = InsetSpaceParams::ENSKIP;
break; break;
case 4: case 4:
params.kind = InsetSpaceParams::QUAD; params.kind = InsetSpaceParams::RIGHTARROWFILL;
break; break;
case 5: case 5:
params.kind = InsetSpaceParams::QQUAD; params.kind = InsetSpaceParams::UPBRACEFILL;
break; break;
case 6: case 6:
switch (fillPatternCO->currentIndex()) { params.kind = InsetSpaceParams::DOWNBRACEFILL;
case 1:
params.kind = InsetSpaceParams::DOTFILL;
break;
case 2:
params.kind = InsetSpaceParams::HRULEFILL;
break;
case 3:
params.kind = InsetSpaceParams::LEFTARROWFILL;
break;
case 4:
params.kind = InsetSpaceParams::RIGHTARROWFILL;
break;
case 5:
params.kind = InsetSpaceParams::UPBRACEFILL;
break;
case 6:
params.kind = InsetSpaceParams::DOWNBRACEFILL;
break;
default:
if (keepCB->isChecked())
params.kind = InsetSpaceParams::HFILL_PROTECTED;
else
params.kind = InsetSpaceParams::HFILL;
break;
}
break; break;
case 7: default:
if (keepCB->isChecked()) if (keepCB->isChecked())
params.kind = InsetSpaceParams::CUSTOM_PROTECTED; params.kind = InsetSpaceParams::HFILL_PROTECTED;
else else
params.kind = InsetSpaceParams::CUSTOM; params.kind = InsetSpaceParams::HFILL;
break;
}
} else if (item == "custom") {
params.kind = keepCB->isChecked() ?
InsetSpaceParams::CUSTOM_PROTECTED : InsetSpaceParams::CUSTOM;
params.length = GlueLength(widgetsToLength(valueLE, unitCO)); params.length = GlueLength(widgetsToLength(valueLE, unitCO));
break; } else if (item == "visible")
case 8: params.kind = InsetSpaceParams::VISIBLE;
params.kind = InsetSpaceParams::VISIBLE;
break;
}
return from_ascii(InsetSpace::params2string(params)); return from_ascii(InsetSpace::params2string(params));
} }
@ -330,7 +295,7 @@ bool GuiHSpace::checkWidgets() const
{ {
if (!InsetParamsWidget::checkWidgets()) if (!InsetParamsWidget::checkWidgets())
return false; return false;
return spacingCO->currentIndex() != (math_mode_ ? 9 : 7) return spacingCO->itemData(spacingCO->currentIndex()).toString() != "custom"
|| !valueLE->text().isEmpty(); || !valueLE->text().isEmpty();
} }

View File

@ -34,15 +34,13 @@ private Q_SLOTS:
private: private:
/// \name InsetParamsWidget inherited methods /// \name InsetParamsWidget inherited methods
//@{ //@{
InsetCode insetCode() const { return SPACE_CODE; } InsetCode insetCode() const { return math_mode_ ? MATH_SPACE_CODE : SPACE_CODE; }
FuncCode creationCode() const { return LFUN_INSET_INSERT; } FuncCode creationCode() const { return LFUN_INSET_INSERT; }
void paramsToDialog(Inset const *); void paramsToDialog(Inset const *);
docstring dialogToParams() const; docstring dialogToParams() const;
bool checkWidgets() const; bool checkWidgets() const;
//@} //@}
/// ///
docstring dialogToMathParams() const;
///
bool const math_mode_; bool const math_mode_;
}; };

View File

@ -488,9 +488,9 @@ void InsetSpaceParams::read(Lexer & lex)
kind = InsetSpaceParams::ENSKIP; kind = InsetSpaceParams::ENSKIP;
else if (command == "\\negthinspace{}") else if (command == "\\negthinspace{}")
kind = InsetSpaceParams::NEGTHIN; kind = InsetSpaceParams::NEGTHIN;
else if (math && command == "\\negmedspace{}") else if (command == "\\negmedspace{}")
kind = InsetSpaceParams::NEGMEDIUM; kind = InsetSpaceParams::NEGMEDIUM;
else if (math && command == "\\negthickspace{}") else if (command == "\\negthickspace{}")
kind = InsetSpaceParams::NEGTHICK; kind = InsetSpaceParams::NEGTHICK;
else if (command == "\\hfill{}") else if (command == "\\hfill{}")
kind = InsetSpaceParams::HFILL; kind = InsetSpaceParams::HFILL;

View File

@ -45,23 +45,27 @@ struct SpaceInfo {
}; };
SpaceInfo space_info[] = { SpaceInfo space_info[] = {
// name width kind negative visible custom // name width kind negative visible custom
{"!", 6, InsetSpaceParams::NEGTHIN, true, true, false}, {"!", 6, InsetSpaceParams::NEGTHIN, true, true, false},
{"negthinspace", 6, InsetSpaceParams::NEGTHIN, true, true, false}, {"negthinspace", 6, InsetSpaceParams::NEGTHIN, true, true, false},
{"negmedspace", 8, InsetSpaceParams::NEGMEDIUM, true, true, false}, {"negmedspace", 8, InsetSpaceParams::NEGMEDIUM, true, true, false},
{"negthickspace", 10, InsetSpaceParams::NEGTHICK, true, true, false}, {"negthickspace", 10, InsetSpaceParams::NEGTHICK, true, true, false},
{",", 6, InsetSpaceParams::THIN, false, true, false}, {",", 6, InsetSpaceParams::THIN, false, true, false},
{"thinspace", 6, InsetSpaceParams::THIN, false, true, false}, {"thinspace", 6, InsetSpaceParams::THIN, false, true, false},
{":", 8, InsetSpaceParams::MEDIUM, false, true, false}, {":", 8, InsetSpaceParams::MEDIUM, false, true, false},
{"medspace", 8, InsetSpaceParams::MEDIUM, false, true, false}, {"medspace", 8, InsetSpaceParams::MEDIUM, false, true, false},
{";", 10, InsetSpaceParams::THICK, false, true, false}, {";", 10, InsetSpaceParams::THICK, false, true, false},
{"thickspace", 10, InsetSpaceParams::THICK, false, true, false}, {"thickspace", 10, InsetSpaceParams::THICK, false, true, false},
{"enskip", 10, InsetSpaceParams::ENSKIP, false, true, false}, {"enskip", 10, InsetSpaceParams::ENSKIP, false, true, false},
{"quad", 20, InsetSpaceParams::QUAD, false, true, false}, {"enspace", 10, InsetSpaceParams::ENSPACE, false, true, false},
{"qquad", 40, InsetSpaceParams::QQUAD, false, true, false}, {"quad", 20, InsetSpaceParams::QUAD, false, true, false},
{"lyxnegspace", -2, InsetSpaceParams::NEGTHIN, true, false, false}, {"qquad", 40, InsetSpaceParams::QQUAD, false, true, false},
{"lyxposspace", 2, InsetSpaceParams::THIN, false, false, false}, {"lyxnegspace", -2, InsetSpaceParams::NEGTHIN, true, false, false},
{"hspace", 0, InsetSpaceParams::CUSTOM, false, true, true}, {"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},
}; };
int const nSpace = sizeof(space_info)/sizeof(SpaceInfo); int const nSpace = sizeof(space_info)/sizeof(SpaceInfo);
@ -93,11 +97,12 @@ InsetMathSpace::InsetMathSpace(string const & name, string const & length)
} }
InsetMathSpace::InsetMathSpace(Length const & length) InsetMathSpace::InsetMathSpace(Length const & length, bool const prot)
: space_(defaultSpace), length_(length) : space_(defaultSpace), length_(length)
{ {
for (int i = 0; i < nSpace; ++i) for (int i = 0; i < nSpace; ++i)
if (space_info[i].name == "hspace") { if ((prot && space_info[i].name == "hspace*")
|| (!prot && space_info[i].name == "hspace")) {
space_ = i; space_ = i;
break; break;
} }
@ -221,6 +226,7 @@ void InsetMathSpace::htmlize(HtmlStream & ms) const
ms << from_ascii("&emsp;"); ms << from_ascii("&emsp;");
break; break;
case InsetSpaceParams::ENSKIP: case InsetSpaceParams::ENSKIP:
case InsetSpaceParams::ENSPACE:
ms << from_ascii("&ensp;"); ms << from_ascii("&ensp;");
break; break;
case InsetSpaceParams::QUAD: case InsetSpaceParams::QUAD:
@ -229,7 +235,12 @@ void InsetMathSpace::htmlize(HtmlStream & ms) const
case InsetSpaceParams::QQUAD: case InsetSpaceParams::QQUAD:
ms << from_ascii("&emsp;&emsp;"); ms << from_ascii("&emsp;&emsp;");
break; break;
case InsetSpaceParams::CUSTOM: { case InsetSpaceParams::HFILL:
case InsetSpaceParams::HFILL_PROTECTED:
// FIXME: is there a useful HTML entity?
break;
case InsetSpaceParams::CUSTOM:
case InsetSpaceParams::CUSTOM_PROTECTED: {
string l = length_.asHTMLString(); string l = length_.asHTMLString();
ms << MTag("span", "width='" + l + "'") ms << MTag("span", "width='" + l + "'")
<< from_ascii("&nbsp;") << ETag("span"); << from_ascii("&nbsp;") << ETag("span");

View File

@ -28,7 +28,7 @@ public:
/// ///
explicit InsetMathSpace(std::string const & name, std::string const & length); explicit InsetMathSpace(std::string const & name, std::string const & length);
/// ///
explicit InsetMathSpace(Length const & length); explicit InsetMathSpace(Length const & length, bool const prot = false);
/// ///
InsetMathSpace const * asSpaceInset() const { return this; } InsetMathSpace const * asSpaceInset() const { return this; }
/// ///

View File

@ -1751,12 +1751,17 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE); parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE);
} }
else if (t.cs() == "hspace" && nextToken().character() != '*') { else if (t.cs() == "hspace") {
bool const prot = nextToken().character() == '*';
if (prot)
getToken();
docstring const name = t.cs(); docstring const name = t.cs();
docstring const arg = parse_verbatim_item(); docstring const arg = parse_verbatim_item();
Length length; Length length;
if (isValidLength(to_utf8(arg), &length)) if (prot && arg == "\\fill")
cell->push_back(MathAtom(new InsetMathSpace(length))); cell->push_back(MathAtom(new InsetMathSpace("hspace*{\\fill}", "")));
else if (isValidLength(to_utf8(arg), &length))
cell->push_back(MathAtom(new InsetMathSpace(length, prot)));
else { else {
// Since the Length class cannot use length variables // Since the Length class cannot use length variables
// we must not create an InsetMathSpace. // we must not create an InsetMathSpace.