Author: uwestoehr
Date: Sat Oct 29 22:26:50 2011
New Revision: 40070
URL: http://www.lyx.org/trac/changeset/40070
Log:
backporting tex2lyx: the support for subfloats
Modified:
lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/TODO.txt
lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/preamble.cpp
lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp
lyx-devel/branches/BRANCH_2_0_X/status.20x
Modified: lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/TODO.txt
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/TODO.txt Sat Oct 29
22:14:48 2011 (r40069)
+++ lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/TODO.txt Sat Oct 29
22:26:50 2011 (r40070)
@@ -30,7 +30,6 @@
293 ? InsetInfo
309 \nocite InsetCitation
310 \nocite{*} InsetBibtex
-316 subfig.sty (subfloats) InsetFloat
322 ? local layout
325 japanese one japanese language
326 PDFLaTeX for external insets InsetExternal
Modified: lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/preamble.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/preamble.cpp Sat Oct 29
22:14:48 2011 (r40069)
+++ lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/preamble.cpp Sat Oct 29
22:26:50 2011 (r40070)
@@ -648,6 +648,9 @@
else if (name == "wrapfig")
; // ignore this
+ else if (name == "subfig")
+ ; // ignore this
+
else if (is_known(name, known_languages))
h_language = name;
@@ -1266,9 +1269,16 @@
string const arg2 = p.verbatim_item();
string const arg3 = p.verbatim_item();
// test case \@ifundefined{date}{}{\date{}}
- if (arg1 == "date" && arg2.empty() && arg3 ==
"\\date{}")
+ if (arg1 == "date" && arg2.empty() && arg3 ==
"\\date{}") {
h_suppress_date = "true";
- else if (!in_lyx_preamble) {
+ // test for case
+ //\@ifundefined{showcaptionsetup}{}{%
+ // \PassOptionsToPackage{caption=false}{subfig}}
+ // that LyX uses for subfloats
+ } else if (arg1 == "showcaptionsetup" && arg2.empty()
+ && arg3 == "%\n
\\PassOptionsToPackage{caption=false}{subfig}") {
+ ; // do nothing
+ } else if (!in_lyx_preamble) {
h_preamble << t.asInput()
<< '{' << arg1 << '}'
<< '{' << arg2 << '}'
Modified: lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp Sat Oct 29
22:14:48 2011 (r40069)
+++ lyx-devel/branches/BRANCH_2_0_X/src/tex2lyx/text.cpp Sat Oct 29
22:26:50 2011 (r40070)
@@ -226,6 +226,9 @@
char const * const known_coded_phrases[] = {"LyX", "TeX", "LaTeX2e", "LaTeX",
0};
int const known_phrase_lengths[] = {3, 5, 7, 0};
+// string to store the float type to be able to determine the type of subfloats
+string float_type = "";
+
/// splits "x=z, y=b" into a map and an ordered keyword vector
void split_map(string const & s, map<string, string> & res, vector<string> &
keys)
@@ -1057,6 +1060,14 @@
eat_whitespace(p, os, parent_context, false);
parent_context.check_layout(os);
begin_inset(os, "Float " + unstarred_name + "\n");
+ // store the float type for subfloats
+ // subfloats only work with figures and tables
+ if (unstarred_name == "figure")
+ float_type = unstarred_name;
+ else if (unstarred_name == "table")
+ float_type = unstarred_name;
+ else
+ float_type = "";
if (p.hasOpt())
os << "placement " << p.getArg('[', ']') << '\n';
os << "wide " << convert<string>(is_starred)
@@ -1068,6 +1079,8 @@
// we must make sure that the next item gets a \begin_layout.
parent_context.new_paragraph(os);
p.skip_spaces();
+ // the float is parsed thus delete the type
+ float_type = "";
}
else if (unstarred_name == "sidewaysfigure"
@@ -2128,7 +2141,7 @@
p.skip_spaces();
context.check_layout(os);
p.skip_spaces();
- begin_inset(os, "Caption\n\n");
+ begin_inset(os, "Caption\n");
Context newcontext(true, context.textclass);
newcontext.font = context.font;
newcontext.check_layout(os);
@@ -2151,6 +2164,68 @@
newcontext.check_end_layout(os);
}
+ else if (t.cs() == "subfloat") {
+ // the syntax is \subfloat[caption]{content}
+ // if it is a table of figure depends on the
surrounding float
+ bool has_caption = false;
+ p.skip_spaces();
+ // do nothing if there is no outer float
+ if (!float_type.empty()) {
+ context.check_layout(os);
+ p.skip_spaces();
+ begin_inset(os, "Float " + float_type + "\n");
+ os << "wide false"
+ << "\nsideways false"
+ << "\nstatus collapsed\n\n";
+ // test for caption
+ string caption;
+ if (p.next_token().cat() != catEscape &&
+ p.next_token().character() ==
'[') {
+ p.get_token(); // eat
'['
+ caption =
parse_text_snippet(p, FLAG_BRACK_LAST, outer, context);
+ has_caption = true;
+ }
+ // the content
+ parse_text_in_inset(p, os, FLAG_ITEM, outer,
context);
+ // the caption comes always as the last
+ if (has_caption) {
+ // we must make sure that the caption
gets a \begin_layout
+ os << "\n\\begin_layout Plain Layout";
+ p.skip_spaces();
+ begin_inset(os, "Caption\n");
+ Context newcontext(true,
context.textclass);
+ newcontext.font = context.font;
+ newcontext.check_layout(os);
+ os << caption << "\n";
+ newcontext.check_end_layout(os);
+ // We don't need really a new
paragraph, but
+ // we must make sure that the next item
gets a \begin_layout.
+ //newcontext.new_paragraph(os);
+ end_inset(os);
+ p.skip_spaces();
+ }
+ // We don't need really a new paragraph, but
+ // we must make sure that the next item gets a
\begin_layout.
+ if (has_caption)
+ context.new_paragraph(os);
+ end_inset(os);
+ p.skip_spaces();
+ context.check_end_layout(os);
+ // close the layout we opened
+ if (has_caption)
+ os << "\n\\end_layout\n";
+ } else {
+ // if the float type is not supported or there
is no surrounding float
+ // output it as ERT
+ if (p.hasOpt()) {
+ string opt_arg =
convert_command_inset_arg(p.getArg('[', ']'));
+ handle_ert(os, t.asInput() + '[' +
opt_arg +
+ "]{" + p.verbatim_item() + '}',
context);
+ } else
+ handle_ert(os, t.asInput() + "{" +
p.verbatim_item() + '}', context);
+ }
+ }
+
else if (t.cs() == "includegraphics") {
bool const clip = p.next_token().asInput() == "*";
if (clip)
Modified: lyx-devel/branches/BRANCH_2_0_X/status.20x
==============================================================================
--- lyx-devel/branches/BRANCH_2_0_X/status.20x Sat Oct 29 22:14:48 2011
(r40069)
+++ lyx-devel/branches/BRANCH_2_0_X/status.20x Sat Oct 29 22:26:50 2011
(r40070)
@@ -63,6 +63,8 @@
* Wrapped floats (wrapfigure, wraptable) (bug 4378).
+ * Subfloats (\subfloat).
+
* Command \date{} in the preamble to suppress the date output.