mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
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?
This commit is contained in:
parent
dce6c8875c
commit
c1965123ed
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -42,6 +42,13 @@
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{Title}
|
||||
|
||||
\date %stupid stuff
|
||||
{two days ago}
|
||||
|
||||
\maketitle
|
||||
|
||||
\tableofcontents
|
||||
\lstlistoflistings
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user