]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
Let the Foot inset have a different Layout when inside a title
[lyx.git] / src / tex2lyx / text.cpp
index f9b850f7adaa1aaed8df731e20f310b35ea58a7d..2c212a425fffbc7afc57b8171e0a591c94baf0fa 100644 (file)
@@ -112,10 +112,10 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer,
 
 
 char const * const known_ref_commands[] = { "ref", "pageref", "vref",
- "vpageref", "prettyref", "eqref", 0 };
+ "vpageref", "prettyref", "nameref", "eqref", 0 };
 
 char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref",
- "vpageref", "formatted", "eqref", 0 };
+ "vpageref", "formatted", "nameref", "eqref", 0 };
 
 char const * const known_refstyle_commands[] = { "algref", "chapref", "corref",
  "eqref", "enuref", "figref", "fnref", "lemref", "parref", "partref", "propref",
@@ -935,7 +935,9 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                width_unit = "in";
                width_special = "width";
        } else if (latex_width.empty() && outer_type == "framebox") {
-               use_ert = true;
+               width_value.clear();
+               width_unit.clear();
+               width_special = "none";
        }
        if (use_ert) {
                ostringstream ss;
@@ -992,9 +994,6 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                        if (outer_flags & FLAG_END)
                                output_ert_inset(os, "\\end{" + outer_type + '}',
                                           parent_context);
-                       else if (inner_type.empty() && outer_type == "framebox")
-                               // in this case it is already closed later
-                               ;
                        else
                                output_ert_inset(os, "}", parent_context);
                }
@@ -1009,7 +1008,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                begin_inset(os, "Box ");
                if (outer_type == "framed")
                        os << "Framed\n";
-               else if (outer_type == "framebox")
+               else if (outer_type == "framebox" || outer_type == "fbox")
                        os << "Boxed\n";
                else if (outer_type == "shadowbox")
                        os << "Shadowbox\n";
@@ -1020,18 +1019,27 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                        preamble.registerAutomaticallyLoadedPackage("color");
                } else if (outer_type == "doublebox")
                        os << "Doublebox\n";
-               else if (outer_type.empty())
+               else if (outer_type.empty() || outer_type == "mbox")
                        os << "Frameless\n";
                else
                        os << outer_type << '\n';
                os << "position \"" << position << "\"\n";
                os << "hor_pos \"" << hor_pos << "\"\n";
-               os << "has_inner_box " << !inner_type.empty() << "\n";
+               if (outer_type == "mbox")
+                       os << "has_inner_box 1\n";
+               else
+                       os << "has_inner_box " << !inner_type.empty() << "\n";
                os << "inner_pos \"" << inner_pos << "\"\n";
                os << "use_parbox " << (inner_type == "parbox" || shadedparbox)
                   << '\n';
-               os << "use_makebox " << (inner_type == "makebox") << '\n';
-               os << "width \"" << width_value << width_unit << "\"\n";
+               if (outer_type == "mbox")
+                       os << "use_makebox 1\n";
+               else
+                       os << "use_makebox " << (inner_type == "makebox") << '\n';
+               if (outer_type == "fbox" || outer_type == "mbox")
+                       os << "width \"\"\n";
+               else
+                       os << "width \"" << width_value << width_unit << "\"\n";
                os << "special \"" << width_special << "\"\n";
                os << "height \"" << height_value << height_unit << "\"\n";
                os << "height_special \"" << height_special << "\"\n";
@@ -1131,7 +1139,8 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer,
                        p.skip_spaces(true);
                }
        }
