]> git.lyx.org Git - features.git/commitdiff
backporting tex2lyx: the support for subfloats
authorUwe Stöhr <uwestoehr@web.de>
Sat, 29 Oct 2011 20:26:50 +0000 (20:26 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Sat, 29 Oct 2011 20:26:50 +0000 (20:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@40070 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/TODO.txt
src/tex2lyx/preamble.cpp
src/tex2lyx/text.cpp
status.20x

index 7e081ba3d86ea47285eb96b8a5617078aa183d65..a3d5547bb612df723d533ee194e13d73e99c131d 100644 (file)
@@ -30,7 +30,6 @@ Format LaTeX feature                        LyX feature
 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
index 4ce162df494a821274ceea4fedad063b19091a06..f757bb75444ce0aa336656f35acaefc2e979b754 100644 (file)
@@ -648,6 +648,9 @@ void handle_package(Parser &p, string const & name, string const & opts,
        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 @@ void parse_preamble(Parser & p, ostream & os,
                        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 << '}'
index 4edc2912f13e14b6557373485aedb025ec7ad934..dcbb64a223e743bcd7ab72c093c58692bab29af0 100644 (file)
@@ -226,6 +226,9 @@ char const * const known_phrases[] = {"LyX", "TeX", "LaTeXe", "LaTeX", 0};
 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 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                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 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                // 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 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        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 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        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)
index 8c2cf19f8386c8bc8dca628526c584acc8ea1074..21f65fa590ea956a21bebb7ceffbc0b5e9be3395 100644 (file)
@@ -63,6 +63,8 @@ What's new
 
   * Wrapped floats (wrapfigure, wraptable) (bug 4378).
 
+  * Subfloats (\subfloat).
+
   * Command \date{} in the preamble to suppress the date output.