support for \mbox and \fbox

- fileformat change
- it was a pity that LyX did not yet support a simple rectangular frame without a defined width but LyX did this for e.g. oval frames
- \fbox and \mbox often occur in TeX files and can now be imported
This commit is contained in:
Uwe Stöhr 2013-03-22 01:33:58 +01:00
parent cb5dd33475
commit 22ad7e4369
8 changed files with 196 additions and 89 deletions

View File

@ -11,27 +11,32 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2013-08-22 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 468: support for \mbox and \fbox
New checkbox in the box dialog to avoid using an explicit
width.
2013-08-19 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 467: support for iwona fonts
new supported sansserif fonts "iwona", "iwonal", "iwonac"
and "iwonalc" and the math font "iwona-math"
2013-03-17 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 466: Powerdot updates.
- Support for item arguments ([...], <...>)
- Support for list option
- Support for Pause layout (like in beamer)
- Support for twocolumn layout
- Support for \onslide, \onslide* and \onslide+ via fle inset.
* Format incremented to 466: Powerdot updates.
- Support for item arguments ([...], <...>)
- Support for list option
- Support for Pause layout (like in beamer)
- Support for twocolumn layout
- Support for \onslide, \onslide* and \onslide+ via fle inset.
2013-03-16 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 465: Convert old beamer frames to new ones.
The layouts BeginFrame, BeginPlainFrame and EndFrame are now not
valied anymore (use "Frame", "PlainFrame" instead, and nesting).
* Format incremented to 465: Convert old beamer frames to new ones.
The layouts BeginFrame, BeginPlainFrame and EndFrame are now not
valied anymore (use "Frame", "PlainFrame" instead, and nesting).
2013-02-27 Kornel Benko <kornel@lyx.org>
* Format incremented to 464:
- Added "cancel" to the GUI handled list of LaTeX packages
* Format incremented to 464:
- Added "cancel" to the GUI handled list of LaTeX packages
2013-02-18 Julien Rioux <jrioux@lyx.org>
* Format incremented to 463:

View File

@ -4051,6 +4051,35 @@ def revert_powerdot_columns(document):
i = endlay
def revert_mbox_fbox(document):
'Convert revert mbox/fbox boxes to TeX-code'
i = 0
while True:
i = find_token(document.body, "\\begin_inset Box", i)
if i == -1:
return
j = find_token(document.body, "width", i)
if j != i + 7:
document.warning("Malformed LyX document: Can't find box width")
return
width = get_value(document.body, "width", j)
k = find_end_of_inset(document.body, j)
if k == -1:
document.warning("Malformed LyX document: Can't find end of box inset")
i += 1
continue
BeginLayout = find_token(document.body, "\\begin_layout Plain Layout", j)
EndLayout = find_token(document.body, "\\end_layout", BeginLayout)
# replace if width is "-999col%"
if (width == '"-999col%"'):
document.body[EndLayout:k + 1] = put_cmd_in_ert("}")
if document.body[i] == "\\begin_inset Box Frameless":
document.body[i:BeginLayout + 1] = put_cmd_in_ert("\\mbox{")
if document.body[i] == "\\begin_inset Box Boxed":
document.body[i:BeginLayout + 1] = put_cmd_in_ert("\\fbox{")
i = i + 1
##
# Conversion hub
#
@ -4110,10 +4139,12 @@ convert = [
[464, [convert_use_cancel]],
[465, [convert_lyxframes, remove_endframes]],
[466, []],
[467, []]
[467, []],
[468, []]
]
revert = [
[467, [revert_mbox_fbox]],
[466, [revert_iwona_fonts]],
[465, [revert_powerdot_flexes, revert_powerdot_pause, revert_powerdot_itemargs, revert_powerdot_columns]],
[464, []],

View File

@ -103,7 +103,7 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
widthED->setValidator(unsignedLengthValidator(widthED));
// initialize the length validator
addCheckedWidget(widthED, widthLA);
addCheckedWidget(widthED, widthCB);
addCheckedWidget(heightED, heightCB);
initDialog();
@ -125,15 +125,25 @@ void GuiBox::on_innerBoxCO_activated(int /* index */)
if (heightCB->isChecked() && !ibox)
heightCB->setChecked(false);
heightCB->setEnabled(ibox);
// the width can only be selected for makebox or framebox
widthCB->setEnabled(itype == "makebox"
|| (outer == "Boxed" && itype == "none"));
widthCB->setChecked(itype != "none" && !widthCB->isEnabled());
// except for frameless and boxed, the width cannot be specified if
// there is no inner box
bool const width_enabled =
ibox || outer == "Frameless" || outer == "Boxed";
widthED->setEnabled(width_enabled);
widthUnitsLC->setEnabled(width_enabled);
// halign is only allowed for Boxed without inner box or for makebox
halignCO->setEnabled((!ibox && outer == "Boxed")
|| (itype == "makebox"));
// enable if width_enabled, except if checkbaox is active but unset
widthED->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
widthUnitsLC->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
if (!widthCB->isChecked() && widthCB->isEnabled()) {
widthED->setEnabled(false);
widthUnitsLC->setEnabled(false);
}
// halign is only allowed without inner box and if a width is used and if
// pagebreak is not used
halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
&& ((!ibox && outer == "Boxed") || itype == "makebox"));
// pagebreak is only allowed for Boxed without inner box
pagebreakCB->setEnabled(!ibox && outer == "Boxed");
setSpecial(ibox);
@ -164,16 +174,29 @@ void GuiBox::on_typeCO_activated(int index)
heightCB->setEnabled(ibox);
setSpecial(ibox);
}
// the width can only be selected for makebox or framebox
widthCB->setEnabled(itype == "makebox"
|| (type == "Boxed" && itype == "none"));
widthCB->setChecked(itype != "none" && !widthCB->isEnabled());
// except for frameless and boxed, the width cannot be specified if
// there is no inner box
bool const width_enabled =
itype != "none" || frameless || type == "Boxed";
widthED->setEnabled(width_enabled);
widthUnitsLC->setEnabled(width_enabled);
// halign is only allowed for Boxed without inner box or for makebox
halignCO->setEnabled((type == "Boxed" && itype == "none") || (itype == "makebox"));
// enable if width_enabled, except if checkbaox is active but unset
widthED->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
widthUnitsLC->setEnabled(width_enabled || (widthCB->isEnabled() && widthCB->isChecked()));
if (!widthCB->isChecked() && widthCB->isEnabled()) {
widthED->setEnabled(false);
widthUnitsLC->setEnabled(false);
}
// halign is only allowed without inner box and if a width is used and if
// pagebreak is not used
halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
&& ((itype == "none" && type == "Boxed") || itype == "makebox"));
// pagebreak is only allowed for Boxed without inner box
pagebreakCB->setEnabled(type == "Boxed" && itype == "none");
if (type != "Boxed")
pagebreakCB->setChecked(false);
changed();
}
@ -188,6 +211,17 @@ void GuiBox::initDialog()
}
void GuiBox::on_widthCB_stateChanged(int state)
{
if (widthCB->isEnabled()) {
widthED->setEnabled(widthCB->isChecked());
widthUnitsLC->setEnabled(widthCB->isChecked());
halignCO->setEnabled(widthCB->isChecked());
}
changed();
}
void GuiBox::on_heightCB_stateChanged(int state)
{
bool const enable = (innerBoxCO->currentText() != qt_("None"))
@ -202,6 +236,9 @@ void GuiBox::on_pagebreakCB_stateChanged()
{
bool pbreak = (pagebreakCB->checkState() == Qt::Checked);
innerBoxCO->setEnabled(!pbreak);
widthCB->setEnabled(!pbreak);
if (pbreak)
widthCB->setChecked(!pbreak);
widthED->setEnabled(!pbreak);
widthUnitsLC->setEnabled(!pbreak);
if (!pbreak) {
@ -256,25 +293,33 @@ void GuiBox::paramsToDialog(Inset const * inset)
ialignCO->setEnabled(ibox);
setSpecial(ibox);
// halign and pagebreak are only allowed for Boxed without inner box
halignCO->setEnabled((!ibox && type == "Boxed") || (params.use_makebox));
// halign is only allowed without inner box and if a width is used and if
// pagebreak is not used
halignCO->setEnabled(!pagebreakCB->isChecked() && widthCB->isChecked()
&& ((!ibox && type == "Boxed") || params.use_makebox));
// pagebreak is only allowed for Boxed without inner box
pagebreakCB->setEnabled(!ibox && type == "Boxed");
// except for frameless and boxed, the width cannot be specified if
// there is no inner box
bool const width_enabled = (ibox || frameless || type == "Boxed");
widthED->setEnabled(width_enabled);
widthUnitsLC->setEnabled(width_enabled);
Length::UNIT const default_unit = Length::defaultUnit();
lengthToWidgets(widthED, widthUnitsLC,
(params.width).asString(), default_unit);
// the width can only be selected for makebox or framebox
widthCB->setEnabled(inner_type == "makebox"
|| (type == "Boxed" && !ibox && !pagebreakCB->isChecked()));
// "-999col%" is the code for no width
if ((params.width).asString() == "-999col%")
widthCB->setCheckState(Qt::Unchecked);
else {
if (widthCB->isEnabled())
widthCB->setChecked(true);
lengthToWidgets(widthED, widthUnitsLC,
(params.width).asString(), default_unit);
QString const special = toqstr(params.special);
if (!special.isEmpty() && special != "none")
widthUnitsLC->setCurrentItem(special);
}
QString const special = toqstr(params.special);
if (!special.isEmpty() && special != "none")
widthUnitsLC->setCurrentItem(special);
widthED->setEnabled(widthCB->isChecked());
widthUnitsLC->setEnabled(widthCB->isChecked());
lengthToWidgets(heightED, heightUnitsLC,
(params.height).asString(), default_unit);
@ -321,13 +366,22 @@ docstring GuiBox::dialogToParams() const
QString unit =
widthUnitsLC->itemData(widthUnitsLC->currentIndex()).toString();
QString value = widthED->text();
if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
params.special = fromqstr(unit);
// Note: the unit is simply ignored in this case
params.width = Length(value.toDouble(), Length::IN);
if (widthCB->isChecked()) {
if (ids_spec_.contains(unit) && !isValidLength(fromqstr(value))) {
params.special = fromqstr(unit);
// Note: the unit is simply ignored in this case
params.width = Length(value.toDouble(), Length::IN);
} else {
params.special = "none";
params.width = Length(widgetsToLength(widthED, widthUnitsLC));
}
} else {
params.special = "none";
params.width = Length(widgetsToLength(widthED, widthUnitsLC));
if (widthCB->isEnabled()) {
// use the code "-999col%" for the case that no width was selected
params.special = "none";
params.width = Length("-999col%");
}
}
// the height parameter is omitted if the value

View File

@ -31,6 +31,7 @@ private Q_SLOTS:
void on_innerBoxCO_activated(int);
void on_typeCO_activated(int);
void initDialog();
void on_widthCB_stateChanged(int state);
void on_heightCB_stateChanged(int state);
void on_pagebreakCB_stateChanged();

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BoxUi</class>
<widget class="QWidget" name="BoxUi">
@ -234,15 +235,18 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="widthLA">
<widget class="QCheckBox" name="widthCB">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>&amp;Width:</string>
</property>
<property name="buddy">
<cstring>widthED</cstring>
<property name="checked">
<bool>false</bool>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>

View File

@ -162,7 +162,7 @@ void InsetBox::setButtonLabel()
bool InsetBox::hasFixedWidth() const
{
return params_.inner_box || params_.special != "width";
return from_ascii(params_.width.asLatexString()) != "-9.99\\columnwidth";
}
@ -316,20 +316,24 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
os << "\\begin{framed}%\n";
break;
case Boxed:
os << "\\framebox";
if (!params_.inner_box) {
// 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 << "]";
}
// "-999col%" is the code for no width
if (from_ascii(width_string) != "-9.99\\columnwidth") {
os << "\\framebox";
if (!params_.inner_box) {
// 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 << "]";
}
} else
os << "\\fbox";
os << "{";
break;
case ovalbox:
@ -354,18 +358,22 @@ void InsetBox::latex(otexstream & os, OutputParams const & runparams) const
if (params_.use_parbox)
os << "\\parbox";
else if (params_.use_makebox) {
os << "\\makebox";
// FIXME UNICODE
// output the width and horizontal position
if (params_.special != "none") {
os << "[" << params_.width.value()
<< '\\' << from_utf8(params_.special)
<< ']';
// "-999col%" is the code for no width
if (from_ascii(width_string) != "-9.99\\columnwidth") {
os << "\\makebox";
// FIXME UNICODE
// output the width and horizontal position
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 << "]";
} else
os << '[' << from_ascii(width_string)
<< ']';
if (params_.hor_pos != 'c')
os << "[" << params_.hor_pos << "]";
os << "\\mbox";
os << "{";
}
else

View File

@ -1009,7 +1009,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
begin_inset(os, "Box ");
if (outer_type == "framed")
os << "Framed\n";
else if (outer_type == "framebox")
else if (outer_type == "framebox" || outer_type == "fbox")
os << "Boxed\n";
else if (outer_type == "shadowbox")
os << "Shadowbox\n";
@ -1020,18 +1020,27 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
preamble.registerAutomaticallyLoadedPackage("color");
} else if (outer_type == "doublebox")
os << "Doublebox\n";
else if (outer_type.empty())
else if (outer_type.empty() || outer_type == "mbox")
os << "Frameless\n";
else
os << outer_type << '\n';
os << "position \"" << position << "\"\n";
os << "hor_pos \"" << hor_pos << "\"\n";
os << "has_inner_box " << !inner_type.empty() << "\n";
if (outer_type == "mbox")
os << "has_inner_box 1\n";
else
os << "has_inner_box " << !inner_type.empty() << "\n";
os << "inner_pos \"" << inner_pos << "\"\n";
os << "use_parbox " << (inner_type == "parbox" || shadedparbox)
<< '\n';
os << "use_makebox " << (inner_type == "makebox") << '\n';
os << "width \"" << width_value << width_unit << "\"\n";
if (outer_type == "mbox")
os << "use_makebox 1\n";
else
os << "use_makebox " << (inner_type == "makebox") << '\n';
if (outer_type == "fbox" || outer_type == "mbox")
os << "width \"-999col%\"\n";
else
os << "width \"" << width_value << width_unit << "\"\n";
os << "special \"" << width_special << "\"\n";
os << "height \"" << height_value << height_unit << "\"\n";
os << "height_special \"" << height_special << "\"\n";
@ -1131,7 +1140,8 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer,
p.skip_spaces(true);
}
}
if (outer_type == "shaded") {
if (outer_type == "shaded" || outer_type == "fbox"
|| outer_type == "mbox") {
// These boxes never have an inner box
;
} else if (p.next_token().asInput() == "\\parbox") {
@ -4127,7 +4137,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
"", "", t.cs());
}
else if (t.cs() == "ovalbox" || t.cs() == "Ovalbox" ||
else if (t.cs() == "fbox" || t.cs() == "mbox" ||
t.cs() == "ovalbox" || t.cs() == "Ovalbox" ||
t.cs() == "shadowbox" || t.cs() == "doublebox")
parse_outer_box(p, os, FLAG_ITEM, outer, context, t.cs(), "");
@ -4142,18 +4153,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
parse_text(p, os, FLAG_ITEM, outer, context);
output_ert_inset(os, "}", context);
} else {
//the syntax is: \framebox[width][position]{content}
string special = p.getFullOpt();
special += p.getOpt();
// LyX does not yet support \framebox without any option
if (!special.empty())
parse_outer_box(p, os, FLAG_ITEM, outer,
context, t.cs(), special);
else {
eat_whitespace(p, os, context, false);
output_ert_inset(os, "\\framebox{", context);
parse_text(p, os, FLAG_ITEM, outer, context);
output_ert_inset(os, "}", context);
}
parse_outer_box(p, os, FLAG_ITEM, outer,
context, t.cs(), special);
}
}

View File

@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
#define LYX_FORMAT_LYX 467 // uwestoehr: iwona font support
#define LYX_FORMAT_TEX2LYX 467 // uwestoehr: iwona font support
#define LYX_FORMAT_LYX 468 // uwestoehr: mbox/fbox support
#define LYX_FORMAT_TEX2LYX 468 // uwestoehr: mbox/fbox support
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER