]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
tex2lyx: support for wrapped floats and all their possible options
[lyx.git] / src / tex2lyx / text.cpp
index ce588869816d139bea186dd1b2399b4c7a381043..a2bd665c8f6c6ae4a52f58b4cbf0e168fe093da0 100644 (file)
@@ -1075,6 +1075,57 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                p.skip_spaces();
        }
 
+       else if (unstarred_name == "sidewaysfigure"
+               || unstarred_name == "sidewaystable") {
+               eat_whitespace(p, os, parent_context, false);
+               parent_context.check_layout(os);
+               if (unstarred_name == "sidewaysfigure")
+                       begin_inset(os, "Float figure\n");
+               else
+                       begin_inset(os, "Float table\n");
+               os << "wide " << convert<string>(is_starred)
+                  << "\nsideways true"
+                  << "\nstatus open\n\n";
+               parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+               end_inset(os);
+               // We don't need really a new paragraph, but
+               // we must make sure that the next item gets a \begin_layout.
+               parent_context.new_paragraph(os);
+               p.skip_spaces();
+       }
+
+       else if (name == "wrapfigure" || name == "wraptable") {
+               // syntax is \begin{wrapfigure}[lines]{placement}[overhang]{width}
+               eat_whitespace(p, os, parent_context, false);
+               parent_context.check_layout(os);
+               // default values
+               string lines = "0";
+               string overhang = "0col%";
+               // parse
+               if (p.hasOpt())
+                       lines = p.getArg('[', ']');
+               string const placement = p.getArg('{', '}');
+               if (p.hasOpt())
+                       overhang = p.getArg('[', ']');
+               string const width = p.getArg('{', '}');
+               // write
+               if (name == "wrapfigure")
+                       begin_inset(os, "Wrap figure\n");
+               else
+                       begin_inset(os, "Wrap table\n");
+               os << "lines " << lines
+                  << "\nplacement " << placement
+                  << "\noverhang " << lyx::translate_len(overhang)
+                  << "\nwidth " << lyx::translate_len(width)
+                  << "\nstatus open\n\n";
+               parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+               end_inset(os);
+               // We don't need really a new paragraph, but
+               // we must make sure that the next item gets a \begin_layout.
+               parent_context.new_paragraph(os);
+               p.skip_spaces();
+       }
+
        else if (name == "minipage") {
                eat_whitespace(p, os, parent_context, false);
                parse_box(p, os, 0, FLAG_END, outer, parent_context, "", "", name);
@@ -2452,13 +2503,37 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        if (t.cs() == "phantom")
                                begin_inset(os, "Phantom Phantom\n");
                        if (t.cs() == "hphantom")
-                               begin_inset(os, "Phantom Hhantom\n");
+                               begin_inset(os, "Phantom HPhantom\n");
                        if (t.cs() == "vphantom")
-                               begin_inset(os, "Phantom Vhantom\n");
+                               begin_inset(os, "Phantom VPhantom\n");
                        os << "status open\n";
                        parse_text_in_inset(p, os, FLAG_ITEM, outer, context);
                        end_inset(os);
                }
+
+               else if (t.cs() == "href") {
+                       context.check_layout(os);
+                       string target = p.getArg('{', '}');
+                       string name = p.getArg('{', '}');
+                       string type;
+                       size_t i = target.find(':');
+                       if (i != string::npos) {
+                               type = target.substr(0, i + 1);
+                               if (type == "mailto:" || type == "file:")
+                                       target = target.substr(i + 1);
+                               // handle the case that name is equal to target, except of "http://"
+                               else if (target.substr(i + 3) == name && type == "http:")
+                                       target = name;
+                       }
+                       begin_command_inset(os, "href", "href");
+                       if (name != target)
+                               os << "name \"" << name << "\"\n";
+                       os << "target \"" << target << "\"\n";
+                       if (type == "mailto:" || type == "file:")
+                               os << "type \"" << type << "\"\n";
+                       end_inset(os);
+                       skip_spaces_braces(p);
+               }
                
                else if (t.cs() == "lyxline") {
                        // swallow size argument (it is not used anyway)
@@ -2488,14 +2563,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "rule") {
-                       string offset = "";
-                       string width;
-                       string thickness;
-                       if (p.hasOpt())
-                               offset = p.getArg('[', ']');
-                       width = p.getArg('{', '}');
-                       thickness = p.getArg('{', '}');
-                                       
+                       string const offset = (p.hasOpt() ? p.getArg('[', ']') : string());
+                       string const width = p.getArg('{', '}');
+                       string const thickness = p.getArg('{', '}');
                        context.check_layout(os);
                        begin_command_inset(os, "line", "rule");
                        if (!offset.empty())
@@ -2702,8 +2772,27 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "printnomenclature") {
+                       string width = "";
+                       string width_type = "";
                        context.check_layout(os);
                        begin_command_inset(os, "nomencl_print", "printnomenclature");
+                       // case of a custom width
+                       if (p.hasOpt()) {
+                               width = p.getArg('[', ']');
+                               width = translate_len(width);
+                               width_type = "custom";
+                       }
+                       // case of no custom width
+                       // the case of no custom width but the width set
+                       // via \settowidth{\nomlabelwidth}{***} cannot be supported
+                       // because the user could have set anything, not only the width
+                       // of the longest label (which would be width_type = "auto")
+                       string label = convert_command_inset_arg(p.getArg('{', '}'));
+                       if (label.empty() && width_type.empty())
+                               width_type = "none";
+                       os << "set_width \"" << width_type << "\"\n";
+                       if (width_type == "custom")
+                               os << "width \"" << width << '\"';
                        end_inset(os);
                        skip_spaces_braces(p);
                }