]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
Extend LATEXIFY command param handling and add literal param.
[lyx.git] / src / tex2lyx / text.cpp
index 32944aabdec3784351ca2fb3fcbca0e4a6d2029f..b3cbc46c660fb5d9aa2ef611d739de2ab164c23f 100644 (file)
@@ -127,7 +127,6 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer,
 string fboxrule = "";
 string fboxsep = "";
 string shadow_size = "";
-bool wasBoxAlign = false;
 
 char const * const known_ref_commands[] = { "ref", "pageref", "vref",
  "vpageref", "prettyref", "nameref", "eqref", 0 };
@@ -137,11 +136,11 @@ char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref",
 
 char const * const known_refstyle_commands[] = { "algref", "chapref", "corref",
  "eqref", "enuref", "figref", "fnref", "lemref", "parref", "partref", "propref",
- "secref", "subref", "tabref", "thmref", 0 };
+ "secref", "subsecref", "tabref", "thmref", 0 };
 
 char const * const known_refstyle_prefixes[] = { "alg", "chap", "cor",
  "eq", "enu", "fig", "fn", "lem", "par", "part", "prop",
- "sec", "sub", "tab", "thm", 0 };
+ "sec", "subsec", "tab", "thm", 0 };
 
 
 /**
@@ -314,7 +313,7 @@ char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut",
 "textovercross", "textsubarch", "textsuperimposetilde", "textraising",
 "textlowering", "textadvancing", "textretracting", "textdoublegrave",
 "texthighrise", "textlowrise", "textrisefall", "textsyllabic",
-"textsubring", 0};
+"textsubring", "textsubbar", 0};
 
 /// TIPA tones that need special handling
 char const * const known_tones[] = {"15", "51", "45", "12", "454", 0};
@@ -522,8 +521,8 @@ docstring convert_unicodesymbols(docstring s)
                bool termination;
                docstring rem;
                set<string> req;
-               docstring parsed = encodings.fromLaTeXCommand(s,
-                               Encodings::TEXT_CMD, termination, rem, &req);
+               docstring parsed = normalize_c(encodings.fromLaTeXCommand(s,
+                               Encodings::TEXT_CMD, termination, rem, &req));
                set<string>::const_iterator it = req.begin();
                set<string>::const_iterator en = req.end();
                for (; it != en; ++it)
@@ -581,6 +580,16 @@ void output_ert_inset(ostream & os, string const & s, Context & context)
 }
 
 
+void output_comment(Parser & p, ostream & os, string const & s,
+                    Context & context)
+{
+       if (p.next_token().cat() == catNewline)
+               output_ert_inset(os, '%' + s, context);
+       else
+               output_ert_inset(os, '%' + s + '\n', context);
+}
+
+
 Layout const * findLayout(TextClass const & textclass, string const & name, bool command)
 {
        Layout const * layout = findLayoutWithoutModule(textclass, name, command);
@@ -884,6 +893,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                        p.getArg('{', '}');
                        inner_type = "minipage";
                        inner_flags = FLAG_END;
+                       active_environments.push_back("minipage");
                }
                // parse parbox
                else if (p.next_token().asInput() == "\\parbox") {
@@ -906,7 +916,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                        inner_pos = "t";
                }
        }
-       if (inner_type == "makebox" && !p.hasOpt())
+       if (!p.hasOpt() && (inner_type == "makebox" || outer_type == "mbox"))
                hor_pos = "c";
        if (!inner_type.empty() && p.hasOpt()) {
                if (inner_type != "makebox")
@@ -1021,50 +1031,6 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                }
                p.popPosition();
        }
-       // if only \makebox{content} was used we can set its width to 1\width
-       // because this identic and also identic to \mbox
-       // this doesn't work for \framebox{content}, thus we have to use ERT for this
-       if (latex_width.empty() && inner_type == "makebox" && background_color.empty()) {
-               width_value = "1";
-               width_unit = "in";
-               width_special = "width";
-       } else if (latex_width.empty() && outer_type == "framebox") {
-               width_value.clear();
-               width_unit.clear();
-               width_special = "none";
-       }
-
-       // try to determine the box content alignment
-       // first handle the simple case of "{\centering..."
-       if (p.next_token().asInput() == "\\raggedright") {
-               wasBoxAlign = true;
-               hor_pos = "l";
-       } else if (p.next_token().asInput() == "\\centering") {
-               wasBoxAlign = true;
-               hor_pos = "c";
-       } else if (p.next_token().asInput() == "\\raggedleft") {
-               wasBoxAlign = true;
-               hor_pos = "r";
-       } else {
-               // now handle the cases "{%catNewline\centering..."
-               // and "{catNewline\centering..."
-               p.pushPosition();
-               p.get_token().asInput();
-               if (p.next_token().cat() == catComment || p.next_token().cat() == catNewline)
-                       p.get_token().asInput();
-               if (p.next_token().asInput() == "\\raggedright") {
-                       wasBoxAlign = true;
-                       hor_pos = "l";
-               } else if (p.next_token().asInput() == "\\centering") {
-                       wasBoxAlign = true;
-                       os << "\n sada";
-                       hor_pos = "c";
-               } else if (p.next_token().asInput() == "\\raggedleft") {
-                       wasBoxAlign = true;
-                       hor_pos = "r";
-               }
-               p.popPosition();
-       }
 
        if (use_ert) {
                ostringstream ss;
@@ -1154,7 +1120,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                os << "hor_pos \"" << hor_pos << "\"\n";
                if (outer_type == "mbox")
                        os << "has_inner_box 1\n";
-               if (!frame_color.empty())
+               else if (!frame_color.empty() && inner_type == "makebox")
                        os << "has_inner_box 0\n";
                else
                        os << "has_inner_box " << !inner_type.empty() << "\n";
@@ -1163,7 +1129,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                   << '\n';
                if (outer_type == "mbox")
                        os << "use_makebox 1\n";
-               if (!frame_color.empty())
+               else if (!frame_color.empty())
                        os << "use_makebox 0\n";
                else
                        os << "use_makebox " << (inner_type == "makebox") << '\n';
@@ -1233,13 +1199,13 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                // LyX puts a % after the end of the minipage
                if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) {
                        // new paragraph
-                       //output_ert_inset(os, "%dummy", parent_context);
+                       //output_comment(p, os, "dummy", parent_context);
                        p.get_token();
                        p.skip_spaces();
                        parent_context.new_paragraph(os);
                }
                else if (p.next_token().cat() == catSpace || p.next_token().cat() == catNewline) {
-                       //output_ert_inset(os, "%dummy", parent_context);
+                       //output_comment(p, os, "dummy", parent_context);
                        p.get_token();
                        p.skip_spaces();
                        // We add a protected space if something real follows
@@ -1250,6 +1216,8 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                }
 #endif
        }
+       if (inner_type == "minipage" && (!frame_color.empty() || !background_color.empty()))
+               active_environments.pop_back();
        if (inner_flags != FLAG_BRACE_LAST && (!frame_color.empty() || !background_color.empty())) {
                // in this case we have to eat the the closing brace of the color box
                p.get_token().asInput(); // the '}'
@@ -1587,15 +1555,17 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                preamble.registerAutomaticallyLoadedPackage("verbatim");
        }
 
-       else if (name == "verbatim") {
+       else if (unstarred_name == "verbatim") {
                // FIXME: this should go in the generic code that
                // handles environments defined in layout file that
                // have "PassThru 1". However, the code over there is
                // already too complicated for my taste.
+               string const ascii_name =
+                       (name == "verbatim*") ? "Verbatim*" : "Verbatim";
                parent_context.new_paragraph(os);
                Context context(true, parent_context.textclass,
-                               &parent_context.textclass[from_ascii("Verbatim")]);
-               string s = p.verbatimEnvironment("verbatim");
+                               &parent_context.textclass[from_ascii(ascii_name)]);
+               string s = p.verbatimEnvironment(name);
                output_ert(os, s, context);
                p.skip_spaces();
        }
@@ -1712,8 +1682,8 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                        p.skip_spaces(true);
                        os << "btprint " << '"' << "btPrintAll" << '"' << "\n";
                }
-               os << "bibfiles " << '"' << bibfile << '"' << "\n";
-               os << "options " << '"' << bibstyle << '"' <<  "\n";
+               os << "bibfiles " << '"' << bibfile << "\"\n"
+                  << "options " << '"' << bibstyle << "\"\n";
                parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
                end_inset(os);
                p.skip_spaces();
@@ -1922,7 +1892,7 @@ void parse_comment(Parser & p, ostream & os, Token const & t, Context & context)
        LASSERT(t.cat() == catComment, return);
        if (!t.cs().empty()) {
                context.check_layout(os);
-               output_ert_inset(os, '%' + t.cs(), context);
+               output_comment(p, os, t.cs(), context);
                if (p.next_token().cat() == catNewline) {
                        // A newline after a comment line starts a new
                        // paragraph
@@ -2105,7 +2075,6 @@ void copy_file(FileName const & src, string dstname)
                dst = FileName(dstname);
        else
                dst = makeAbsPath(dstname, absParent);
-       string const absMaster = getMasterFilePath(false);
        FileName const srcpath = src.onlyPath();
        FileName const dstpath = dst.onlyPath();
        if (equivalent(srcpath, dstpath))
@@ -2791,7 +2760,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        } else {
                                begin_command_inset(os, "bibitem", "bibitem");
                                os << "label \"" << label << "\"\n"
-                                     "key \"" << key << "\"\n";
+                                  << "key \"" << key << "\"\n"
+                                  << "literal \"true\"\n";
                                end_inset(os);
                        }
                }
@@ -2869,8 +2839,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        context.check_layout(os);
                        // FIXME: This is a hack to prevent paragraph
                        // deletion if it is empty. Handle this better!
-                       output_ert_inset(os,
-                               "%dummy comment inserted by tex2lyx to "
+                       output_comment(p, os,
+                               "dummy comment inserted by tex2lyx to "
                                "ensure that this paragraph is not empty",
                                context);
                        // Both measures above may generate an additional
@@ -2944,7 +2914,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        // the syntax is \subfloat[list entry][sub caption]{content}
                        // if it is a table of figure depends on the surrounding float
                        // FIXME: second optional argument is not parsed
-                       bool has_caption = false;
                        p.skip_spaces();
                        // do nothing if there is no outer float
                        if (!float_type.empty()) {
@@ -2956,6 +2925,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                   << "\nstatus collapsed\n\n";
                                // test for caption
                                string caption;
+                               bool has_caption = false;
                                if (p.next_token().cat() != catEscape &&
                                                p.next_token().character() == '[') {
                                                        p.get_token(); // eat '['
@@ -3470,6 +3440,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        os << "target \"" << target << "\"\n";
                        if (type == "mailto:" || type == "file:")
                                os << "type \"" << type << "\"\n";
+                       os << "literal \"true\"\n";
                        end_inset(os);
                        skip_spaces_braces(p);
                }
@@ -3527,6 +3498,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                           << ":";
                        os << convert_command_inset_arg(p.verbatim_item())
                           << "\"\n";
+                       os << "plural \"false\"\n";
+                       os << "caps \"false\"\n";
+                       os << "noprefix \"false\"\n";
                        end_inset(os);
                        preamble.registerAutomaticallyLoadedPackage("refstyle");
                }
@@ -3543,6 +3517,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                os << "reference \""
                                   << convert_command_inset_arg(p.verbatim_item())
                                   << "\"\n";
+                               os << "plural \"false\"\n";
+                               os << "caps \"false\"\n";
+                               os << "noprefix \"false\"\n";
                                end_inset(os);
                                if (t.cs() == "vref" || t.cs() == "vpageref")
                                        preamble.registerAutomaticallyLoadedPackage("varioref");
@@ -3610,7 +3587,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        os << "before " << '"' << before << '"' << "\n";
                        os << "key \""
                           << convert_command_inset_arg(p.verbatim_item())
-                          << "\"\n";
+                          << "\"\n"
+                          << "literal \"true\"\n";
                        end_inset(os);
                        // Need to set the cite engine if natbib is loaded by
                        // the document class directly
@@ -3662,9 +3640,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                before.erase(before.length() - 1, 1);
                        }
                        begin_command_inset(os, "citation", command);
-                       os << "after " << '"' << after << '"' << "\n";
-                       os << "before " << '"' << before << '"' << "\n";
-                       os << "key " << '"' << citation << '"' << "\n";
+                       os << "after " << '"' << after << "\"\n"
+                          << "before " << '"' << before << "\"\n"
+                          << "key " << '"' << citation << "\"\n"
+                          << "literal \"true\"\n";
                        end_inset(os);
                        // Need to set the cite engine if jurabib is loaded by
                        // the document class directly
@@ -3681,8 +3660,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        // the BibTeX inset
                        if (key != "*") {
                                begin_command_inset(os, "citation", t.cs());
-                               os << "after " << '"' << after << '"' << "\n";
-                               os << "key " << '"' << key << '"' << "\n";
+                               os << "after " << '"' << after << "\"\n"
+                                  << "key " << '"' << key << "\"\n"
+                                  << "literal \"true\"\n";
                                end_inset(os);
                        } else if (t.cs() == "nocite")
                                btprint = key;
@@ -3712,7 +3692,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                           << convert_command_inset_arg(p.verbatim_item());
                        os << "\"\ndescription \""
                           << convert_command_inset_arg(p.verbatim_item())
-                          << "\"\n";
+                          << "\"\n"
+                          << "literal \"true\"\n";
                        end_inset(os);
                        preamble.registerAutomaticallyLoadedPackage("nomencl");
                }
@@ -3742,6 +3723,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        os << "type \"idx\"\n";
                                else
                                        os << "type \"" << indexname << "\"\n";
+                               os << "literal \"true\"\n";
                        }
                        end_inset(os);
                        skip_spaces_braces(p);
@@ -4299,7 +4281,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                             || t.cs() == "shadowsize"
                                 || t.cs() == "raggedleft" || t.cs() == "centering"
                         || t.cs() == "raggedright") {
-                       p.skip_spaces(true);
                        if (t.cs() == "fboxrule")
                                fboxrule = "";
                        if (t.cs() == "fboxsep")
@@ -4308,6 +4289,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                shadow_size = "";
                        if (t.cs() != "raggedleft" && t.cs() != "centering"
                         && t.cs() != "raggedright") {
+                               p.skip_spaces(true);
                                while (p.good() && p.next_token().cat() != catSpace
                                       && p.next_token().cat() != catNewline
                                       && p.next_token().cat() != catEscape) {
@@ -4319,11 +4301,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                                shadow_size = shadow_size + p.get_token().asInput();
                                }
                        } else {
-                               // we only handle them if they are in a box
-                               if (!wasBoxAlign)
-                                       output_ert_inset(os, '\\' + t.cs() + ' ', context);
+                               output_ert_inset(os, t.asInput(), context);
                        }
-                       wasBoxAlign = false;
                }
 
                //\framebox() is part of the picture environment and different from \framebox{}
@@ -4779,10 +4758,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                        // handle some TIPA special characters
                        else if (preamble.isPackageUsed("tipa")) {
-                               if (name == "\\textglobfall") {
-                                       name = "End";
-                                       skip_braces(p);
-                               } else if (name == "\\s") {
+                               if (name == "\\s") {
                                        // fromLaTeXCommand() does not yet
                                        // recognize tipa short cuts
                                        name = "\\textsyllabic";
@@ -4791,7 +4767,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        // fromLaTeXCommand() does not yet
                                        // recognize tipa short cuts
                                        p.get_token();
-                                       name = "\\b";
+                                       name = "\\textsubbar";
                                } else if (name == "\\textdoublevertline") {
                                        // FIXME: This is not correct,
                                        // \textvertline is higher than \textbardbl
@@ -4858,8 +4834,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        bool termination;
                        docstring rem;
                        set<string> req;
-                       docstring s = encodings.fromLaTeXCommand(from_utf8(name),
-                                       Encodings::TEXT_CMD, termination, rem, &req);
+                       docstring s = normalize_c(encodings.fromLaTeXCommand(from_utf8(name),
+                                       Encodings::TEXT_CMD, termination, rem, &req));
                        if (!s.empty()) {
                                context.check_layout(os);
                                os << to_utf8(s);