diff --git a/development/FORMAT b/development/FORMAT index 99ac907483..2de19fae70 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes ----------------------- +2008-01-11 Jürgen Spitzmüller + * Format incremented to 312: support for sidewaysalgorithm (rotfloat) + and wide sideways{figure,table}. + 2008-01-10 Richard Heck * Format incremented to 311: dummy format to drive the AMS conversion diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx index c354476f3a..49d51629e9 100644 --- a/lib/chkconfig.ltx +++ b/lib/chkconfig.ltx @@ -247,6 +247,7 @@ \TestPackage{prettyref} \TestPackage{preview} \TestPackage{rotating} +\TestPackage{rotfloat} \TestPackage{setspace} \TestPackage{soul} \TestPackage{subfigure} diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index c4912ab9dd..4c9bf8995a 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), ("1_4", range(222,246), minor_versions("1.4" , 5)), ("1_5", range(246,277), minor_versions("1.5" , 2)), - ("1_6", range(277,312), minor_versions("1.6" , 0))] # Richard Heck: AMS conversion + ("1_6", range(277,313), minor_versions("1.6" , 0))] # JSpitzm: rotfloat support def formats_list(): diff --git a/lib/lyx2lyx/lyx_1_4.py b/lib/lyx2lyx/lyx_1_4.py index dd5a63be5c..9952d14a8f 100644 --- a/lib/lyx2lyx/lyx_1_4.py +++ b/lib/lyx2lyx/lyx_1_4.py @@ -1826,20 +1826,35 @@ def convert_float(document): def revert_float(document): - " Revert sideway floats. " + " Revert sideways floats. " i = 0 while 1: i = find_token_exact(document.body, '\\begin_inset Float', i) if i == -1: return + floatline = document.body[i] j = find_end_of_inset(document.body, i) if j == -1: document.warning("Malformed lyx document: Missing '\\end_inset'.") i = i + 1 continue if get_value(document.body, 'sideways', i, j) != "false": - document.warning("Conversion of 'sideways true' not yet implemented.") - # Don't remove 'sideways' so that people will get warnings by lyx + l = find_token(document.body, "\\begin_layout Standard", i + 1, j) + if l == -1: + document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.") + return + floattype = "table" + if floatline == "\\begin_inset Float figure": + floattype = "figure" + document.body[j] = '\\layout Standard\n\\begin_inset ERT\nstatus Collapsed\n\n' \ + '\\layout Standard\n\n\n\\backslash\n' \ + 'end{sideways' + floattype + '}\n\n\\end_inset\n' + del document.body[i+1:l-1] + document.body[i] = '\\begin_inset ERT\nstatus Collapsed\n\n' \ + '\\layout Standard\n\n\n\\backslash\n' \ + 'begin{sideways' + floattype + '}\n\n\\end_inset\n\n' + add_to_preamble(document, + ['\\usepackage{rotfloat}\n']) i = i + 1 continue del_token(document.body, 'sideways', i, j) diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index b2287e55aa..3996b883bc 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -36,6 +36,15 @@ def wrap_into_ert(string, src, dst): return string.replace(src, '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n' + dst + '\n\\end_layout\n\\end_inset\n') +def add_to_preamble(document, text): + """ Add text to the preamble if it is not already there. + Only the first line is checked!""" + + if find_token(document.preamble, text[0], 0) != -1: + return + + document.preamble.extend(text) + #################################################################### def fix_wrong_tables(document): @@ -1092,6 +1101,77 @@ def revert_serbianlatin(document): j = j + 1 +def revert_rotfloat(document): + " Revert sidewaysalgorithm. " + i = 0 + while 1: + i = find_token(document.body, '\\begin_inset Float algorithm', i) + if i == -1: + return + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed lyx document: Missing '\\end_inset'.") + i = i + 1 + continue + if get_value(document.body, 'sideways', i, j) != "false": + l = find_token(document.body, "\\begin_layout Standard", i + 1, j) + if l == -1: + document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.") + return + document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \ + '\\begin_layout Standard\n\n\n\\backslash\n' \ + 'end{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n' + del document.body[i+1:l-1] + document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \ + '\\begin_layout Standard\n\n\n\\backslash\n' \ + 'begin{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n' + add_to_preamble(document, + ['% Commands inserted by lyx2lyx for sideways algorithm float', + '\\usepackage{rotfloat}\n' + '\\floatstyle{ruled}\n' + '\\newfloat{algorithm}{tbp}{loa}\n' + '\\floatname{algorithm}{Algorithm}\n']) + i = i + 1 + continue + i = i + 1 + + +def revert_widesideways(document): + " Revert wide sideways floats. " + i = 0 + while 1: + i = find_token(document.body, '\\begin_inset Float', i) + if i == -1: + return + floatline = document.body[i] + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Malformed lyx document: Missing '\\end_inset'.") + i = i + 1 + continue + if get_value(document.body, 'sideways', i, j) != "false": + if get_value(document.body, 'wide', i, j) != "false": + l = find_token(document.body, "\\begin_layout Standard", i + 1, j) + if l == -1: + document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.") + return + floattype = "table" + if floatline == "\\begin_inset Float figure": + floattype = "figure" + document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \ + '\\begin_layout Standard\n\n\n\\backslash\n' \ + 'end{sideways' + floattype + '*}\n\\end_layout\n\n\\end_inset\n' + del document.body[i+1:l-1] + document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \ + '\\begin_layout Standard\n\n\n\\backslash\n' \ + 'begin{sideways' + floattype + '*}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n' + add_to_preamble(document, + ['\\usepackage{rotfloat}\n']) + i = i + 1 + continue + i = i + 1 + + ## # Conversion hub # @@ -1131,10 +1211,12 @@ convert = [[277, [fix_wrong_tables]], [308, []], [309, []], [310, []], - [311, [convert_ams_classes]] + [311, [convert_ams_classes]], + [312, []], ] -revert = [[310, []], +revert = [[311, [revert_rotfloat, revert_widesideways]], + [310, []], [309, [revert_btprintall]], [308, [revert_nocite]], [307, [revert_serbianlatin]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 5d90106fad..d33fa3f31a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -118,7 +118,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 311; // Richard Heck: a dummy format to drive the AMS conversion +int const LYX_FORMAT = 312; // JSpitzm: rotfloat support } // namespace anon diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index e60fd461d9..3abf35872c 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -510,6 +510,7 @@ char const * simplefeatures[] = { the `float' package. See the caption package documentation for explanation.*/ "float", + "rotfloat", "wrapfig", "booktabs", "dvipost", diff --git a/src/frontends/qt4/FloatPlacement.cpp b/src/frontends/qt4/FloatPlacement.cpp index f8025ef605..f689ab24e8 100644 --- a/src/frontends/qt4/FloatPlacement.cpp +++ b/src/frontends/qt4/FloatPlacement.cpp @@ -112,6 +112,9 @@ void FloatPlacement::set(lyx::InsetFloatParams const & params) { set(params.placement); + standardfloat_ = (params.type == "figure" + || params.type == "table"); + if (params.wide) { herepossiblyCB->setChecked(false); heredefinitelyCB->setChecked(false); @@ -120,8 +123,8 @@ void FloatPlacement::set(lyx::InsetFloatParams const & params) spanCB->setChecked(params.wide); sidewaysCB->setChecked(params.sideways); - sidewaysCB->setEnabled(params.type == "figure" - || params.type == "table"); + // the package rotfloat only has *-versions for figure and table + spanCB->setEnabled(!params.sideways || standardfloat_); checkAllowed(); } @@ -225,7 +228,7 @@ void FloatPlacement::checkAllowed() ignoreCB->setEnabled(!sideways && !defaults && ignore); herepossiblyCB->setEnabled(!sideways && !defaults && !span); heredefinitelyCB->setEnabled(!sideways && !defaults && !span); - spanCB->setEnabled(!sideways); + spanCB->setEnabled(!sideways || standardfloat_); } else { topCB->setEnabled(!defaults); bottomCB->setEnabled(!defaults); diff --git a/src/frontends/qt4/FloatPlacement.h b/src/frontends/qt4/FloatPlacement.h index 581d5d711a..557f48ab52 100644 --- a/src/frontends/qt4/FloatPlacement.h +++ b/src/frontends/qt4/FloatPlacement.h @@ -46,6 +46,10 @@ public Q_SLOTS: Q_SIGNALS: void changed(); +private: + /// one of figure or table? + bool standardfloat_; + }; diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 0d80dcbf5b..08625e2884 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -261,7 +261,7 @@ void InsetFloat::validate(LaTeXFeatures & features) const } if (params_.sideways) - features.require("rotating"); + features.require("rotfloat"); features.useFloat(params_.type); InsetCollapsable::validate(features); @@ -284,13 +284,13 @@ int InsetFloat::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { FloatList const & floats = buf.params().getTextClass().floats(); - string tmptype = (params_.wide ? params_.type + "*" : params_.type); - if (params_.sideways) { - if (params_.type == "table") - tmptype = "sidewaystable"; - else if (params_.type == "figure") - tmptype = "sidewaysfigure"; - } + string tmptype = params_.type; + if (params_.sideways) + tmptype = "sideways" + params_.type; + if (params_.wide && (!params_.sideways || + params_.type == "figure" || + params_.type == "table")) + tmptype += "*"; // Figure out the float placement to use. // From lowest to highest: // - float default placement