The attached patch adds support for \makebox (box without frame and inner box). This fixes http://www.lyx.org/trac/ticket/2956 and is a fileformat change.
You might think that such a box is useless. But we should leave the decision to the user. LaTeX is offering \makebox for good reasons and experienced users might want to use \makebox without being forced to use TeX code.
OK to go in? regards Uwe
Index: lib/lyx2lyx/lyx_2_0.py =================================================================== --- lib/lyx2lyx/lyx_2_0.py (revision 34709) +++ lib/lyx2lyx/lyx_2_0.py (working copy) @@ -1717,7 +1717,44 @@ return document.body[i] = "\\begin_inset OptArg" i += 1 - + + +def revert_makebox(document): + " Convert \\makebox to ERT " + i = 0 + while 1: + # only revert frameless boxes without an inner box + i = find_token(document.body, '\\begin_inset Box Frameless', i) + if i == -1: + return + else: + z = find_end_of_inset(document.body, i) + if z == -1: + document.warning("Malformed LyX document: Can't find end of box inset.") + return + j = find_token(document.body, 'has_inner_box 0', i) + # assure we found the inner box of the current box + if j > i+3 or j == -1: + return + else: + # remove the \end_inset + document.body[z-2:z+1] = put_cmd_in_ert("}") + # determine the alignment + k = find_token(document.body, 'hor_pos', j-1) + align = document.body[k][9] + # determine the width + l = find_token(document.body, 'width "', j+3) + length = document.body[l][7:] + # remove trailing '"' + length = length[:-1] + # latex_length returns "bool,length" + length = latex_length(length).split(",")[1] + subst = "\\makebox[" + length + "][" \ + + align + "]{" + document.body[i:i+13] = put_cmd_in_ert(subst) + i += 1 + + ## # Conversion hub # @@ -1770,10 +1807,12 @@ [390, []], [391, []], [392, [convert_beamer_args]], - [393, [convert_optarg]] + [393, [convert_optarg]], + [394, []], ] -revert = [[392, [revert_argument]], +revert = [[393, [revert_makebox]], + [392, [revert_argument]], [391, [revert_beamer_args]], [390, [revert_align_decimal]], [389, [revert_output_sync]], Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (revision 34709) +++ src/Buffer.cpp (working copy) @@ -126,7 +126,7 @@ // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 393; // rgh: rename OptArg to Argument in LyX format +int const LYX_FORMAT = 394; // uwestoehr: support for \makebox typedef map<string, bool> DepClean; typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache; Index: src/frontends/qt4/GuiBox.cpp =================================================================== --- src/frontends/qt4/GuiBox.cpp (revision 34709) +++ src/frontends/qt4/GuiBox.cpp (working copy) @@ -156,14 +156,14 @@ && type != "Boxed"); widthED->setEnabled(!width_disabled); widthUnitsLC->setEnabled(!width_disabled); - setInnerType(frameless, itype); + setInnerType(itype); changed(); } void GuiBox::initDialog() { - setInnerType(true, toqstr("minipage")); + setInnerType(toqstr("minipage")); widthED->setText("100"); widthUnitsLC->setCurrentItem(Length::PCW); heightCB->setCheckState(Qt::Checked); @@ -226,7 +226,7 @@ if (params.use_parbox) inner_type = "parbox"; bool const frameless = (params.type == "Frameless"); - setInnerType(frameless, inner_type); + setInnerType(inner_type); char c = params.pos; valignCO->setCurrentIndex(string("tcb").find(c, 0)); @@ -350,14 +350,10 @@ } -void GuiBox::setInnerType(bool frameless, QString const & type) +void GuiBox::setInnerType(QString const & type) { - // with "frameless" boxes, inner box is mandatory - // (i.e. is the actual box) - // we have to remove "none" then and adjust the combo innerBoxCO->clear(); - if (!frameless) - innerBoxCO->addItem(qt_("None"), toqstr("none")); + innerBoxCO->addItem(qt_("None"), toqstr("none")); innerBoxCO->addItem(qt_("Parbox"), toqstr("parbox")); innerBoxCO->addItem(qt_("Minipage"), toqstr("minipage")); int i = (innerBoxCO->findData(type) != -1) Index: src/frontends/qt4/GuiBox.h =================================================================== --- src/frontends/qt4/GuiBox.h (revision 34709) +++ src/frontends/qt4/GuiBox.h (working copy) @@ -46,7 +46,7 @@ /// add and remove special lengths void setSpecial(bool ibox); /// only show valid inner box items - void setInnerType(bool frameless, QString const & type); + void setInnerType(QString const & type); QStringList ids_; /// Index: src/insets/InsetBox.cpp =================================================================== --- src/insets/InsetBox.cpp (revision 34709) +++ src/insets/InsetBox.cpp (working copy) @@ -274,6 +274,21 @@ switch (btype) { case Frameless: + if (!params_.inner_box) { + os << "\\makebox"; + // Special widths, see usrguide §3.5 + // FIXME UNICODE + if (params_.special != "none") { + os << "[" << params_.width.value() + << '\\' << from_utf8(params_.special) + << ']'; + } else + os << '[' << from_ascii(width_string) + << ']'; + if (params_.hor_pos != 'c') + os << "[" << params_.hor_pos << "]"; + os << "{"; + } break; case Framed: os << "\\begin{framed}%\n"; @@ -294,7 +309,6 @@ if (params_.hor_pos != 'c') os << "[" << params_.hor_pos << "]"; } - os << "{"; break; case ovalbox: @@ -368,6 +382,8 @@ switch (btype) { case Frameless: + if (!params_.inner_box) + os << "}"; break; case Framed: os << "\\end{framed}"; @@ -398,6 +414,8 @@ switch (btype) { case Frameless: + if (!params_.inner_box) + os << "[\n"; break; case Framed: case Boxed: @@ -423,7 +441,11 @@ int len = 0; switch (btype) { case Frameless: - os << "\n"; + if (!params_.inner_box) { + os << "\n]"; + len = 1; + } else + os << "\n"; break; case Framed: case Boxed: