Am Sonntag, 7. November 2004 11:49 schrieb Lars Gullik Bjønnes: > Juergen Spitzmueller <[EMAIL PROTECTED]> writes: > | Yes, I can understand this. After all, we're in feature freeze for quite a > | while now (2004-06-01). But 1.4 seems still far away, even though there's new > | hope now that Alfredo and Andre seem to find more time again (I check > | bugzilla regularly if I have some spare time, but the scope of bugs that I'm > | able to fix is limited).
The same holds for me. > | Wrt booktabs, I just fear that I'll see native support (which I need for my > | daily work) not before 2007. The changes are not severe and if there might be > | some bugs, I am willing to fix these. Me too. > I'd like the booktabs patch developed and stabilized outside the main > branch in CVS. Either completely outside CVS or in a separate branch. Ok. I think it should be done in CVS. Jürgen, should I create a branch (following Alfredos hints, I did it never before)? Here comes a port to 1.4 (that I did already yesterday in order to try it out). Changes from Edwins original version: - lyx2lyx support - Disable vertical rules for latex and plaintext output. They are not yet disabled in the frontends. I think that the rules should not be deleted if one checks the booktabs checkbox, but simply disabled. They should just reappear if the checkbox is unchecked, because one can quickly check the effect of using booktabs without destroying a (maybe complicated) rule setting - Rename and reposition the checkbox What still needs to be done IMHO: - Disable changing of rules in the frontend if booktabs are enabled - add GUI for \addlinespace - maybe add \morecmidrules somewhere (don't know if this is necessary) - mention booktabs in LyxConfig.in and LaTeXConfig.in - documentation - testing of course BTW, the tabe "Table Settings" of QTabularDialogBase.ui is a bit confusing IMHO even without booktabs, because it is not clear what belongs to a cell and what to the whole table. Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/lyx2lyx/lyx_1_4.py lyx-1.4-cvs/lib/lyx2lyx/lyx_1_4.py --- lyx-1.4-clean/lib/lyx2lyx/lyx_1_4.py 2004-10-27 21:03:47.000000000 +0200 +++ lyx-1.4-cvs/lib/lyx2lyx/lyx_1_4.py 2004-11-06 13:55:49.000000000 +0100 @@ -1356,6 +1484,24 @@ def revert_paperpackage(file): file.header[i] = replace(file.header[i], paperpackage, packages[paperpackage]) +def revert_booktabs(file): +# we just remove the booktabs flag, everything else will become a mess. + i = 0 + while 1: + i = find_token(file.body, "\\begin_inset Tabular", i) + if i == -1: + return + j = find_end_of_inset(file.body, i + 1) + if j == -1: + file.warning("Malformed LyX file: Could not find end of tabular.") + continue + for k in range(i, j): + if re.search('^<features.* booktabs="true".*>$', file.body[k]): + file.warning("Converting 'booktabs' table to normal table.") + file.body[k] = replace(file.body[k], ' booktabs="true"', '') + i = i + 1 + + ## # Bullets # @@ -1526,7 +1693,8 @@ def convert(file): 235 : [convert_paperpackage], 236 : [convert_bullets, add_begin_header, add_begin_body, normalize_papersize, strip_end_space], - 237 : [use_x_boolean]} + 237 : [use_x_boolean], + 238 : ''} chain = table.keys() chain.sort() @@ -1542,7 +1710,8 @@ def convert(file): def revert(file): - table = { 236: [use_x_binary], + table = { 237: [revert_booktabs], + 236: [use_x_binary], 235: [denormalize_papersize, remove_begin_body,remove_begin_header, revert_bullets], 234: [revert_paperpackage], diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/lyx2lyx/LyX.py lyx-1.4-cvs/lib/lyx2lyx/LyX.py --- lyx-1.4-clean/lib/lyx2lyx/LyX.py 2004-10-28 20:04:49.000000000 +0200 +++ lyx-1.4-cvs/lib/lyx2lyx/LyX.py 2004-10-28 18:44:04.000000000 +0200 @@ -44,7 +44,7 @@ format_relation = [("0_10", [210], ["0. ("1_1_6fix3", [218], ["1.1.6fix3","1.1.6fix4","1.1"]), ("1_2", [220], ["1.2.0","1.2.1","1.2.3","1.2.4","1.2"]), ("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3.5","1.3"]), - ("1_4", range(223,238), ["1.4.0cvs","1.4"])] + ("1_4", range(223,239), ["1.4.0cvs","1.4"])] def formats_list(): diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/buffer.C lyx-1.4-cvs/src/buffer.C --- lyx-1.4-clean/src/buffer.C 2004-11-07 17:23:45.000000000 +0100 +++ lyx-1.4-cvs/src/buffer.C 2004-11-07 17:34:28.000000000 +0100 @@ -136,7 +139,7 @@ extern BufferList bufferlist; namespace { -const int LYX_FORMAT = 237; +const int LYX_FORMAT = 238; } // namespace anon diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/controllers/ControlTabular.C lyx-1.4-cvs/src/frontends/controllers/ControlTabular.C --- lyx-1.4-clean/src/frontends/controllers/ControlTabular.C 2004-05-21 08:55:40.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/controllers/ControlTabular.C 2004-11-06 12:12:18.000000000 +0100 @@ -213,6 +213,15 @@ void ControlTabular::valign(ControlTabul } +void ControlTabular::booktabs(bool yes) +{ + if (yes) + set(LyXTabular::SET_BOOKTABS); + else + set(LyXTabular::UNSET_BOOKTABS); +} + + void ControlTabular::longTabular(bool yes) { if (yes) diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/controllers/ControlTabular.h lyx-1.4-cvs/src/frontends/controllers/ControlTabular.h --- lyx-1.4-clean/src/frontends/controllers/ControlTabular.h 2004-05-21 08:55:40.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/controllers/ControlTabular.h 2004-11-06 12:12:53.000000000 +0100 @@ -67,6 +67,8 @@ public: void valign(VALIGN h); + void booktabs(bool yes); + void longTabular(bool yes); private: diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/qt2/QTabular.C lyx-1.4-cvs/src/frontends/qt2/QTabular.C --- lyx-1.4-clean/src/frontends/qt2/QTabular.C 2004-05-21 08:55:46.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/qt2/QTabular.C 2004-11-06 12:30:07.000000000 +0100 @@ -59,6 +59,7 @@ void QTabular::build_dialog() bcview().addReadOnly(dialog_->borderSetPB); bcview().addReadOnly(dialog_->borderUnsetPB); bcview().addReadOnly(dialog_->borders); + bcview().addReadOnly(dialog_->booktabsCB); bcview().addReadOnly(dialog_->longTabularCB); bcview().addReadOnly(dialog_->headerStatusCB); bcview().addReadOnly(dialog_->headerBorderAboveCB); @@ -146,6 +147,8 @@ void QTabular::update_contents() dialog_->longTabularCB->setChecked(tabular.isLongTabular()); + dialog_->booktabsCB->setChecked(tabular.useBookTabs()); + update_borders(); LyXLength pwidth; diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/qt2/QTabularDialog.C lyx-1.4-cvs/src/frontends/qt2/QTabularDialog.C --- lyx-1.4-clean/src/frontends/qt2/QTabularDialog.C 2004-06-04 18:10:20.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/qt2/QTabularDialog.C 2004-11-06 12:15:38.000000000 +0100 @@ -345,5 +345,14 @@ void QTabularDialog::ltLastFooterEmpty_c form_->changed(); } + +void QTabularDialog::booktabs_clicked() +{ + if (booktabsCB->isChecked()) + form_->controller().set(LyXTabular::SET_BOOKTABS); + else + form_->controller().set(LyXTabular::UNSET_BOOKTABS); +} + } // namespace frontend } // namespace lyx diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/qt2/QTabularDialog.h lyx-1.4-cvs/src/frontends/qt2/QTabularDialog.h --- lyx-1.4-clean/src/frontends/qt2/QTabularDialog.h 2004-05-21 08:55:47.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/qt2/QTabularDialog.h 2004-11-06 12:15:45.000000000 +0100 @@ -59,6 +59,7 @@ protected slots: virtual void ltLastFooterBorderAbove_clicked(); virtual void ltLastFooterBorderBelow_clicked(); virtual void ltLastFooterEmpty_clicked(); + virtual void booktabs_clicked(); protected: virtual void closeEvent(QCloseEvent * e); diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/qt2/ui/QTabularDialogBase.ui lyx-1.4-cvs/src/frontends/qt2/ui/QTabularDialogBase.ui --- lyx-1.4-clean/src/frontends/qt2/ui/QTabularDialogBase.ui 2003-09-03 18:02:57.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/qt2/ui/QTabularDialogBase.ui 2004-11-07 18:52:01.000000000 +0100 @@ -121,7 +121,26 @@ <string>Horizontal alignment in column</string> </property> </widget> - <widget row="3" column="0" rowspan="1" colspan="4" > + <widget row="3" column="0"> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>booktabsCB</cstring> + </property> + <property stdset="1"> + <name>enabled</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>text</name> + <string>&Formal table</string> + </property> + <property> + <name>toolTip</name> + <string>Print as formal table (different horizontal rules, no vertical rules)</string> + </property> + </widget> + <widget row="4" column="0" rowspan="1" colspan="4" > <class>QCheckBox</class> <property stdset="1"> <name>name</name> @@ -140,7 +159,7 @@ <string>Rotate the table by 90 degrees</string> </property> </widget> - <widget row="4" column="0" rowspan="1" colspan="4" > + <widget row="5" column="0" rowspan="1" colspan="4" > <class>QCheckBox</class> <property stdset="1"> <name>name</name> @@ -155,7 +174,7 @@ <string>Rotate this cell by 90 degrees</string> </property> </widget> - <widget row="5" column="0" rowspan="1" colspan="2" > + <widget row="6" column="0" rowspan="1" colspan="2" > <class>QLabel</class> <property stdset="1"> <name>name</name> @@ -170,7 +189,7 @@ <cstring>specialAlignmentED</cstring> </property> </widget> - <widget row="5" column="2" rowspan="1" colspan="2" > + <widget row="6" column="2" rowspan="1" colspan="2" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> @@ -181,7 +200,7 @@ <string>Custom column format (LaTeX)</string> </property> </widget> - <spacer row="6" column="2" > + <spacer row="7" column="2" > <property> <name>name</name> <cstring>Spacer5</cstring> @@ -1469,6 +1488,13 @@ <receiver>QTabularDialogBase</receiver> <slot>longTabular()</slot> </connection> + <connection> + <sender>booktabsCB</sender> + <signal>clicked()</signal> + <receiver>QTabularDialogBase</receiver> + <slot>booktabs_clicked()</slot> + </connection> + <slot access="protected">booktabs_clicked()</slot> <slot access="protected">borderSet_clicked()</slot> <slot access="protected">borderUnset_clicked()</slot> <slot access="protected">bottomBorder_changed()</slot> diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/xforms/forms/form_tabular.fd lyx-1.4-cvs/src/frontends/xforms/forms/form_tabular.fd --- lyx-1.4-clean/src/frontends/xforms/forms/form_tabular.fd 2003-11-21 12:38:17.000000000 +0100 +++ lyx-1.4-cvs/src/frontends/xforms/forms/form_tabular.fd 2004-11-07 18:53:40.000000000 +0100 @@ -125,7 +125,7 @@ argument: Name: form_tabular_options Width: 505 Height: 225 -Number of Objects: 10 +Number of Objects: 11 -------------------- class: FL_BOX @@ -292,7 +292,7 @@ argument: 0 -------------------- class: FL_LABELFRAME type: ENGRAVED_FRAME -box: 280 20 120 75 +box: 280 20 120 90 boxtype: FL_NO_BOX colors: FL_BLACK FL_COL1 alignment: FL_ALIGN_TOP_LEFT @@ -307,6 +307,24 @@ name: callback: argument: +-------------------- +class: FL_CHECKBUTTON +type: PUSH_BUTTON +box: 280 80 95 25 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Formal table|#F +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: check_booktabs +callback: C_FormDialogView_InputCB +argument: 0 + =============== FORM =============== Name: form_tabular_column Width: 505 diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/frontends/xforms/FormTabular.C lyx-1.4-cvs/src/frontends/xforms/FormTabular.C --- lyx-1.4-clean/src/frontends/xforms/FormTabular.C 2004-05-21 08:56:02.000000000 +0200 +++ lyx-1.4-cvs/src/frontends/xforms/FormTabular.C 2004-11-06 12:34:11.000000000 +0100 @@ -361,6 +361,9 @@ void FormTabular::update() setEnabled(column_options_->radio_valign_bottom, !pwidth.zero()); setEnabled(column_options_->radio_valign_middle, !pwidth.zero()); + fl_set_button(tabular_options_->check_booktabs, + tabular.useBookTabs()); + fl_set_button(tabular_options_->check_longtable, tabular.isLongTabular()); @@ -622,6 +625,11 @@ ButtonPolicy::SMInput FormTabular::input num = LyXTabular::SET_LONGTABULAR; else num = LyXTabular::UNSET_LONGTABULAR; + } else if (ob == tabular_options_->check_booktabs) { + if (fl_get_button(tabular_options_->check_booktabs)) + num = LyXTabular::SET_BOOKTABS; + else + num = LyXTabular::UNSET_BOOKTABS; } else if (ob == tabular_options_->check_rotate_tabular) { s = fl_get_button(tabular_options_->check_rotate_tabular); if (s) diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insettabular.C lyx-1.4-cvs/src/insets/insettabular.C --- lyx-1.4-clean/src/insets/insettabular.C 2004-11-06 10:51:28.000000000 +0100 +++ lyx-1.4-cvs/src/insets/insettabular.C 2004-11-06 12:27:22.000000000 +0100 @@ -118,6 +118,8 @@ TabularFeature tabularFeature[] = { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" }, { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" }, { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" }, + { LyXTabular::SET_BOOKTABS, "set-booktabs" }, + { LyXTabular::UNSET_BOOKTABS, "unset-booktabs" }, { LyXTabular::LAST_ACTION, "" } }; @@ -867,6 +876,14 @@ bool InsetTabular::getStatus(LCursor & c case LyXTabular::SET_LTNEWPAGE: status.setOnOff(tabular.getLTNewPage(sel_row_start)); break; + + case LyXTabular::SET_BOOKTABS: + status.setOnOff(tabular.useBookTabs()); + break; + + case LyXTabular::UNSET_BOOKTABS: + status.setOnOff(!tabular.useBookTabs()); + break; default: status.clear(); @@ -1444,6 +1461,14 @@ void InsetTabular::tabularFeatures(LCurs tabular.setLTNewPage(row, !tabular.getLTNewPage(row)); break; + case LyXTabular::SET_BOOKTABS: + tabular.setBookTabs(true); + break; + + case LyXTabular::UNSET_BOOKTABS: + tabular.setBookTabs(false); + break; + // dummy stuff just to avoid warnings case LyXTabular::LAST_ACTION: break; diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/tabular.C lyx-1.4-cvs/src/tabular.C --- lyx-1.4-clean/src/tabular.C 2004-11-06 10:51:00.000000000 +0100 +++ lyx-1.4-cvs/src/tabular.C 2004-11-07 19:20:54.000000000 +0100 @@ -369,6 +369,7 @@ void LyXTabular::init(BufferParams const column_info.back().right_line = true; is_long_tabular = false; rotate = false; + use_booktabs = false; } @@ -538,10 +539,10 @@ int LyXTabular::numberOfCellsInRow(int c } -// returns 1 if there is a topline, returns 0 if not bool LyXTabular::topLine(int cell, bool onlycolumn) const { - if (!onlycolumn && isMultiColumn(cell)) + if (!onlycolumn && isMultiColumn(cell) && + !(use_booktabs && row_of_cell(cell) == 0)) return cellinfo_of_cell(cell).top_line; return row_info[row_of_cell(cell)].top_line; } @@ -549,7 +550,8 @@ bool LyXTabular::topLine(int cell, bool bool LyXTabular::bottomLine(int cell, bool onlycolumn) const { - if (!onlycolumn && isMultiColumn(cell)) + if (!onlycolumn && isMultiColumn(cell) && + !(use_booktabs && isLastRow(cell))) return cellinfo_of_cell(cell).bottom_line; return row_info[row_of_cell(cell)].bottom_line; } @@ -557,6 +559,8 @@ bool LyXTabular::bottomLine(int cell, bo bool LyXTabular::leftLine(int cell, bool onlycolumn) const { + if (use_booktabs) + return false; if (!onlycolumn && isMultiColumn(cell) && (isFirstCellInRow(cell) || isMultiColumn(cell-1))) { @@ -572,6 +576,8 @@ bool LyXTabular::leftLine(int cell, bool bool LyXTabular::rightLine(int cell, bool onlycolumn) const { + if (use_booktabs) + return false; if (!onlycolumn && isMultiColumn(cell) && (isLastCellInRow(cell) || isMultiColumn(cell + 1))) { @@ -1078,6 +1084,7 @@ void LyXTabular::write(Buffer const & bu // global longtable options os << "<features" << write_attribute("rotate", rotate) + << write_attribute("booktabs", use_booktabs) << write_attribute("islongtable", is_long_tabular) << write_attribute("firstHeadTopDL", endfirsthead.topDL) << write_attribute("firstHeadBottomDL", endfirsthead.bottomDL) @@ -1244,6 +1251,7 @@ void LyXTabular::read(Buffer const & buf return; } getTokenValue(line, "rotate", rotate); + getTokenValue(line, "booktabs", use_booktabs); getTokenValue(line, "islongtable", is_long_tabular); // compatibility read for old longtable options. Now we can make any // row part of the header/footer type we want before it was strict @@ -1424,6 +1432,18 @@ int LyXTabular::unsetMultiColumn(int cel } +void LyXTabular::setBookTabs(bool what) +{ + use_booktabs = what; +} + + +bool LyXTabular::useBookTabs() const +{ + return use_booktabs; +} + + void LyXTabular::setLongTabular(bool what) { is_long_tabular = what; @@ -1719,12 +1739,14 @@ int LyXTabular::TeXTopHLine(ostream & os if (topLine(i)) ++tmp; } - if (tmp == n - fcell) { - os << "\\hline "; + if (use_booktabs && row == 0) { + os << "\\toprule "; + } else if (tmp == n - fcell) { + os << (use_booktabs ? "\\midrule " : "\\hline "); } else if (tmp) { for (int i = fcell; i < n; ++i) { if (topLine(i)) { - os << "\\cline{" + os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << column_of_cell(i) + 1 << '-' << right_column_of_cell(i) + 1 @@ -1752,12 +1774,14 @@ int LyXTabular::TeXBottomHLine(ostream & if (bottomLine(i)) ++tmp; } - if (tmp == n - fcell) { - os << "\\hline"; + if (use_booktabs && row == rows_ - 1) { + os << "\\bottomrule "; + } else if (tmp == n - fcell) { + os << (use_booktabs ? "\\midrule " : "\\hline "); } else if (tmp) { for (int i = fcell; i < n; ++i) { if (bottomLine(i)) { - os << "\\cline{" + os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << column_of_cell(i) + 1 << '-' << right_column_of_cell(i) + 1 @@ -2043,7 +2067,7 @@ int LyXTabular::latex(Buffer const & buf if (!column_info[i].align_special.empty()) { os << column_info[i].align_special; } else { - if (column_info[i].left_line) + if (!use_booktabs && column_info[i].left_line) os << '|'; if (!column_info[i].p_width.zero()) { switch (column_info[i].alignment) { @@ -2090,7 +2114,7 @@ int LyXTabular::latex(Buffer const & buf break; } } - if (column_info[i].right_line) + if (!use_booktabs && column_info[i].right_line) os << '|'; } } @@ -2564,6 +2588,8 @@ int LyXTabular::getCellFromInset(InsetBa void LyXTabular::validate(LaTeXFeatures & features) const { features.require("NeedTabularnewline"); + if (useBookTabs()) + features.require("booktabs"); if (isLongTabular()) features.require("longtable"); if (needRotating()) diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/tabular.h lyx-1.4-cvs/src/tabular.h --- lyx-1.4-clean/src/tabular.h 2004-10-11 14:06:38.000000000 +0200 +++ lyx-1.4-cvs/src/tabular.h 2004-11-06 12:10:43.000000000 +0100 @@ -124,6 +124,10 @@ public: /// SET_SPECIAL_MULTI, /// + SET_BOOKTABS, + /// + UNSET_BOOKTABS, + /// LAST_ACTION }; /// @@ -304,6 +308,10 @@ public: /// int right_column_of_cell(int cell) const; /// + void setBookTabs(bool); + /// + bool useBookTabs() const; + /// void setLongTabular(bool); /// bool isLongTabular() const; @@ -487,6 +495,8 @@ public: /// int width_of_tabular; /// + bool use_booktabs; + /// bool rotate; // // for long tabulars