From: Georg Baum Date: Thu, 19 Apr 2012 18:46:08 +0000 (+0200) Subject: Fix bug #8104 (\date argument was eaten) X-Git-Tag: 2.1.0beta1~1933^2~21 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c1965123ed2a5390a1d719f4ba3f92c27376adff;p=features.git Fix bug #8104 (\date argument was eaten) 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? --- diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 8953a47bb7..fa93a2a26b 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -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; diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index 5c2d883aab..5fe6c572bd 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -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; diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index 71a1680253..b30050dc4a 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -42,6 +42,13 @@ \begin{document} +\title{Title} + +\date %stupid stuff +{two days ago} + +\maketitle + \tableofcontents \lstlistoflistings diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index db7e7c6d35..3f65d43642 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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 const & req = newlayout->requires(); for (set::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 const & req = newlayout->requires(); for (set::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 const & req = newlayout->requires(); for (set::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 const & req = newlayout->requires(); for (set::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