-       if (outer_type == "shaded") {
+       if (outer_type == "shaded" || outer_type == "fbox"
+               || outer_type == "mbox") {
                // These boxes never have an inner box
                ;
        } else if (p.next_token().asInput() == "\\parbox") {
@@ -1516,6 +1525,37 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                        preamble.registerAutomaticallyLoadedPackage("color");
        }
 
+       else if (name == "btSect") {
+               eat_whitespace(p, os, parent_context, false);
+               parent_context.check_layout(os);
+               begin_command_inset(os, "bibtex", "bibtex");
+               string bibstyle = "plain";
+               if (p.hasOpt()) {
+                       bibstyle = p.getArg('[', ']');
+                       p.skip_spaces(true);
+               }
+               string const bibfile = p.getArg('{', '}');
+               eat_whitespace(p, os, parent_context, false);
+               Token t = p.get_token();
+               if (t.asInput() == "\\btPrintCited") {
+                       p.skip_spaces(true);
+                       os << "btprint " << '"' << "btPrintCited" << '"' << "\n";
+               }
+               if (t.asInput() == "\\btPrintNotCited") {
+                       p.skip_spaces(true);
+                       os << "btprint " << '"' << "btPrintNotCited" << '"' << "\n";
+               }
+               if (t.asInput() == "\\btPrintAll") {
+                       p.skip_spaces(true);
+                       os << "btprint " << '"' << "btPrintAll" << '"' << "\n";
+               }
+               os << "bibfiles " << '"' << bibfile << '"' << "\n";
+               os << "options " << '"' << bibstyle << '"' <<  "\n";
+               parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+               end_inset(os);
+               p.skip_spaces();
+       }
+
        else if (name == "framed" || name == "shaded") {
                eat_whitespace(p, os, parent_context, false);
                parse_outer_box(p, os, FLAG_END, outer, parent_context, name, "");
@@ -1590,24 +1630,13 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                if (last_env == name) {
                        // we need to output a separator since LyX would export
                        // the two environments as one otherwise (bug 5716)
-                       docstring const sep = from_ascii("--Separator--");
                        TeX2LyXDocClass const & textclass(parent_context.textclass);
-                       if (textclass.hasLayout(sep)) {
-                               Context newcontext(parent_context);
-                               newcontext.layout = &(textclass[sep]);
-                               newcontext.check_layout(os);
-                               newcontext.check_end_layout(os);
-                       } else {
-                               parent_context.check_layout(os);
-                               begin_inset(os, "Note Note\n");
-                               os << "status closed\n";
-                               Context newcontext(true, textclass,
-                                               &(textclass.defaultLayout()));
-                               newcontext.check_layout(os);
-                               newcontext.check_end_layout(os);
-                               end_inset(os);
-                               parent_context.check_end_layout(os);
-                       }
+                       Context newcontext(true, textclass,
+                                       &(textclass.defaultLayout()));
+                       newcontext.check_layout(os);
+                       begin_inset(os, "Separator plain\n");
+                       end_inset(os);
+                       newcontext.check_end_layout(os);
                }
                switch (context.layout->latextype) {
                case  LATEX_LIST_ENVIRONMENT:
@@ -1984,43 +2013,55 @@ void copy_file(FileName const & src, string dstname)
 }
 
 
-/// Parse a NoWeb Chunk section. The initial "<<" is already parsed.
-bool parse_noweb(Parser & p, ostream & os, Context & context)
+/// Parse a literate Chunk section. The initial "<<" is already parsed.
+bool parse_chunk(Parser & p, ostream & os, Context & context)
 {
        // check whether a chunk is possible here.
-       if (!context.new_layout_allowed ||
-           !context.textclass.hasLayout(from_ascii("Chunk"))) {
+       if (!context.textclass.hasInsetLayout(from_ascii("Flex:Chunk"))) {
                return false;
        }
 
        p.pushPosition();
 
        // read the parameters
-       Parser::Arg stuff = p.verbatimStuff(">>=", false);
-       if (!stuff.first) {
+       Parser::Arg const params = p.verbatimStuff(">>=\n", false);
+       if (!params.first) {
                p.popPosition();
                return false;
        }
-       string chunk = "<<" + stuff.second + ">>="
-               + p.verbatimStuff("\n").second + '\n';
 
-       stuff = p.verbatimStuff("\n@");
-       if (!stuff.first) {
+       Parser::Arg const code = p.verbatimStuff("\n@");
+       if (!code.first) {
                p.popPosition();
                return false;
        }
-       chunk += stuff.second + "\n@";
-       string post_chunk = p.verbatimStuff("\n").second + '\n';
+       string const post_chunk = p.verbatimStuff("\n").second + '\n';
        if (post_chunk[0] != ' ' && post_chunk[0] != '\n') {
                p.popPosition();
                return false;
        }
-       chunk += post_chunk;
+       // The last newline read is important for paragraph handling
+       p.putback();
+       p.deparse();
 
-       context.new_paragraph(os);
-       Context newcontext(true, context.textclass,
-               &context.textclass[from_ascii("Chunk")]);
-       output_ert(os, chunk, newcontext);
+       //cerr << "params=[" << params.second << "], code=[" << code.second << "]" <<endl;
+       // We must have a valid layout before outputting the Chunk inset.
+       context.check_layout(os);
+       Context chunkcontext(true, context.textclass);
+       chunkcontext.layout = &context.textclass.plainLayout();
+       begin_inset(os, "Flex Chunk");
+       os << "\nstatus open\n";
+       if (!params.second.empty()) {
+               chunkcontext.check_layout(os);
+               Context paramscontext(true, context.textclass);
+               paramscontext.layout = &context.textclass.plainLayout();
+               begin_inset(os, "Argument 1");
+               os << "\nstatus open\n";
+               output_ert(os, params.second, paramscontext);
+               end_inset(os);
+       }
+       output_ert(os, code.second, chunkcontext);
+       end_inset(os);
 
        p.dropPosition();
        return true;
@@ -2296,16 +2337,16 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.asInput() == "<"
                         && p.next_token().asInput() == "<") {
-                       bool has_noweb = false;
+                       bool has_chunk = false;
                        if (noweb_mode) {
                                p.pushPosition();
                                p.get_token();
-                               has_noweb = parse_noweb(p, os, context);
-                               if (!has_noweb)
+                               has_chunk = parse_chunk(p, os, context);
+                               if (!has_chunk)
                                        p.popPosition();
                        }
 
-                       if (!has_noweb) {
+                       if (!has_chunk) {
                                context.check_layout(os);
                                begin_inset(os, "Quotes ");
                                //FIXME: this is a right danish quote;
@@ -2430,6 +2471,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        if (!rem.empty())
                                                output_ert_inset(os,
                                                        to_utf8(rem), context);
+                                       for (set<string>::const_iterator it = req.begin();
+                                            it != req.end(); ++it)
+                                               preamble.registerAutomaticallyLoadedPackage(*it);
                                } else
                                        // we did not find a non-ert version
                                        output_ert_inset(os, name, context);
@@ -2584,11 +2628,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                        if (optarg) {
                                if (context.layout->labeltype != LABEL_MANUAL) {
-                                       // LyX does not support \item[\mybullet]
-                                       // in itemize environments
+                                       // handle option of itemize item
+                                       begin_inset(os, "Argument item:1\n");
+                                       os << "status open\n";
+                                       os << "\n\\begin_layout Plain Layout\n";
                                        Parser p2(s + ']');
                                        os << parse_text_snippet(p2,
                                                FLAG_BRACK_LAST, outer, context);
+                                       // we must not use context.check_end_layout(os)
+                                       // because that would close the outer itemize layout
+                                       os << "\n\\end_layout\n";
+                                       end_inset(os);
+                                       eat_whitespace(p, os, context, false);
                                } else if (!s.empty()) {
                                        // LyX adds braces around the argument,
                                        // so we need to remove them here.
@@ -2604,8 +2655,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        } else {
                                                Parser p2(s + ']');
                                                os << parse_text_snippet(p2,
-                                                       FLAG_BRACK_LAST,
-                                                       outer, context);
+                                                       FLAG_BRACK_LAST, outer, context);
                                        }
                                        // The space is needed to separate the
                                        // item from the rest of the sentence.
@@ -2779,10 +2829,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "caption") {
+                       bool starred = false;
+                       if (p.next_token().asInput() == "*") {
+                               p.get_token();
+                               starred = true;
+                       }
                        p.skip_spaces();
                        context.check_layout(os);
                        p.skip_spaces();
-                       begin_inset(os, "Caption Standard\n");
+                       if (starred)
+                               begin_inset(os, "Caption LongTableNoNumber\n");
+                       else
+                               begin_inset(os, "Caption Standard\n");
                        Context newcontext(true, context.textclass, 0, 0, context.font);
                        newcontext.check_layout(os);
                        // FIXME InsetArgument is now properly implemented in InsetLayout
@@ -3279,6 +3337,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                os << to_utf8(s);
                                if (!rem.empty())
                                        output_ert_inset(os, to_utf8(rem), context);
+                               for (set<string>::const_iterator it = req.begin();
+                                    it != req.end(); ++it)
+                                       preamble.registerAutomaticallyLoadedPackage(*it);
                        } else
                                // we did not find a non-ert version
                                output_ert_inset(os, command, context);
@@ -3806,16 +3867,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        skip_braces(p);
                }
 
-               else if (t.cs() == "-") {
-                       context.check_layout(os);
-                       os << "\\SpecialChar \\-\n";
-               }
-
                else if (t.cs() == "_" || t.cs() == "&" || t.cs() == "#"
                            || t.cs() == "$" || t.cs() == "{" || t.cs() == "}"
-                           || t.cs() == "%") {
+                           || t.cs() == "%" || t.cs() == "-") {
                        context.check_layout(os);
-                       os << t.cs();
+                       if (t.cs() == "-")
+                               os << "\\SpecialChar \\-\n";
+                       else
+                               os << t.cs();
                }
 
                else if (t.cs() == "char") {
@@ -3908,8 +3967,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                string const absfigname =
                                        changeExtension(abstexname, ".fig");
                                fix_child_filename(filename);
-                               string const lyxname =
-                                       changeExtension(filename, ".lyx");
+                               string const lyxname = changeExtension(filename,
+                                       roundtripMode() ? ".lyx.lyx" : ".lyx");
                                string const abslyxname = makeAbsPath(
                                        lyxname, getParentFilePath(false)).absFileName();
                                bool xfig = false;
@@ -4123,7 +4182,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                          "", "", t.cs());
                }
 
-               else if (t.cs() == "ovalbox" || t.cs() == "Ovalbox" ||
+               else if (t.cs() == "fbox" || t.cs() == "mbox" ||
+                            t.cs() == "ovalbox" || t.cs() == "Ovalbox" ||
                         t.cs() == "shadowbox" || t.cs() == "doublebox")
                        parse_outer_box(p, os, FLAG_ITEM, outer, context, t.cs(), "");
 
@@ -4138,18 +4198,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                parse_text(p, os, FLAG_ITEM, outer, context);
                                output_ert_inset(os, "}", context);
                        } else {
+                               //the syntax is: \framebox[width][position]{content}
                                string special = p.getFullOpt();
                                special += p.getOpt();
-                               // LyX does not yet support \framebox without any option
-                               if (!special.empty())
-                                       parse_outer_box(p, os, FLAG_ITEM, outer,
-                                                       context, t.cs(), special);
-                               else {
-                                       eat_whitespace(p, os, context, false);
-                                       output_ert_inset(os, "\\framebox{", context);
-                                       parse_text(p, os, FLAG_ITEM, outer, context);
-                                       output_ert_inset(os, "}", context);
-                               }
+                               parse_outer_box(p, os, FLAG_ITEM, outer,
+                                                   context, t.cs(), special);
                        }
                }