]> git.lyx.org Git - features.git/commitdiff
Fix bug #8104 (\date argument was eaten)
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 19 Apr 2012 18:46:08 +0000 (20:46 +0200)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 19 Apr 2012 18:46:08 +0000 (20:46 +0200)
I introduced this bug in r40091 where support for empty dates was added.
I also noticed that the title_layout_found flag was not properly passed down
to all variants of parse_text*. Since this is rather a global variable I
placed it into the preamble class.

The test case of bug #8104 shows other problems as well, but those are no
regressions and will be fixed separately.

OK for branch?

src/tex2lyx/Preamble.cpp
src/tex2lyx/Preamble.h
src/tex2lyx/test/test-insets.tex
src/tex2lyx/text.cpp

index 8953a47bb78b6adc414d8f2766b873be235405ab..fa93a2a26b25a45c46da6107e83349a1ffabef67 100644 (file)
@@ -395,7 +395,7 @@ string remove_braces(string const & value)
 } // anonymous namespace
 
 
-Preamble::Preamble() : one_language(true)
+Preamble::Preamble() : one_language(true), title_layout_found(false)
 {
        //h_backgroundcolor;
        //h_boxbgcolor;
index 5c2d883aab51c5bfbbf191c9c858947198977625..5fe6c572bdec640fe2a4a88891b4d21215f15e5d 100644 (file)
@@ -55,6 +55,10 @@ public:
        void addModule(std::string const & module);
        ///
        void suppressDate(bool suppress);
+       ///
+       bool titleLayoutFound() const { return title_layout_found; }
+       ///
+       void titleLayoutFound(bool found) { title_layout_found = found; }
        /// Register an author named \p name in the author list
        void registerAuthor(std::string const & name);
        /// Get author named \p name (must be registered first)
@@ -78,6 +82,9 @@ private:
        /// needed to handle encodings with babel
        bool one_language;
 
+       /// was at least one title layout found?
+       bool title_layout_found;
+
        std::ostringstream h_preamble;
        std::string h_backgroundcolor;
        std::string h_biblio_style;
index 71a16802536977cf91d4b5604308ef870e911ce3..b30050dc4ab133e5e551e8d9e4fc0f596b3f7b16 100644 (file)
 
 \begin{document}
 
+\title{Title}
+
+\date %stupid stuff
+{two days ago}
+
+\maketitle
+
 \tableofcontents
 \lstlistoflistings
 
index db7e7c6d35ed09b33f018ee55eb5bb3bbe53ac19..3f65d43642b0fc361bbbf52d54a0bb498eb912a9 100644 (file)
@@ -1186,8 +1186,7 @@ void parse_unknown_environment(Parser & p, string const & name, ostream & os,
 
 
 void parse_environment(Parser & p, ostream & os, bool outer,
-                       string & last_env, bool & title_layout_found,
-                       Context & parent_context)
+                       string & last_env, Context & parent_context)
 {
        Layout const * newlayout;
        InsetLayout const * newinsetlayout = 0;
@@ -1554,8 +1553,8 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                context.check_end_deeper(os);
                parent_context.new_paragraph(os);
                p.skip_spaces();
-               if (!title_layout_found)
-                       title_layout_found = newlayout->intitle;
+               if (!preamble.titleLayoutFound())
+                       preamble.titleLayoutFound(newlayout->intitle);
                set<string> const & req = newlayout->requires();
                for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
                        preamble.registerAutomaticallyLoadedPackage(*it);
@@ -1971,7 +1970,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
        bool const use_natbib = preamble.isPackageUsed("natbib");
        bool const use_jurabib = preamble.isPackageUsed("jurabib");
        string last_env;
-       bool title_layout_found = false;
        while (p.good()) {
                Token const & t = p.get_token();
 
@@ -2298,7 +2296,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "begin")
                        parse_environment(p, os, outer, last_env,
-                                         title_layout_found, context);
+                                         context);
 
                else if (t.cs() == "end") {
                        if (flags & FLAG_END) {
@@ -2469,10 +2467,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                // Must catch empty dates before findLayout is called below
                else if (t.cs() == "date") {
+                       eat_whitespace(p, os, context, false);
+                       p.pushPosition();
                        string const date = p.verbatim_item();
-                       if (date.empty())
+                       p.popPosition();
+                       if (date.empty()) {
                                preamble.suppressDate(true);
-                       else {
+                               p.verbatim_item();
+                       } else {
                                preamble.suppressDate(false);
                                if (context.new_layout_allowed &&
                                    (newlayout = findLayout(context.textclass,
@@ -2480,16 +2482,17 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        // write the layout
                                        output_command_layout(os, p, outer,
                                                        context, newlayout);
-                                       p.skip_spaces();
-                                       if (!title_layout_found)
-                                               title_layout_found = newlayout->intitle;
+                                       parse_text_snippet(p, os, FLAG_ITEM, outer, context);
+                                       if (!preamble.titleLayoutFound())
+                                               preamble.titleLayoutFound(newlayout->intitle);
                                        set<string> const & req = newlayout->requires();
                                        for (set<string>::const_iterator it = req.begin();
                                             it != req.end(); it++)
                                                preamble.registerAutomaticallyLoadedPackage(*it);
                                } else
-                                       handle_ert(os, "\\date{" + date + '}',
-                                                       context);
+                                       handle_ert(os,
+                                               "\\date{" + p.verbatim_item() + '}',
+                                               context);
                        }
                }
 
@@ -2502,8 +2505,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        p.get_token();
                        output_command_layout(os, p, outer, context, newlayout);
                        p.skip_spaces();
-                       if (!title_layout_found)
-                               title_layout_found = newlayout->intitle;
+                       if (!preamble.titleLayoutFound())
+                               preamble.titleLayoutFound(newlayout->intitle);
                        set<string> const & req = newlayout->requires();
                        for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
                                preamble.registerAutomaticallyLoadedPackage(*it);
@@ -2515,8 +2518,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        // write the layout
                        output_command_layout(os, p, outer, context, newlayout);
                        p.skip_spaces();
-                       if (!title_layout_found)
-                               title_layout_found = newlayout->intitle;
+                       if (!preamble.titleLayoutFound())
+                               preamble.titleLayoutFound(newlayout->intitle);
                        set<string> const & req = newlayout->requires();
                        for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
                                preamble.registerAutomaticallyLoadedPackage(*it);
@@ -2808,7 +2811,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                }
 
                else if (t.cs() == "makeindex" || t.cs() == "maketitle") {
-                       if (title_layout_found) {
+                       if (preamble.titleLayoutFound()) {
                                // swallow this
                                skip_spaces_braces(p);
                        } else