]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
Merge branch 'master' into biblatex2
[lyx.git] / src / tex2lyx / text.cpp
index d7e18fa4402d4b2eee44a9eecda99bd0ed8ada6b..d60418ef0b832bab1bdc8168c3345f03cdd51626 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 };
@@ -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);
@@ -1023,37 +1032,6 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                p.popPosition();
        }
 
-       // 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;
-                       hor_pos = "c";
-               } else if (p.next_token().asInput() == "\\raggedleft") {
-                       wasBoxAlign = true;
-                       hor_pos = "r";
-               }
-               p.popPosition();
-       }
-
        if (use_ert) {
                ostringstream ss;
                if (!outer_type.empty()) {
@@ -1221,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
@@ -1577,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();
        }
@@ -1912,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
@@ -2858,8 +2838,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
@@ -3516,6 +3496,8 @@ 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";
                        end_inset(os);
                        preamble.registerAutomaticallyLoadedPackage("refstyle");
                }
@@ -3532,6 +3514,8 @@ 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";
                                end_inset(os);
                                if (t.cs() == "vref" || t.cs() == "vpageref")
                                        preamble.registerAutomaticallyLoadedPackage("varioref");
@@ -4308,17 +4292,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) {
-                                       // LyX will add a space after outputting the
-                                       // alignment command, so eat any space which
-                                       // might follow. Otherwise the paragraph
-                                       // might start with an unneeded space.
-                                       p.skip_spaces(true);
-                               } else
-                                       output_ert_inset(os, t.asInput(), context);
+                               output_ert_inset(os, t.asInput(), context);
                        }
-                       wasBoxAlign = false;
                }
 
                //\framebox() is part of the picture environment and different from \framebox{}
@@ -4774,10 +4749,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";
@@ -4853,8 +4825,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);